Skip to content

Commit a4c0e8a

Browse files
authored
feat(DockView): remove EditorRequired attribute (#985)
* refactor: 参数排序 * feat: 增加参数检查逻辑开启本地存储时必须给 Name 参数 * chore: bump version 10.0.9
1 parent bef55d7 commit a4c0e8a

2 files changed

Lines changed: 33 additions & 16 deletions

File tree

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.8</Version>
4+
<Version>10.0.9</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ namespace BootstrapBlazor.Components;
1414
/// </summary>
1515
public partial class DockViewV2
1616
{
17-
/// <summary>
18-
/// <para lang="zh">获得/设置 DockView 名称,默认为 null,用于本地存储标识</para>
19-
/// <para lang="en">Gets or sets the DockView name. Default is null and it is used for local storage identification</para>
20-
/// </summary>
21-
[Parameter]
22-
[EditorRequired]
23-
[NotNull]
24-
public string? Name { get; set; }
25-
2617
/// <summary>
2718
/// <para lang="zh">获得/设置 布局配置</para>
2819
/// <para lang="en">Gets or sets the layout configuration</para>
@@ -128,6 +119,14 @@ public partial class DockViewV2
128119
[Parameter]
129120
public string? Version { get; set; }
130121

122+
/// <summary>
123+
/// <para lang="zh">获得/设置 DockView 名称,默认为 null,用于本地存储标识</para>
124+
/// <para lang="en">Gets or sets the DockView name. Default is null and it is used for local storage identification</para>
125+
/// </summary>
126+
[Parameter]
127+
[NotNull]
128+
public string? Name { get; set; }
129+
131130
/// <summary>
132131
/// <para lang="zh">获得/设置 是否启用本地存储布局,默认为 null</para>
133132
/// <para lang="en">Gets or sets whether local storage layout is enabled. Default is null</para>
@@ -186,6 +185,20 @@ protected override void OnInitialized()
186185
ThemeProviderService.ThemeChangedAsync += OnThemeChangedAsync;
187186
}
188187

188+
/// <summary>
189+
/// <inheritdoc/>
190+
/// </summary>
191+
protected override void OnParametersSet()
192+
{
193+
base.OnParametersSet();
194+
195+
// 开启本体存储未提供 Name 时抛出异常提示
196+
if (IsEnableLocalStorage && string.IsNullOrEmpty(Name))
197+
{
198+
throw new InvalidOperationException("Name must be provided when local storage is enabled.");
199+
}
200+
}
201+
189202
/// <summary>
190203
/// <inheritdoc/>
191204
/// </summary>
@@ -196,19 +209,19 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
196209

197210
if (!firstRender)
198211
{
199-
await InvokeVoidAsync("update", Id, GetOptions());
212+
await InvokeVoidAsync("update", Id, GetDockViewConfig());
200213
}
201214
}
202215

203216
/// <summary>
204217
/// <inheritdoc />
205218
/// </summary>
206-
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, GetOptions());
219+
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, GetDockViewConfig());
207220

208-
private DockViewConfig GetOptions() => new()
221+
private DockViewConfig GetDockViewConfig() => new()
209222
{
210-
EnableLocalStorage = EnableLocalStorage ?? _options.EnableLocalStorage ?? false,
211-
LocalStorageKey = $"{GetPrefixKey()}-{Name}-{GetVersion()}",
223+
EnableLocalStorage = IsEnableLocalStorage,
224+
LocalStorageKey = LocalStorageKey,
212225
IsLock = IsLock,
213226
ShowLock = ShowLock,
214227
IsFloating = IsFloating,
@@ -227,6 +240,10 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
227240
LoadTabs = nameof(LoadTabs)
228241
};
229242

243+
private bool IsEnableLocalStorage => EnableLocalStorage ?? _options.EnableLocalStorage ?? false;
244+
245+
private string? LocalStorageKey => IsEnableLocalStorage ? $"{GetPrefixKey()}-{Name}-{GetVersion()}" : null;
246+
230247
private string GetVersion() => Version ?? _options.Version ?? "v1";
231248

232249
private string GetPrefixKey() => LocalStoragePrefix ?? _options.LocalStoragePrefix ?? "bb-dockview";
@@ -237,7 +254,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
237254
/// </summary>
238255
public async Task Reset(string? layoutConfig = null)
239256
{
240-
var options = GetOptions();
257+
var options = GetDockViewConfig();
241258
if (layoutConfig != null)
242259
{
243260
options.LayoutConfig = layoutConfig;

0 commit comments

Comments
 (0)