Skip to content

Commit 7f88927

Browse files
feat(DockView): add OnlyWhenVisible render mode (#974)
* refactor: 移除 Partial 渲染模式 * feat: 增加 DockViewComponentState 类记录各个组件状态 * refactor: 实现组件状态同步逻辑 * refactor: 修改panelVisibleChangedCallback参数改为使用key * refactor: 更新缓存值逻辑 * feat: 增加 Render 参数 * refactor: 恢复默认值 * refactor:增加enableLocalStorage判断 * feat: 增加状态切换逻辑 * doc: 更新注释 * refactor: 精简代码 * fix: 修复拖动panel到组时显示空白 * refactor: 调整代码结构顺序 * feat: 增加可见性缓存功能 * refactor: 使用扩展方法精简代码 * fix: 切换数据时不需要更新panel的visible状态 * feat: 增加组件实例用于同步组件实例状态 * chore: 调整渲染结构方便调试 * feat: 增加状态切换同步组件状态逻辑 * refactor: 精简代码 * fix:修复关闭按钮配置不生效 * chore: 更改文件编码 * chore: bump version 10.0.7 * refactor: 精简代码 * refactor: 组件方法直接调用 DockView 方法 * refactor: 代码内聚 * fix:删除panel时隐藏空的group及enableLocalStorage不起作用 * refactor: 增加忽略标签防止报错 * revert: 撤销更改 * fix: 修复隐藏组时出现多余的线条 * fix: 修改切换数据dockview更新不对 * fix: 修复切换数据dockview出现空白 * chore: bump version 10.0.8-beta01 * chore: bump version 10.0.8-beta02 * feat(DockViewConfig): add FirstRender parameter * refactor: 更改 FirstRender 参数值逻辑 * feat: 增加首次渲染不移动 Panel 逻辑 * Revert "refactor: 更改 FirstRender 参数值逻辑" This reverts commit 161471a. * Revert "feat(DockViewConfig): add FirstRender parameter" This reverts commit c095c99. * refactor: 更新 firstLoad 变量 * chore: bump version 10.0.8-beta03 * refactor(DockView): add closePanel rewrite function * chore: bump version 10.0.8-beta04 * fix: 通过样式修复隐藏group时出现多余的线条 * fix: 增加isUpdate状态判断点击按钮时不发送panel显示状态 * refactor: 更新是否触发面板可见回调事件逻辑 * style: 更新样式 * refactor: 支持服务器端无 Key 逻辑 * fix: 添加js消除多余的线条 * refactor:修改是要否保留panel的DOM结构的判断 * chore: 更新样式 * chore: bump version 10.0.8-beta05 --------- Co-authored-by: zhaijunlei <276318515@qq.com>
1 parent 3e77f24 commit 7f88927

21 files changed

Lines changed: 496 additions & 346 deletions

src/components/BootstrapBlazor.DockView/BootstrapBlazor.DockView.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>10.0.7</Version>
4+
<Version>10.0.8-beta05</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>

src/components/BootstrapBlazor.DockView/Components/DockViewComponent.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{
1212
<DockViewTitleBar BarIcon="@TitleBarIcon" BarIconUrl="@TitleBarIconUrl" OnClickBarCallback="OnClickBar"></DockViewTitleBar>
1313
}
14-
@if (Visible)
14+
@if (IsRender())
1515
{
1616
@ChildContent
1717
}
Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
1+
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

@@ -8,131 +8,152 @@
88
namespace BootstrapBlazor.Components;
99

1010
/// <summary>
11-
/// DockContentItem 配置项子项对标 content 配置项内部 content 配置
11+
/// <para lang="zh">DockView 组件配置项,对应 content 配置项中的组件项</para>
12+
/// <para lang="en">DockView component option corresponding to a component item in the content configuration</para>
1213
/// </summary>
1314
public partial class DockViewComponent
1415
{
1516
/// <summary>
16-
/// 获得/设置 组件是否显示 Header 默认 true 显示
17+
/// <para lang="zh">获得/设置 组件是否显示标题栏,默认为 true</para>
18+
/// <para lang="en">Gets or sets whether the component header is displayed. Default is true</para>
1719
/// </summary>
1820
[Parameter]
1921
public bool ShowHeader { get; set; } = true;
2022

2123
/// <summary>
22-
/// 获得/设置 组件 Title
24+
/// <para lang="zh">获得/设置 组件标题</para>
25+
/// <para lang="en">Gets or sets the component title</para>
2326
/// </summary>
2427
[Parameter]
2528
public string? Title { get; set; }
2629

2730
/// <summary>
28-
/// 获得/设置 组件 Title 宽度 默认 null 未设置
31+
/// <para lang="zh">获得/设置 组件标题宽度,默认为 null</para>
32+
/// <para lang="en">Gets or sets the component title width. Default is null</para>
2933
/// </summary>
3034
[Parameter]
3135
public int? TitleWidth { get; set; }
3236

3337
/// <summary>
34-
/// 获得/设置 组件 Title 样式 默认 null 未设置
38+
/// <para lang="zh">获得/设置 组件标题样式类,默认为 null</para>
39+
/// <para lang="en">Gets or sets the component title CSS class. Default is null</para>
3540
/// </summary>
3641
[Parameter]
3742
public string? TitleClass { get; set; }
3843

3944
/// <summary>
40-
/// 获得/设置 Title 模板 默认 null 未设置
45+
/// <para lang="zh">获得/设置 标题模板,默认为 null</para>
46+
/// <para lang="en">Gets or sets the title template. Default is null</para>
4147
/// </summary>
4248
[Parameter]
43-
[JsonIgnore]
4449
public RenderFragment? TitleTemplate { get; set; }
4550

4651
/// <summary>
47-
/// 获得/设置 组件 Class 默认 null 未设置
52+
/// <para lang="zh">获得/设置 组件样式类,默认为 null</para>
53+
/// <para lang="en">Gets or sets the component CSS class. Default is null</para>
4854
/// </summary>
4955
[Parameter]
5056
public string? Class { get; set; }
5157

5258
/// <summary>
53-
/// 获得/设置 组件是否可见 默认 true 可见
59+
/// <para lang="zh">获得/设置 组件是否可见,默认为 true</para>
60+
/// <para lang="en">Gets or sets whether the component is visible. Default is true</para>
5461
/// </summary>
5562
[Parameter]
5663
public bool Visible { get; set; } = true;
5764

5865
/// <summary>
59-
/// 获得/设置 组件是否允许关闭 默认 null 使用 DockView 的配置
66+
/// <para lang="zh">获得/设置 组件是否允许关闭,默认为 null,未设置时使用 DockView 的配置</para>
67+
/// <para lang="en">Gets or sets whether the component can be closed. Default is null. When not set, the DockView configuration is used</para>
6068
/// </summary>
6169
[Parameter]
6270
public bool? ShowClose { get; set; }
6371

6472
/// <summary>
65-
/// 获得/设置 组件唯一标识值 默认 null 未设置时取 Title 作为唯一标识
73+
/// <para lang="zh">获得/设置 组件唯一标识,默认为 null,未设置时使用 Title 作为唯一标识</para>
74+
/// <para lang="en">Gets or sets the unique component identifier. Default is null. When not set, Title is used as the unique identifier</para>
6675
/// </summary>
6776
[Parameter]
6877
public string? Key { get; set; }
6978

7079
/// <summary>
71-
/// 获得/设置 是否锁定 默认 null 未设置时取 DockView 的配置
80+
/// <para lang="zh">获得/设置 组件是否锁定,默认为 null,未设置时使用 DockView 的配置</para>
81+
/// <para lang="en">Gets or sets whether the component is locked. Default is null. When not set, the DockView configuration is used</para>
7282
/// </summary>
73-
/// <remarks>锁定后无法拖动</remarks>
7483
[Parameter]
7584
public bool? IsLock { get; set; }
7685

7786
/// <summary>
78-
/// 获得/设置 是否显示锁定按钮 默认 null 未设置时取 DockView 的配置
87+
/// <para lang="zh">获得/设置 是否显示锁定按钮,默认为 null,未设置时使用 DockView 的配置</para>
88+
/// <para lang="en">Gets or sets whether the lock button is displayed. Default is null. When not set, the DockView configuration is used</para>
7989
/// </summary>
8090
[Parameter]
8191
public bool? ShowLock { get; set; }
8292

8393
/// <summary>
84-
/// 获得/设置 是否悬浮 默认 null 未设置时取 DockView 的配置
94+
/// <para lang="zh">获得/设置 是否悬浮,默认为 null,未设置时使用 DockView 的配置</para>
95+
/// <para lang="en">Gets or sets whether the component is floating. Default is null. When not set, the DockView configuration is used</para>
8596
/// </summary>
8697
[Parameter]
8798
public bool? IsFloating { get; set; }
8899

89100
/// <summary>
90-
/// 获得/设置 是否显示可悬浮按钮 默认 null 未设置时取 DockView 的配置
101+
/// <para lang="zh">获得/设置 是否显示悬浮按钮,默认为 null,未设置时使用 DockView 的配置</para>
102+
/// <para lang="en">Gets or sets whether the float button is displayed. Default is null. When not set, the DockView configuration is used</para>
91103
/// </summary>
92104
[Parameter]
93105
public bool? ShowFloat { get; set; }
94106

95107
/// <summary>
96-
/// 获得/设置 是否显示最大化按钮 默认 null 未设置时取 DockView 的配置
108+
/// <para lang="zh">获得/设置 是否显示最大化按钮,默认为 null,未设置时使用 DockView 的配置</para>
109+
/// <para lang="en">Gets or sets whether the maximize button is displayed. Default is null. When not set, the DockView configuration is used</para>
97110
/// </summary>
98111
[Parameter]
99112
public bool? ShowMaximize { get; set; }
100113

101114
/// <summary>
102-
/// 获得/设置 是否一直显示 默认 null 未设置时取 DockView 的配置
115+
/// <para lang="zh">获得/设置 组件渲染模式,默认为 null,未设置时使用 DockView 的配置</para>
116+
/// <para lang="en">Gets or sets the component render mode. Default is null. When not set, the DockView configuration is used</para>
103117
/// </summary>
104118
[Parameter]
105-
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
106119
public string? Renderer { get; set; }
107120

108121
/// <summary>
109-
/// 获得/设置 是否显示标题前置图标 默认 false 不显示
122+
/// <para lang="zh">获得/设置 是否显示标题前置图标,默认为 false</para>
123+
/// <para lang="en">Gets or sets whether the leading title icon is displayed. Default is false</para>
110124
/// </summary>
111125
[Parameter]
112126
[JsonIgnore]
113127
public bool ShowTitleBar { get; set; }
114128

115129
/// <summary>
116-
/// 获得/设置 标题前置图标 默认 null 未设置使用默认图标
130+
/// <para lang="zh">获得/设置 标题前置图标,默认为 null,未设置时使用默认图标</para>
131+
/// <para lang="en">Gets or sets the leading title icon. Default is null. When not set, the default icon is used</para>
117132
/// </summary>
118133
[Parameter]
119134
[JsonIgnore]
120135
public string? TitleBarIcon { get; set; }
121136

122137
/// <summary>
123-
/// 获得/设置 标题前置图标 Url 默认 null 未设置使用默认图标
138+
/// <para lang="zh">获得/设置 标题前置图标地址,默认为 null,未设置时使用默认图标</para>
139+
/// <para lang="en">Gets or sets the leading title icon URL. Default is null. When not set, the default icon is used</para>
124140
/// </summary>
125141
[Parameter]
126142
[JsonIgnore]
127143
public string? TitleBarIconUrl { get; set; }
128144

129145
/// <summary>
130-
/// 获得/设置 标题前置图标点击回调方法 默认 null
146+
/// <para lang="zh">获得/设置 标题前置图标点击回调方法,默认为 null</para>
147+
/// <para lang="en">Gets or sets the click callback for the leading title icon. Default is null</para>
131148
/// </summary>
132149
[Parameter]
133150
[JsonIgnore]
134151
public Func<Task>? OnClickTitleBarCallback { get; set; }
135152

153+
[CascadingParameter]
154+
[NotNull]
155+
private DockViewV2? DockView { get; set; }
156+
136157
/// <summary>
137158
/// <inheritdoc/>
138159
/// </summary>
@@ -141,6 +162,20 @@ protected override void OnInitialized()
141162
base.OnInitialized();
142163

143164
Type = DockViewContentType.Component;
165+
166+
// 增加组件状态用于序列化
167+
DockView?.AddComponentState(new DockViewComponentState(this) { Key = Key });
168+
}
169+
170+
/// <summary>
171+
/// <inheritdoc/>
172+
/// </summary>
173+
protected override void OnParametersSet()
174+
{
175+
base.OnParametersSet();
176+
177+
// 同步组件状态到缓存
178+
DockView.UpdateComponentState(Key, Visible, IsLock);
144179
}
145180

146181
private async Task OnClickBar()
@@ -151,12 +186,20 @@ private async Task OnClickBar()
151186
}
152187
}
153188

189+
private bool IsRender() => DockView.IsRender(Key);
190+
191+
internal void SetVisible(bool visible) => Visible = visible;
192+
193+
internal void SetLock(bool isLock) => IsLock = isLock;
194+
154195
/// <summary>
155-
/// 设置 Visible 参数方法
196+
/// <inheritdoc/>
156197
/// </summary>
157-
/// <param name="visible"></param>
158-
public void SetVisible(bool visible)
198+
/// <param name="disposing"></param>
199+
protected override void Dispose(bool disposing)
159200
{
160-
Visible = visible;
201+
base.Dispose(disposing);
202+
203+
DockView.RemoveComponentState(Key);
161204
}
162205
}

src/components/BootstrapBlazor.DockView/Components/DockViewComponentBase.cs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,40 @@
88
namespace BootstrapBlazor.Components;
99

1010
/// <summary>
11-
/// <para lang="zh">DockComponent 基类</para>
12-
/// <para lang="en">Base class for DockComponent</para>
11+
/// <para lang="zh">DockView 组件基类</para>
12+
/// <para lang="en">Base class for DockView components</para>
1313
/// </summary>
1414
public abstract class DockViewComponentBase : IdComponentBase, IDisposable
1515
{
1616
/// <summary>
17-
/// <para lang="zh">获得/设置 渲染类型 默认 Component</para>
18-
/// <para lang="en">Gets or sets the render type. Default is Component.</para>
17+
/// <para lang="zh">获得/设置 组件渲染类型,默认为 Component</para>
18+
/// <para lang="en">Gets or sets the component render type. Default is Component</para>
1919
/// </summary>
2020
[Parameter]
2121
public DockViewContentType Type { get; set; }
2222

2323
/// <summary>
24-
/// <para lang="zh">获得/设置 组件宽度百分比 默认 null 未设置</para>
25-
/// <para lang="en">Gets or sets the component width percentage. Default is null (not set).</para>
24+
/// <para lang="zh">获得/设置 组件宽度百分比,默认为 null</para>
25+
/// <para lang="en">Gets or sets the component width percentage. Default is null</para>
2626
/// </summary>
2727
[Parameter]
2828
public int? Width { get; set; }
2929

3030
/// <summary>
31-
/// <para lang="zh">获得/设置 组件高度百分比 默认 null 未设置</para>
32-
/// <para lang="en">Gets or sets the component height percentage. Default is null (not set).</para>
31+
/// <para lang="zh">获得/设置 组件高度百分比,默认为 null</para>
32+
/// <para lang="en">Gets or sets the component height percentage. Default is null</para>
3333
/// </summary>
3434
[Parameter]
3535
public int? Height { get; set; }
3636

3737
/// <summary>
38-
/// <para lang="zh">获得/设置 子组件</para>
39-
/// <para lang="en">Gets or sets the child content.</para>
38+
/// <para lang="zh">获得/设置 子组件内容</para>
39+
/// <para lang="en">Gets or sets the child content</para>
4040
/// </summary>
4141
[Parameter]
4242
[JsonIgnore]
4343
public RenderFragment? ChildContent { get; set; }
4444

45-
/// <summary>
46-
/// <para lang="zh">获得/设置 DockContent 实例</para>
47-
/// <para lang="en">Gets or sets the DockContent instance.</para>
48-
/// </summary>
4945
[CascadingParameter]
5046
private List<DockViewComponentBase>? Parent { get; set; }
5147

@@ -60,8 +56,8 @@ protected override void OnInitialized()
6056
}
6157

6258
/// <summary>
63-
/// <para lang="zh">资源销毁方法</para>
64-
/// <para lang="en">Resource disposal method</para>
59+
/// <para lang="zh">资源释放方法</para>
60+
/// <para lang="en">Releases resources</para>
6561
/// </summary>
6662
/// <param name="disposing"></param>
6763
protected virtual void Dispose(bool disposing)
@@ -73,8 +69,8 @@ protected virtual void Dispose(bool disposing)
7369
}
7470

7571
/// <summary>
76-
/// <para lang="zh">资源销毁方法</para>
77-
/// <para lang="en">Resource disposal method</para>
72+
/// <para lang="zh">资源释放方法</para>
73+
/// <para lang="en">Releases resources</para>
7874
/// </summary>
7975
public void Dispose()
8076
{

0 commit comments

Comments
 (0)