diff --git a/src/components/BootstrapBlazor.DockView/BootstrapBlazor.DockView.csproj b/src/components/BootstrapBlazor.DockView/BootstrapBlazor.DockView.csproj index a1d49187..814a0425 100644 --- a/src/components/BootstrapBlazor.DockView/BootstrapBlazor.DockView.csproj +++ b/src/components/BootstrapBlazor.DockView/BootstrapBlazor.DockView.csproj @@ -1,7 +1,7 @@  - 10.0.8 + 10.0.9 diff --git a/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs b/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs index b00fb337..ed199065 100644 --- a/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs +++ b/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs @@ -14,15 +14,6 @@ namespace BootstrapBlazor.Components; /// public partial class DockViewV2 { - /// - /// 获得/设置 DockView 名称,默认为 null,用于本地存储标识 - /// Gets or sets the DockView name. Default is null and it is used for local storage identification - /// - [Parameter] - [EditorRequired] - [NotNull] - public string? Name { get; set; } - /// /// 获得/设置 布局配置 /// Gets or sets the layout configuration @@ -128,6 +119,14 @@ public partial class DockViewV2 [Parameter] public string? Version { get; set; } + /// + /// 获得/设置 DockView 名称,默认为 null,用于本地存储标识 + /// Gets or sets the DockView name. Default is null and it is used for local storage identification + /// + [Parameter] + [NotNull] + public string? Name { get; set; } + /// /// 获得/设置 是否启用本地存储布局,默认为 null /// Gets or sets whether local storage layout is enabled. Default is null @@ -186,6 +185,20 @@ protected override void OnInitialized() ThemeProviderService.ThemeChangedAsync += OnThemeChangedAsync; } + /// + /// + /// + protected override void OnParametersSet() + { + base.OnParametersSet(); + + // 开启本体存储未提供 Name 时抛出异常提示 + if (IsEnableLocalStorage && string.IsNullOrEmpty(Name)) + { + throw new InvalidOperationException("Name must be provided when local storage is enabled."); + } + } + /// /// /// @@ -196,19 +209,19 @@ protected override async Task OnAfterRenderAsync(bool firstRender) if (!firstRender) { - await InvokeVoidAsync("update", Id, GetOptions()); + await InvokeVoidAsync("update", Id, GetDockViewConfig()); } } /// /// /// - protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, GetOptions()); + protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, GetDockViewConfig()); - private DockViewConfig GetOptions() => new() + private DockViewConfig GetDockViewConfig() => new() { - EnableLocalStorage = EnableLocalStorage ?? _options.EnableLocalStorage ?? false, - LocalStorageKey = $"{GetPrefixKey()}-{Name}-{GetVersion()}", + EnableLocalStorage = IsEnableLocalStorage, + LocalStorageKey = LocalStorageKey, IsLock = IsLock, ShowLock = ShowLock, IsFloating = IsFloating, @@ -227,6 +240,10 @@ protected override async Task OnAfterRenderAsync(bool firstRender) LoadTabs = nameof(LoadTabs) }; + private bool IsEnableLocalStorage => EnableLocalStorage ?? _options.EnableLocalStorage ?? false; + + private string? LocalStorageKey => IsEnableLocalStorage ? $"{GetPrefixKey()}-{Name}-{GetVersion()}" : null; + private string GetVersion() => Version ?? _options.Version ?? "v1"; private string GetPrefixKey() => LocalStoragePrefix ?? _options.LocalStoragePrefix ?? "bb-dockview"; @@ -237,7 +254,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) /// public async Task Reset(string? layoutConfig = null) { - var options = GetOptions(); + var options = GetDockViewConfig(); if (layoutConfig != null) { options.LayoutConfig = layoutConfig;