Skip to content

Commit 227aba8

Browse files
authored
feat(DockView): add Reset instance method (#2220)
* feat: 增加 Reset 方法 * feat: 增加 Reset 方法 * refactor: 增加 Readonly 关键字 * fix: 修复重置后 Lock 状态不正确问题
1 parent 03501b6 commit 227aba8

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

src/Extensions/Components/BootstrapBlazor.Dock/Components/DockView/DockView.razor.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ public partial class DockView
9696

9797
private bool _isLock;
9898

99+
private readonly string _version = "v1";
100+
99101
private string? ClassString => CssBuilder.Default("bb-dock")
100102
.AddClassFromAttributes(AdditionalAttributes)
101103
.Build();
@@ -143,7 +145,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
143145

144146
private DockViewConfig GetOption() => new()
145147
{
146-
Version = "v1",
148+
Version = _version,
147149
Name = Name,
148150
EnableLocalStorage = EnableLocalStorage,
149151
IsLock = IsLock,
@@ -201,6 +203,12 @@ public async Task Lock(bool @lock)
201203
}
202204
}
203205

206+
/// <summary>
207+
/// 重置为默认布局
208+
/// </summary>
209+
/// <returns></returns>
210+
public Task Reset() => InvokeVoidAsync("reset", Id, GetOption(), Interop);
211+
204212
/// <summary>
205213
/// 标签页关闭回调方法 由 JavaScript 调用
206214
/// </summary>

src/Extensions/Components/BootstrapBlazor.Dock/Components/DockView/DockView.razor.js

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@ export function lock(id, lock) {
9292
lockDock(dock)
9393
}
9494

95+
export function reset(id, option, invoke) {
96+
const dock = Data.get(id)
97+
if (dock) {
98+
removeConfig(option);
99+
100+
const el = dock.el;
101+
const components = getAllContentItems(option.content);
102+
components.forEach(i => {
103+
const item = document.getElementById(i.id);
104+
if (item) {
105+
item.classList.add("d-none");
106+
el.append(item);
107+
}
108+
})
109+
dispose(id)
110+
111+
init(id, option, invoke)
112+
}
113+
}
114+
95115
export function dispose(id) {
96116
const dock = Data.get(id)
97117
Data.remove(id)
@@ -396,9 +416,13 @@ const removeContent = (content, item) => {
396416
}
397417

398418
const hackGoldenLayout = dock => {
419+
if (goldenLayout.bb_docks === void 0) {
420+
goldenLayout.bb_docks = [];
421+
}
422+
goldenLayout.bb_docks.push(dock);
423+
399424
if (!goldenLayout.isHack) {
400425
goldenLayout.isHack = true
401-
const eventsData = dock.eventsData
402426

403427
// hack Tab
404428
goldenLayout.Tab.prototype.onCloseClick = function () {
@@ -418,8 +442,19 @@ const hackGoldenLayout = dock => {
418442
}
419443
}
420444

445+
// hack RowOrColumn
446+
const originSplitterDragStop = goldenLayout.RowOrColumn.prototype.onSplitterDragStop
447+
goldenLayout.RowOrColumn.prototype.onSplitterDragStop = function (splitter) {
448+
originSplitterDragStop.call(this, splitter)
449+
this.layoutManager.emit('splitterDragStop')
450+
}
451+
421452
// hack Header
422453
goldenLayout.Header.prototype.handleButtonPopoutEvent = function () {
454+
// find own dock
455+
const dock = goldenLayout.bb_docks.find(i => i.layout === this.layoutManager);
456+
const eventsData = dock.eventsData
457+
423458
const stack = this.parent
424459
const lock = eventsData.has(stack)
425460
if (lock) {
@@ -438,6 +473,10 @@ const hackGoldenLayout = dock => {
438473
originprocessTabDropdownActiveChanged.call(this)
439474

440475
this._closeButton.onClick = function (ev) {
476+
// find own dock
477+
const dock = goldenLayout.bb_docks.find(i => i.layout === this.layoutManager);
478+
const eventsData = dock.eventsData
479+
441480
const tabs = this._header.tabs.map(tab => {
442481
return { element: tab.componentItem.element, title: tab.componentItem.title }
443482
})
@@ -453,12 +492,5 @@ const hackGoldenLayout = dock => {
453492
}
454493
}
455494
}
456-
457-
// hack RowOrColumn
458-
const originSplitterDragStop = goldenLayout.RowOrColumn.prototype.onSplitterDragStop
459-
goldenLayout.RowOrColumn.prototype.onSplitterDragStop = function (splitter) {
460-
originSplitterDragStop.call(this, splitter)
461-
this.layoutManager.emit('splitterDragStop')
462-
}
463495
}
464496
}

0 commit comments

Comments
 (0)