@@ -185,6 +185,20 @@ protected override void OnInitialized()
185185 ThemeProviderService . ThemeChangedAsync += OnThemeChangedAsync ;
186186 }
187187
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+
188202 /// <summary>
189203 /// <inheritdoc/>
190204 /// </summary>
@@ -195,19 +209,19 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
195209
196210 if ( ! firstRender )
197211 {
198- await InvokeVoidAsync ( "update" , Id , GetOptions ( ) ) ;
212+ await InvokeVoidAsync ( "update" , Id , GetDockViewConfig ( ) ) ;
199213 }
200214 }
201215
202216 /// <summary>
203217 /// <inheritdoc />
204218 /// </summary>
205- protected override Task InvokeInitAsync ( ) => InvokeVoidAsync ( "init" , Id , Interop , GetOptions ( ) ) ;
219+ protected override Task InvokeInitAsync ( ) => InvokeVoidAsync ( "init" , Id , Interop , GetDockViewConfig ( ) ) ;
206220
207- private DockViewConfig GetOptions ( ) => new ( )
221+ private DockViewConfig GetDockViewConfig ( ) => new ( )
208222 {
209- EnableLocalStorage = EnableLocalStorage ?? _options . EnableLocalStorage ?? false ,
210- LocalStorageKey = $ " { GetPrefixKey ( ) } - { Name } - { GetVersion ( ) } " ,
223+ EnableLocalStorage = IsEnableLocalStorage ,
224+ LocalStorageKey = LocalStorageKey ,
211225 IsLock = IsLock ,
212226 ShowLock = ShowLock ,
213227 IsFloating = IsFloating ,
@@ -226,6 +240,10 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
226240 LoadTabs = nameof ( LoadTabs )
227241 } ;
228242
243+ private bool IsEnableLocalStorage => EnableLocalStorage ?? _options . EnableLocalStorage ?? false ;
244+
245+ private string ? LocalStorageKey => IsEnableLocalStorage ? $ "{ GetPrefixKey ( ) } -{ Name } -{ GetVersion ( ) } " : null ;
246+
229247 private string GetVersion ( ) => Version ?? _options . Version ?? "v1" ;
230248
231249 private string GetPrefixKey ( ) => LocalStoragePrefix ?? _options . LocalStoragePrefix ?? "bb-dockview" ;
@@ -236,7 +254,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
236254 /// </summary>
237255 public async Task Reset ( string ? layoutConfig = null )
238256 {
239- var options = GetOptions ( ) ;
257+ var options = GetDockViewConfig ( ) ;
240258 if ( layoutConfig != null )
241259 {
242260 options . LayoutConfig = layoutConfig ;
0 commit comments