Skip to content

Commit 3293550

Browse files
committed
refactor: 更新代码逻辑
1 parent 0574a5b commit 3293550

3 files changed

Lines changed: 9 additions & 53 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
176176
builder.CloseComponent();
177177
}
178178

179-
if (DockView.IsActiveTab(Key))
179+
if (DockView.ShowTab(Key))
180180
{
181181
builder.AddContent(70, ChildContent);
182182
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,7 @@ class DockViewConfig
8080
/// <summary>
8181
/// 获得/设置 加载当前激活标签页事件回调
8282
/// </summary>
83-
public string? LoadActiveTabs { get; set; }
84-
85-
/// <summary>
86-
/// 获得/设置 加载当前未激活标签页事件回调
87-
/// </summary>
88-
public string? LoadInactiveTabs { get; set; }
83+
public string? LoadTabs { get; set; }
8984

9085
/// <summary>
9186
/// 获得/设置 客户端缓存键值

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

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,6 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
172172
{
173173
await base.OnAfterRenderAsync(firstRender);
174174

175-
if (_renderActiveTabs)
176-
{
177-
_renderActiveTabs = false;
178-
await InvokeVoidAsync("reloadActiveTab", Id);
179-
return;
180-
}
181-
182-
if (_renderInactiveTabs)
183-
{
184-
_renderInactiveTabs = false;
185-
await InvokeVoidAsync("reloadInactiveTab", Id);
186-
return;
187-
}
188-
189175
if (!firstRender)
190176
{
191177
await InvokeVoidAsync("update", Id, GetOptions());
@@ -216,8 +202,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
216202
LockChangedCallback = nameof(LockChangedCallbackAsync),
217203
SplitterCallback = nameof(SplitterCallbackAsync),
218204
Contents = _components,
219-
LoadActiveTabs = nameof(LoadActiveTabs),
220-
LoadInactiveTabs = nameof(LoadInactiveTabs)
205+
LoadTabs = nameof(LoadTabs)
221206
};
222207

223208
private string GetVersion() => Version ?? _options.Version ?? "v1";
@@ -274,46 +259,22 @@ public async Task PanelVisibleChangedCallbackAsync(string title, bool status)
274259
}
275260
}
276261

277-
private HashSet<string> _activeTabs = new();
278-
private bool _renderActiveTabs = false;
262+
private HashSet<string> _loadTabs = new();
279263

280264
/// <summary>
281265
///
282266
/// </summary>
283267
/// <param name="tabs"></param>
284268
[JSInvokable]
285-
public Task LoadActiveTabs(List<string> tabs)
269+
public Task LoadTabs(List<string> tabs)
286270
{
287271
// 客户端请求渲染当前激活的标签
288-
_activeTabs.Clear();
289-
foreach (var tab in tabs)
290-
{
291-
_activeTabs.Add(tab);
292-
}
293-
294-
_renderActiveTabs = true;
295-
StateHasChanged();
296-
return Task.CompletedTask;
297-
}
298-
299-
private HashSet<string> _inactiveTabs = new();
300-
private bool _renderInactiveTabs = false;
301-
302-
/// <summary>
303-
///
304-
/// </summary>
305-
/// <param name="tabs"></param>
306-
[JSInvokable]
307-
public Task LoadInactiveTabs(List<string> tabs)
308-
{
309-
// 客户端请求渲染当前未激活的标签
310-
_inactiveTabs.Clear();
272+
_loadTabs.Clear();
311273
foreach (var tab in tabs)
312274
{
313-
_inactiveTabs.Add(tab);
275+
_loadTabs.Add(tab);
314276
}
315277

316-
_renderInactiveTabs = true;
317278
StateHasChanged();
318279
return Task.CompletedTask;
319280
}
@@ -323,14 +284,14 @@ public Task LoadInactiveTabs(List<string> tabs)
323284
/// </summary>
324285
/// <param name="key"></param>
325286
/// <returns></returns>
326-
public bool IsActiveTab(string? key)
287+
public bool ShowTab(string? key)
327288
{
328289
if (Renderer == DockViewRenderMode.Always)
329290
{
330291
return true;
331292
}
332293

333-
return _activeTabs.Contains(key ?? string.Empty);
294+
return _loadTabs.Contains(key ?? string.Empty);
334295
}
335296

336297
/// <summary>

0 commit comments

Comments
 (0)