diff --git a/src/blazor/admin/BootstrapAdmin.Extensions/BootstrapAdmin.Extensions.csproj b/src/blazor/admin/BootstrapAdmin.Extensions/BootstrapAdmin.Extensions.csproj deleted file mode 100644 index aa74cd55..00000000 --- a/src/blazor/admin/BootstrapAdmin.Extensions/BootstrapAdmin.Extensions.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/src/blazor/admin/BootstrapAdmin.Extensions/MenuExtensions.cs b/src/blazor/admin/BootstrapAdmin.Web/Extensions/MenuExtensions.cs similarity index 97% rename from src/blazor/admin/BootstrapAdmin.Extensions/MenuExtensions.cs rename to src/blazor/admin/BootstrapAdmin.Web/Extensions/MenuExtensions.cs index a39b75d6..ec9f96c0 100644 --- a/src/blazor/admin/BootstrapAdmin.Extensions/MenuExtensions.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Extensions/MenuExtensions.cs @@ -1,8 +1,7 @@ using BootstrapAdmin.DataAccess.Models; -using BootstrapBlazor.Components; using Microsoft.AspNetCore.Components.Routing; -namespace BootstrapAdmin.Extensions +namespace BootstrapAdmin.Web.Extensions { /// /// diff --git a/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs index 9c7b4068..43de6e2c 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs @@ -1,6 +1,6 @@ using Bootstrap.Security.Blazor; -using BootstrapAdmin.Extensions; using BootstrapAdmin.Web.Core; +using BootstrapAdmin.Web.Extensions; using BootstrapAdmin.Web.Services; using Microsoft.AspNetCore.Components.Authorization; diff --git a/src/blazor/client/BootstrapClient.Shared/Extensions/MenuExtensions.cs b/src/blazor/client/BootstrapClient.Shared/Extensions/MenuExtensions.cs new file mode 100644 index 00000000..3ded5acb --- /dev/null +++ b/src/blazor/client/BootstrapClient.Shared/Extensions/MenuExtensions.cs @@ -0,0 +1,61 @@ +using BootstrapAdmin.DataAccess.Models; +using BootstrapBlazor.Components; +using Microsoft.AspNetCore.Components.Routing; + +namespace BootstrapClient.Web.Shared.Extensions; + +/// +/// +/// +public static class MenuExtensions +{ + /// + /// + /// + /// + /// + public static MenuItem Parse(this Navigation menu) => new() + { + Text = menu.Name, + Url = menu.Url.Replace("~", ""), + Icon = menu.Icon, + Match = NavLinkMatch.All, + Target = menu.Target, + Id = menu.Id, + ParentId = menu.ParentId + }; + + /// + /// 获取前台菜单 + /// + /// + public static IEnumerable ToClientMenus(this List navigations) + { + var menus = navigations.Where(m => m.Category == EnumNavigationCategory.Customer && m.IsResource == 0); + return CascadeMenus(menus); + } + + /// + /// 获得带层次关系的菜单集合 + /// + /// 未层次化菜单集合 + /// 带层次化的菜单集合 + public static IEnumerable CascadeMenus(IEnumerable navigations) + { + var root = navigations.Where(m => m.ParentId == "0") + .OrderBy(m => m.Category).ThenBy(m => m.Application).ThenBy(m => m.Order) + .Select(m => m.Parse()) + .ToList(); + CascadeMenus(navigations, root); + return root; + } + + private static void CascadeMenus(IEnumerable navigations, List level) + { + level.ForEach(m => + { + m.Items = navigations.Where(sub => sub.ParentId == m.Id).OrderBy(sub => sub.Order).Select(sub => sub.Parse()).ToList(); + CascadeMenus(navigations, m.Items.ToList()); + }); + } +} diff --git a/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor.cs b/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor.cs index 93fe56a9..2cf2f6c3 100644 --- a/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor.cs +++ b/src/blazor/client/BootstrapClient.Shared/Shared/MainLayout.razor.cs @@ -1,7 +1,7 @@ using Bootstrap.Security.Blazor; -using BootstrapAdmin.Extensions; using BootstrapAdmin.Web.Core; using BootstrapBlazor.Components; +using BootstrapClient.Web.Shared.Extensions; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization;