Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/BootstrapBlazor/Components/Tab/Tab.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ public partial class Tab : IHandlerException
[NotNull]
private IIconTheme? IconTheme { get; set; }

[Inject, NotNull]
private DialogService? DialogService { get; set; }

private ConcurrentDictionary<TabItem, bool> LazyTabCache { get; } = new();

private bool HandlerNavigation { get; set; }
Expand Down Expand Up @@ -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);
Expand All @@ -806,19 +807,12 @@ private RenderFragment RenderTabItemContent(TabItem item) => builder =>
}
};

private RenderFragment? _errorContent;

/// <summary>
/// HandlerException 错误处理方法
/// </summary>
/// <param name="ex"></param>
/// <param name="errorContent"></param>
public virtual Task HandlerException(Exception ex, RenderFragment<Exception> errorContent)
{
_errorContent = errorContent(ex);
StateHasChanged();
return Task.CompletedTask;
}
public Task HandlerException(Exception ex, RenderFragment<Exception> errorContent) => DialogService.ShowErrorHandlerDialog(errorContent(ex));

private IEnumerable<MenuItem>? _menuItems;
private MenuItem? GetMenuItem(string url)
Expand Down
18 changes: 18 additions & 0 deletions src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,22 @@ public static async Task ShowValidateFormDialog<TComponent>(this DialogService s
configureOption?.Invoke(option);
await service.Show(option, dialog);
}

/// <summary>
/// 显示异常信息对话框扩展方法
/// </summary>
/// <param name="service"></param>
/// <param name="fragment"></param>
/// <param name="dialog"></param>
/// <returns></returns>
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);
}
}
Loading