@@ -14,15 +14,6 @@ namespace BootstrapBlazor.Components;
1414/// </summary>
1515public 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