diff --git a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs index 86006007f7a..e3db268a989 100644 --- a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs +++ b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs @@ -306,6 +306,9 @@ public partial class Tab : IHandlerException [NotNull] private IIconTheme? IconTheme { get; set; } + [Inject, NotNull] + private DialogService? DialogService { get; set; } + private ConcurrentDictionary LazyTabCache { get; } = new(); private bool HandlerNavigation { get; set; } @@ -792,9 +795,7 @@ private RenderFragment RenderTabItemContent(TabItem item) => builder => if (item.IsActive) { - var content = _errorContent ?? item.ChildContent; - builder.AddContent(0, content); - _errorContent = null; + builder.AddContent(0, item.ChildContent); if (IsLazyLoadTabItem) { LazyTabCache.AddOrUpdate(item, _ => true, (_, _) => true); @@ -806,19 +807,12 @@ private RenderFragment RenderTabItemContent(TabItem item) => builder => } }; - private RenderFragment? _errorContent; - /// /// HandlerException 错误处理方法 /// /// /// - public virtual Task HandlerException(Exception ex, RenderFragment errorContent) - { - _errorContent = errorContent(ex); - StateHasChanged(); - return Task.CompletedTask; - } + public Task HandlerException(Exception ex, RenderFragment errorContent) => DialogService.ShowErrorHandlerDialog(errorContent(ex)); private IEnumerable? _menuItems; private MenuItem? GetMenuItem(string url) diff --git a/src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs b/src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs index fc3f611e036..38468f9d57a 100644 --- a/src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs +++ b/src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs @@ -226,4 +226,22 @@ public static async Task ShowValidateFormDialog(this DialogService s configureOption?.Invoke(option); await service.Show(option, dialog); } + + /// + /// 显示异常信息对话框扩展方法 + /// + /// + /// + /// + /// + public static async Task ShowErrorHandlerDialog(this DialogService service, RenderFragment fragment, Dialog? dialog = null) + { + var option = new DialogOption + { + Title = "Error", + IsScrolling = true, + BodyTemplate = fragment + }; + await service.Show(option, dialog); + } } diff --git a/test/UnitTest/Components/ErrorLoggerTest.cs b/test/UnitTest/Components/ErrorLoggerTest.cs index 3baa1848598..ae3587bbd08 100644 --- a/test/UnitTest/Components/ErrorLoggerTest.cs +++ b/test/UnitTest/Components/ErrorLoggerTest.cs @@ -122,7 +122,7 @@ public void OnErrorHandleAsync_Tab() cut.Contains("errorLogger-click"); var button = cut.Find("button"); button.TriggerEvent("onclick", EventArgs.Empty); - cut.Contains("
TimeStamp:"); + cut.Contains("
TimeStamp:"); } [Fact]