diff --git a/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor b/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor index d52574d9..9ef05393 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor +++ b/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor @@ -1,6 +1,13 @@ -@inherits AssignmentBase +@inherits ComponentBase - +
+ + + +
@code { RenderFragment RenderTreeItem => item => diff --git a/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor.cs index 0a2aba6c..470733dd 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor.cs @@ -2,6 +2,7 @@ // Licensed under the LGPL License, Version 3.0. See License.txt in the project root for license information. // Website: https://admin.blazor.zone +using BootstrapAdmin.DataAccess.Models; using BootstrapAdmin.Web.Core; using BootstrapAdmin.Web.Extensions; @@ -15,10 +16,45 @@ public partial class NavigationTree [NotNull] private List? InternalItems { get; set; } + [NotNull] + private Tree? MenusTree { get; set; } + [Inject] [NotNull] private IDict? DictService { get; set; } + /// + /// + /// + [Parameter] + [EditorRequired] + [NotNull] + public List? Items { get; set; } + + /// + /// + /// + [Parameter] + [EditorRequired] + [NotNull] + public List? Value { get; set; } + + /// + /// 关闭弹窗回调委托 + /// + [Parameter] + [EditorRequired] + [NotNull] + public Func? OnClose { get; set; } + + /// + /// 保存按钮回调委托 + /// + [Parameter] + [EditorRequired] + [NotNull] + public Func, Task>? OnSave { get; set; } + /// /// /// @@ -29,12 +65,9 @@ public partial class NavigationTree InternalItems = Items.ToTreeItemList(Value, RenderTreeItem); } - private Task OnTreeItemChecked(List items) - { - Value = items.Select(i => i.Key!.ToString()!).ToList(); - OnValueChanged(Value); - return Task.CompletedTask; - } - private string GetApp(string? app) => DictService.GetApps().FirstOrDefault(i => i.Key == app).Value ?? "未设置"; + + private Task OnClickClose() => OnClose(); + + private Task OnClickSave() => OnSave(MenusTree.GetCheckedItems().Select(i => i.Key?.ToString()).ToList()); } diff --git a/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor.css b/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor.css new file mode 100644 index 00000000..2ed048f2 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.Web/Components/NavigationTree.razor.css @@ -0,0 +1,13 @@ +.tree-menu { + display: flex; + flex-direction: column; +} + + .tree-menu ::deep .tree { + flex: 1; + margin: -1rem; + padding: 1rem; + max-height: calc(100vh - 173px); + overflow-y: auto; + overflow-x: hidden; + } diff --git a/src/blazor/admin/BootstrapAdmin.Web/Extensions/DialogExtensions.cs b/src/blazor/admin/BootstrapAdmin.Web/Extensions/DialogExtensions.cs index 091886e6..d7d709df 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Extensions/DialogExtensions.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Extensions/DialogExtensions.cs @@ -18,9 +18,48 @@ public static class DialogExtensions public static Task ShowAssignmentDialog(this DialogService dialogService, string title, List items, List value, Func> saveCallback, ToastService? toast) => dialogService.ShowDialog(title, items, value, saveCallback, toast); /// - /// + /// 弹出菜单分配弹窗 /// - public static Task ShowNavigationDialog(this DialogService dialogService, string title, List items, List value, Func> saveCallback, ToastService? toast) => dialogService.ShowDialog(title, items, value, saveCallback, toast); + /// + /// 弹窗标题 + /// 当前用户可用所有菜单集合 + /// 已分配菜单集合 + /// + /// + /// + public static async Task ShowNavigationDialog(this DialogService dialogService, string title, List menus, List value, Func, Task> saveCallback, ToastService? toast) + { + var option = new DialogOption + { + Title = title, + ShowFooter = false, + IsScrolling = true, + Class = "modal-dialog-menu" + }; + var parameters = new Dictionary() + { + [nameof(NavigationTree.Items)] = menus, + [nameof(NavigationTree.Value)] = value, + [nameof(NavigationTree.OnClose)] = () => option.Dialog.Close(), + [nameof(NavigationTree.OnSave)] = new Func, Task>(async items => + { + var ret = await saveCallback(items); + if (toast != null) + { + if (ret) + { + await toast.Success("分配操作", "操作成功!"); + } + else + { + await toast.Error("分配操作", "操作失败,请联系相关管理员!"); + } + } + }) + }; + option.Component = BootstrapDynamicComponent.CreateComponent(parameters); + await dialogService.Show(option); + } private static Task ShowDialog(this DialogService dialogService, string title, List items, List value, Func> saveCallback, ToastService? toast) where TBody : AssignmentBase => dialogService.ShowSaveDialog(title, async () => { diff --git a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Roles.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Roles.razor.cs index 2f1ed67c..653b6155 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Roles.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Roles.razor.cs @@ -72,12 +72,12 @@ public partial class Roles private async Task OnAssignmentMenus(Role role) { - var apps = NavigationService.GetAllMenus(AppContext.UserName); + var menus = NavigationService.GetAllMenus(AppContext.UserName); var values = NavigationService.GetMenusByRoleId(role.Id); - await DialogService.ShowNavigationDialog($"分配菜单 - 当前角色: {role.RoleName}", apps, values, () => + await DialogService.ShowNavigationDialog($"分配菜单 - 当前角色: {role.RoleName}", menus, values, items => { - var ret = NavigationService.SaveMenusByRoleId(role.Id, values); + var ret = NavigationService.SaveMenusByRoleId(role.Id, items); return Task.FromResult(ret); }, ToastService); } diff --git a/src/blazor/admin/BootstrapAdmin.Web/wwwroot/css/site.css b/src/blazor/admin/BootstrapAdmin.Web/wwwroot/css/site.css index 20cd684d..fe5a31a9 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/wwwroot/css/site.css +++ b/src/blazor/admin/BootstrapAdmin.Web/wwwroot/css/site.css @@ -127,3 +127,7 @@ .layout-menu { border-right: 1px solid #ddd; } + +.modal-dialog-menu.modal-dialog-scrollable .modal-body { + overflow: hidden; +}