Skip to content

Commit 852f9ca

Browse files
committed
refactor: 组件方法直接调用 DockView 方法
1 parent 6666447 commit 852f9ca

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ protected override void OnParametersSet()
173173
{
174174
base.OnParametersSet();
175175

176+
// 同步组件状态到缓存
176177
var state = DockView.GetComponentState(Key);
177178
if (state != null)
178179
{
@@ -189,9 +190,7 @@ private async Task OnClickBar()
189190
}
190191
}
191192

192-
private bool IsRender() => DockView.GetComponentState(Key).IsRender();
193-
194-
internal object? GetState() => DockView.GetComponentState(Key).GetComponentState(this);
193+
private bool IsRender() => DockView.IsRender(Key);
195194

196195
internal void SetVisible(bool visible) => Visible = visible;
197196

src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public async Task Reset(string? layoutConfig = null)
249249
/// <para lang="zh">获得 当前布局 JSON 字符串</para>
250250
/// <para lang="en">Gets the current layout JSON string</para>
251251
/// </summary>
252-
public Task<string?> SaveLayout() => InvokeAsync<string?>("save", Id);
252+
public Task<string?> SaveLayout() => InvokeAsync<string>("save", Id);
253253

254254
private Task OnThemeChangedAsync(string themeName)
255255
{
@@ -341,6 +341,7 @@ public async Task SplitterCallbackAsync()
341341
[JSInvokable]
342342
public Task LoadTabs(List<string> tabs)
343343
{
344+
// 注意渲染方式 DockViewRenderMode 为 DockViewRenderMode.OnlyWhenVisible 时此逻辑生效
344345
_loadTabs = tabs.ToHashSet();
345346
foreach (var componnet in _componentStates)
346347
{
@@ -354,6 +355,11 @@ public Task LoadTabs(List<string> tabs)
354355

355356
internal void AddComponentState(DockViewComponentState state)
356357
{
358+
if (Renderer == DockViewRenderMode.Always)
359+
{
360+
return;
361+
}
362+
357363
if (!string.IsNullOrEmpty(state.Key))
358364
{
359365
_componentStates.TryAdd(state.Key, state);
@@ -362,6 +368,11 @@ internal void AddComponentState(DockViewComponentState state)
362368

363369
internal void RemoveComponentState(string? key)
364370
{
371+
if (Renderer == DockViewRenderMode.Always)
372+
{
373+
return;
374+
}
375+
365376
if (!string.IsNullOrEmpty(key))
366377
{
367378
_componentStates.TryRemove(key, out _);
@@ -371,13 +382,23 @@ internal void RemoveComponentState(string? key)
371382
internal DockViewComponentState? GetComponentState(string? key)
372383
{
373384
DockViewComponentState? state = null;
374-
if (!string.IsNullOrEmpty(key) && _componentStates.TryGetValue(key, out var _state))
385+
if (Renderer == DockViewRenderMode.OnlyWhenVisible)
375386
{
376-
state = _state;
387+
if (!string.IsNullOrEmpty(key) && _componentStates.TryGetValue(key, out var _state))
388+
{
389+
state = _state;
390+
}
377391
}
392+
378393
return state;
379394
}
380395

396+
internal bool IsRender(string? key) => Renderer switch
397+
{
398+
DockViewRenderMode.OnlyWhenVisible => GetComponentState(key)?.IsRender() ?? false,
399+
_ => true
400+
};
401+
381402
private void Dispose(bool disposing)
382403
{
383404
if (disposing)

src/components/BootstrapBlazor.DockView/Data/DockViewComponentState.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ class DockViewComponentState(DockViewComponent component)
3232
/// <para lang="zh">获得/设置 组件内容是否渲染,默认为 false</para>
3333
/// <para lang="en">Gets or sets whether the component is rendered. Default is false</para>
3434
/// </summary>
35+
/// <remarks>
36+
/// <para lang="zh">组件内容是否渲染,默认为 false,只有当组件可见时并且当前状态为 Active 时才会渲染组件内容</para>
37+
/// <para lang="en">Whether the component content is rendered. Default is false. The content is only rendered when the component is visible and the current state is Active.</para>
38+
/// </remarks>
3539
public bool Render { get; set; }
3640

3741
/// <summary>
3842
/// <para lang="zh">获得/设置 组件实例,默认为 null</para>
3943
/// <para lang="en">Gets or sets the component instance. Default is null</para>
4044
/// </summary>
41-
public DockViewComponent? Component => component;
45+
public DockViewComponent Component => component;
4246
}

0 commit comments

Comments
 (0)