-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDockViewComponent.cs
More file actions
202 lines (173 loc) · 5.83 KB
/
DockViewComponent.cs
File metadata and controls
202 lines (173 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using System.Text.Json.Serialization;
namespace BootstrapBlazor.Components;
/// <summary>
/// DockContentItem 配置项子项对标 content 配置项内部 content 配置
/// </summary>
public class DockViewComponent : DockViewComponentBase
{
/// <summary>
/// 获得/设置 组件是否显示 Header 默认 true 显示
/// </summary>
[Parameter]
public bool ShowHeader { get; set; } = true;
/// <summary>
/// 获得/设置 组件 Title
/// </summary>
[Parameter]
public string? Title { get; set; }
/// <summary>
/// 获得/设置 组件 Title 宽度 默认 null 未设置
/// </summary>
[Parameter]
public int? TitleWidth { get; set; }
/// <summary>
/// 获得/设置 组件 Title 样式 默认 null 未设置
/// </summary>
[Parameter]
public string? TitleClass { get; set; }
/// <summary>
/// 获得/设置 Title 模板 默认 null 未设置
/// </summary>
[Parameter]
[JsonIgnore]
public RenderFragment? TitleTemplate { get; set; }
/// <summary>
/// 获得/设置 组件 Class 默认 null 未设置
/// </summary>
[Parameter]
public string? Class { get; set; }
/// <summary>
/// 获得/设置 组件是否可见 默认 true 可见
/// </summary>
[Parameter]
public bool Visible { get; set; } = true;
/// <summary>
/// 获得/设置 组件是否允许关闭 默认 null 使用 DockView 的配置
/// </summary>
[Parameter]
public bool? ShowClose { get; set; }
/// <summary>
/// 获得/设置 组件唯一标识值 默认 null 未设置时取 Title 作为唯一标识
/// </summary>
[Parameter]
public string? Key { get; set; }
/// <summary>
/// 获得/设置 是否锁定 默认 null 未设置时取 DockView 的配置
/// </summary>
/// <remarks>锁定后无法拖动</remarks>
[Parameter]
public bool? IsLock { get; set; }
/// <summary>
/// 获得/设置 是否显示锁定按钮 默认 null 未设置时取 DockView 的配置
/// </summary>
[Parameter]
public bool? ShowLock { get; set; }
/// <summary>
/// 获得/设置 是否悬浮 默认 null 未设置时取 DockView 的配置
/// </summary>
[Parameter]
public bool? IsFloating { get; set; }
/// <summary>
/// 获得/设置 是否显示可悬浮按钮 默认 null 未设置时取 DockView 的配置
/// </summary>
[Parameter]
public bool? ShowFloat { get; set; }
/// <summary>
/// 获得/设置 是否显示最大化按钮 默认 null 未设置时取 DockView 的配置
/// </summary>
[Parameter]
public bool? ShowMaximize { get; set; }
/// <summary>
/// 获得/设置 是否一直显示 默认 null 未设置时取 DockView 的配置
/// </summary>
[Parameter]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Renderer { get; set; }
/// <summary>
/// 获得/设置 是否显示标题前置图标 默认 false 不显示
/// </summary>
[Parameter]
[JsonIgnore]
public bool ShowTitleBar { get; set; }
/// <summary>
/// 获得/设置 标题前置图标 默认 null 未设置使用默认图标
/// </summary>
[Parameter]
[JsonIgnore]
public string? TitleBarIcon { get; set; }
/// <summary>
/// 获得/设置 标题前置图标 Url 默认 null 未设置使用默认图标
/// </summary>
[Parameter]
[JsonIgnore]
public string? TitleBarIconUrl { get; set; }
/// <summary>
/// 获得/设置 标题前置图标点击回调方法 默认 null
/// </summary>
[Parameter]
[JsonIgnore]
public Func<Task>? OnClickTitleBarCallback { get; set; }
[CascadingParameter]
[NotNull]
private DockViewV2? DockView { get; set; }
/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void OnInitialized()
{
base.OnInitialized();
Type = DockViewContentType.Component;
}
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="builder"></param>
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(0, "div");
builder.AddAttribute(10, "id", Id);
builder.AddAttribute(20, "class", "bb-dockview-panel");
builder.AddAttribute(30, "data-bb-key", Key);
builder.AddAttribute(40, "data-bb-title", Title);
if (TitleTemplate != null)
{
builder.OpenElement(50, "div");
builder.AddAttribute(51, "class", "bb-dockview-item-title");
builder.AddContent(53, TitleTemplate);
builder.CloseElement();
}
else if (ShowTitleBar)
{
builder.OpenComponent<DockViewTitleBar>(60);
builder.AddAttribute(61, nameof(DockViewTitleBar.BarIcon), TitleBarIcon);
builder.AddAttribute(62, nameof(DockViewTitleBar.BarIconUrl), TitleBarIconUrl);
builder.AddAttribute(63, nameof(DockViewTitleBar.OnClickBarCallback), OnClickBar);
builder.CloseComponent();
}
if (DockView.ShowTab(Key))
{
builder.AddContent(70, ChildContent);
}
builder.CloseElement();
}
private async Task OnClickBar()
{
if (OnClickTitleBarCallback != null)
{
await OnClickTitleBarCallback();
}
}
/// <summary>
/// 设置 Visible 参数方法
/// </summary>
/// <param name="visible"></param>
public void SetVisible(bool visible)
{
Visible = visible;
}
}