Skip to content

Commit 9dc0431

Browse files
authored
feat(Tab): display error information in a dialog (#5590)
* refactor: 增加异常对话框扩展方法 * chore: 更改为弹窗显示异常信息 * test: 更新单元测试
1 parent 745c99f commit 9dc0431

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

src/BootstrapBlazor/Components/Tab/Tab.razor.cs

+5-11
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ public partial class Tab : IHandlerException
306306
[NotNull]
307307
private IIconTheme? IconTheme { get; set; }
308308

309+
[Inject, NotNull]
310+
private DialogService? DialogService { get; set; }
311+
309312
private ConcurrentDictionary<TabItem, bool> LazyTabCache { get; } = new();
310313

311314
private bool HandlerNavigation { get; set; }
@@ -792,9 +795,7 @@ private RenderFragment RenderTabItemContent(TabItem item) => builder =>
792795

793796
if (item.IsActive)
794797
{
795-
var content = _errorContent ?? item.ChildContent;
796-
builder.AddContent(0, content);
797-
_errorContent = null;
798+
builder.AddContent(0, item.ChildContent);
798799
if (IsLazyLoadTabItem)
799800
{
800801
LazyTabCache.AddOrUpdate(item, _ => true, (_, _) => true);
@@ -806,19 +807,12 @@ private RenderFragment RenderTabItemContent(TabItem item) => builder =>
806807
}
807808
};
808809

809-
private RenderFragment? _errorContent;
810-
811810
/// <summary>
812811
/// HandlerException 错误处理方法
813812
/// </summary>
814813
/// <param name="ex"></param>
815814
/// <param name="errorContent"></param>
816-
public virtual Task HandlerException(Exception ex, RenderFragment<Exception> errorContent)
817-
{
818-
_errorContent = errorContent(ex);
819-
StateHasChanged();
820-
return Task.CompletedTask;
821-
}
815+
public Task HandlerException(Exception ex, RenderFragment<Exception> errorContent) => DialogService.ShowErrorHandlerDialog(errorContent(ex));
822816

823817
private IEnumerable<MenuItem>? _menuItems;
824818
private MenuItem? GetMenuItem(string url)

src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs

+18
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,22 @@ public static async Task ShowValidateFormDialog<TComponent>(this DialogService s
226226
configureOption?.Invoke(option);
227227
await service.Show(option, dialog);
228228
}
229+
230+
/// <summary>
231+
/// 显示异常信息对话框扩展方法
232+
/// </summary>
233+
/// <param name="service"></param>
234+
/// <param name="fragment"></param>
235+
/// <param name="dialog"></param>
236+
/// <returns></returns>
237+
public static async Task ShowErrorHandlerDialog(this DialogService service, RenderFragment fragment, Dialog? dialog = null)
238+
{
239+
var option = new DialogOption
240+
{
241+
Title = "Error",
242+
IsScrolling = true,
243+
BodyTemplate = fragment
244+
};
245+
await service.Show(option, dialog);
246+
}
229247
}

test/UnitTest/Components/ErrorLoggerTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void OnErrorHandleAsync_Tab()
122122
cut.Contains("errorLogger-click");
123123
var button = cut.Find("button");
124124
button.TriggerEvent("onclick", EventArgs.Empty);
125-
cut.Contains("<div class=\"tabs-body-content\"><div class=\"error-stack\">TimeStamp:");
125+
cut.Contains("<div class=\"modal-body\"><div class=\"error-stack\">TimeStamp:");
126126
}
127127

128128
[Fact]

0 commit comments

Comments
 (0)