diff --git a/BootstrapAdmin-Blazor.slnf b/BootstrapAdmin-Blazor.slnf index 05f7ff60..3e5291a2 100644 --- a/BootstrapAdmin-Blazor.slnf +++ b/BootstrapAdmin-Blazor.slnf @@ -2,7 +2,8 @@ "solution": { "path": "BootstrapAdmin.sln", "projects": [ - "..\\BootstrapBlazor\\src\\BootstrapBlazor\\BootstrapBlazor.csproj", + "src\\blazor\\admin\\BootstrapAdmin.DataAccess.EFCore\\BootstrapAdmin.DataAccess.EFCore.csproj", + "src\\blazor\\admin\\BootstrapAdmin.DataAccess.Models\\BootstrapAdmin.DataAccess.Models.csproj", "src\\blazor\\admin\\BootstrapAdmin.DataAccess\\BootstrapAdmin.DataAccess.csproj", "src\\blazor\\admin\\BootstrapAdmin.Web\\BootstrapAdmin.Web.csproj", "src\\mvc\\admin\\Bootstrap.Admin\\Bootstrap.Admin.csproj", diff --git a/BootstrapAdmin.sln b/BootstrapAdmin.sln index 8b5a16f2..68703490 100644 --- a/BootstrapAdmin.sln +++ b/BootstrapAdmin.sln @@ -147,6 +147,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BootstrapAdmin.Web", "src\b EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BootstrapAdmin.DataAccess", "src\blazor\admin\BootstrapAdmin.DataAccess\BootstrapAdmin.DataAccess.csproj", "{1C04A3C2-DF68-4716-BA69-259CEC6E2311}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapAdmin.DataAccess.EFCore", "src\blazor\admin\BootstrapAdmin.DataAccess.EFCore\BootstrapAdmin.DataAccess.EFCore.csproj", "{D8ED2DF7-F7E1-4DE7-B097-D0BEE51D58E9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapAdmin.DataAccess.Models", "src\blazor\admin\BootstrapAdmin.DataAccess.Models\BootstrapAdmin.DataAccess.Models.csproj", "{7E3861AB-F797-4A9F-B7CE-0E35751FFCD9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -197,6 +201,14 @@ Global {1C04A3C2-DF68-4716-BA69-259CEC6E2311}.Debug|Any CPU.Build.0 = Debug|Any CPU {1C04A3C2-DF68-4716-BA69-259CEC6E2311}.Release|Any CPU.ActiveCfg = Release|Any CPU {1C04A3C2-DF68-4716-BA69-259CEC6E2311}.Release|Any CPU.Build.0 = Release|Any CPU + {D8ED2DF7-F7E1-4DE7-B097-D0BEE51D58E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D8ED2DF7-F7E1-4DE7-B097-D0BEE51D58E9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D8ED2DF7-F7E1-4DE7-B097-D0BEE51D58E9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D8ED2DF7-F7E1-4DE7-B097-D0BEE51D58E9}.Release|Any CPU.Build.0 = Release|Any CPU + {7E3861AB-F797-4A9F-B7CE-0E35751FFCD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7E3861AB-F797-4A9F-B7CE-0E35751FFCD9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7E3861AB-F797-4A9F-B7CE-0E35751FFCD9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7E3861AB-F797-4A9F-B7CE-0E35751FFCD9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -230,6 +242,8 @@ Global {55A2459A-6BDE-4493-B2C0-5BE1673E99EE} = {DAE3826B-AAAB-468A-9A06-2F56EF5C0767} {EF5EF5A4-616A-4BA7-9E1E-1407E8EC0395} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C} {1C04A3C2-DF68-4716-BA69-259CEC6E2311} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C} + {D8ED2DF7-F7E1-4DE7-B097-D0BEE51D58E9} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C} + {7E3861AB-F797-4A9F-B7CE-0E35751FFCD9} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {221EAE38-5F75-4391-9A48-E462A9F3B8FC} diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdmin.DataAccess.EFCore.csproj b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdmin.DataAccess.EFCore.csproj new file mode 100644 index 00000000..132c02c5 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdmin.DataAccess.EFCore.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Class1.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Class1.cs new file mode 100644 index 00000000..3efb7c69 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Class1.cs @@ -0,0 +1,7 @@ +namespace BootstrapAdmin.DataAccess.EFCore +{ + public class Class1 + { + + } +} \ No newline at end of file diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/BootstrapAdmin.DataAccess.Models.csproj b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/BootstrapAdmin.DataAccess.Models.csproj new file mode 100644 index 00000000..132c02c5 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/BootstrapAdmin.DataAccess.Models.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/BootstrapAdmin.DataAccess.Models.xml b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/BootstrapAdmin.DataAccess.Models.xml new file mode 100644 index 00000000..750aad54 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/BootstrapAdmin.DataAccess.Models.xml @@ -0,0 +1,113 @@ + + + + BootstrapAdmin.DataAccess.Models + + + + + 字典配置项 + + + + + 获得/设置 字典主键 数据库自增列 + + + + + 获得/设置 字典分类 + + + + + 获得/设置 字典名称 + + + + + 获得/设置 字典字典值 + + + + + 获得/设置 字典定义值 0 表示系统使用,1 表示用户自定义 默认为 1 + + + + + Bootstrap Admin 后台管理菜单相关操作实体类 + + + + + 获得/设置 菜单主键ID + + + + + 获得/设置 父级菜单ID 默认为 0 + + + + + 获得/设置 父级菜单名称 + + + + + 获得/设置 菜单名称 + + + + + 获得/设置 菜单序号 + + + + + 获得/设置 菜单图标 + + + + + 获得/设置 菜单URL地址 + + + + + 获得/设置 菜单分类, 0 表示系统菜单 1 表示用户自定义菜单 + + + + + 获得 菜单分类名称,取字典表中的Name category="菜单" + + + + + 获得/设置 是否当前被选中 active为选中 + + + + + 获得/设置 链接目标 + + + + + 获得/设置 是否为资源文件, 0 表示菜单 1 表示资源 2 表示按钮 + + + + + 获得/设置 所属应用程序,此属性由BA后台字典表分配 + + + + + 获得/设置 当前菜单项的所有子菜单集合 + + + + diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Models/Dict.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Dicts.cs similarity index 93% rename from src/blazor/admin/BootstrapAdmin.DataAccess/Models/Dict.cs rename to src/blazor/admin/BootstrapAdmin.DataAccess.Models/Dicts.cs index 515ecf14..3d36a3f2 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/Models/Dict.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Dicts.cs @@ -1,14 +1,11 @@ // Copyright (c) Argo Zhang (argo@163.com). All rights reserved. -using PetaPoco; - namespace BootstrapAdmin.DataAccess.Models { /// /// 字典配置项 /// - [TableName("Dicts")] - public class Dict + public class Dicts { /// /// 获得/设置 字典主键 数据库自增列 diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Models/Menu.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Navigations.cs similarity index 94% rename from src/blazor/admin/BootstrapAdmin.DataAccess/Models/Menu.cs rename to src/blazor/admin/BootstrapAdmin.DataAccess.Models/Navigations.cs index 276fd655..cf522c28 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/Models/Menu.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Navigations.cs @@ -1,14 +1,11 @@ // Copyright (c) Argo Zhang (argo@163.com). All rights reserved. -using PetaPoco; - namespace BootstrapAdmin.DataAccess.Models { /// /// Bootstrap Admin 后台管理菜单相关操作实体类 /// - [TableName("Navigations")] - public class Menu + public class Navigations { /// /// 获得/设置 菜单主键ID @@ -78,6 +75,6 @@ namespace BootstrapAdmin.DataAccess.Models /// /// 获得/设置 当前菜单项的所有子菜单集合 /// - public List Menus { get; } = new List(); + public List Menus { get; } = new List(); } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Admin.DataAccess.xml b/src/blazor/admin/BootstrapAdmin.DataAccess/Admin.DataAccess.xml deleted file mode 100644 index 55e533dd..00000000 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/Admin.DataAccess.xml +++ /dev/null @@ -1,154 +0,0 @@ - - - - Admin.DataAccess - - - - - - - - - - - - - - - - - 字典配置项 - - - - - 获得/设置 字典主键 数据库自增列 - - - - - 获得/设置 字典分类 - - - - - 获得/设置 字典名称 - - - - - 获得/设置 字典字典值 - - - - - 获得/设置 字典定义值 0 表示系统使用,1 表示用户自定义 默认为 1 - - - - - Bootstrap Admin 后台管理菜单相关操作实体类 - - - - - 获得/设置 菜单主键ID - - - - - 获得/设置 父级菜单ID 默认为 0 - - - - - 获得/设置 父级菜单名称 - - - - - 获得/设置 菜单名称 - - - - - 获得/设置 菜单序号 - - - - - 获得/设置 菜单图标 - - - - - 获得/设置 菜单URL地址 - - - - - 获得/设置 菜单分类, 0 表示系统菜单 1 表示用户自定义菜单 - - - - - 获得 菜单分类名称,取字典表中的Name category="菜单" - - - - - 获得/设置 是否当前被选中 active为选中 - - - - - 获得/设置 链接目标 - - - - - 获得/设置 是否为资源文件, 0 表示菜单 1 表示资源 2 表示按钮 - - - - - 获得/设置 所属应用程序,此属性由BA后台字典表分配 - - - - - 获得/设置 当前菜单项的所有子菜单集合 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.csproj b/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.csproj index ea305de9..04834b3c 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.csproj +++ b/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.csproj @@ -7,15 +7,17 @@ - + - - + + + + diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.xml b/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.xml index 3df8e3f4..fe3f04d3 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.xml +++ b/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.xml @@ -4,165 +4,6 @@ BootstrapAdmin.DataAccess - - - - - - - - - - - - - - - 字典配置项 - - - - - 获得/设置 字典主键 数据库自增列 - - - - - 获得/设置 字典分类 - - - - - 获得/设置 字典名称 - - - - - 获得/设置 字典字典值 - - - - - 获得/设置 字典定义值 0 表示系统使用,1 表示用户自定义 默认为 1 - - - - - Bootstrap Admin 后台管理菜单相关操作实体类 - - - - - 获得/设置 菜单主键ID - - - - - 获得/设置 父级菜单ID 默认为 0 - - - - - 获得/设置 父级菜单名称 - - - - - 获得/设置 菜单名称 - - - - - 获得/设置 菜单序号 - - - - - 获得/设置 菜单图标 - - - - - 获得/设置 菜单URL地址 - - - - - 获得/设置 菜单分类, 0 表示系统菜单 1 表示用户自定义菜单 - - - - - 获得 菜单分类名称,取字典表中的Name category="菜单" - - - - - 获得/设置 是否当前被选中 active为选中 - - - - - 获得/设置 链接目标 - - - - - 获得/设置 是否为资源文件, 0 表示菜单 1 表示资源 2 表示按钮 - - - - - 获得/设置 所属应用程序,此属性由BA后台字典表分配 - - - - - 获得/设置 当前菜单项的所有子菜单集合 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 获得带层次关系的菜单集合 - - 未层次化菜单集合 - 带层次化的菜单集合 - - - - 获得指定用户名可访问的所有菜单集合 - - 当前用户名 - 未层次化的菜单集合 - @@ -175,5 +16,39 @@ + + + Dict 字典表接口 + + + + + + + + + + + + + + + + + + + + + + + + + + + 获得指定用户名可访问的所有菜单集合 + + 当前用户名 + 未层次化的菜单集合 + diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Extensions/MenuItemExtensions.cs b/src/blazor/admin/BootstrapAdmin.DataAccess/Extensions/MenuItemExtensions.cs deleted file mode 100644 index 2d49a4f4..00000000 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/Extensions/MenuItemExtensions.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.AspNetCore.Components.Routing; - -namespace BootstrapAdmin.DataAccess.Extensions -{ - /// - /// - /// - public static class MenuItemExtensions - { - /// - /// - /// - /// - /// - public static MenuItem Parse(this Models.Menu menu) => new() - { - Text = menu.Name, - Url = menu.Url.Replace("~", ""), - Icon = menu.Icon, - Match = NavLinkMatch.All, - Target = menu.Target, - Id = menu.Id, - ParentId = menu.ParentId - }; - } -} diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Extensions/ServicesExtensions.cs b/src/blazor/admin/BootstrapAdmin.DataAccess/Extensions/ServicesExtensions.cs index d5620d0e..5c4d0d7f 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/Extensions/ServicesExtensions.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess/Extensions/ServicesExtensions.cs @@ -26,8 +26,8 @@ namespace Microsoft.Extensions.DependencyInjection return new Database(connString); }); - services.TryAddSingleton(); - services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); return services; } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/DictService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess/Services/DictsService.cs similarity index 84% rename from src/blazor/admin/BootstrapAdmin.DataAccess/Services/DictService.cs rename to src/blazor/admin/BootstrapAdmin.DataAccess/Services/DictsService.cs index 103d0a70..e0f288fa 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/DictService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess/Services/DictsService.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace BootstrapAdmin.DataAccess.Services { - class DictService : IDict + class DictsService : IDicts { } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/IDict.cs b/src/blazor/admin/BootstrapAdmin.DataAccess/Services/IDict.cs deleted file mode 100644 index a0602235..00000000 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/IDict.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BootstrapAdmin.DataAccess.Services -{ - /// - /// Dict 字典表接口 - /// - public interface IDict - { - } -} diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/IDicts.cs b/src/blazor/admin/BootstrapAdmin.DataAccess/Services/IDicts.cs new file mode 100644 index 00000000..69f362ab --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.DataAccess/Services/IDicts.cs @@ -0,0 +1,9 @@ +namespace BootstrapAdmin.DataAccess.Services +{ + /// + /// Dict 字典表接口 + /// + public interface IDicts + { + } +} diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/IMenu.cs b/src/blazor/admin/BootstrapAdmin.DataAccess/Services/INavigations.cs similarity index 71% rename from src/blazor/admin/BootstrapAdmin.DataAccess/Services/IMenu.cs rename to src/blazor/admin/BootstrapAdmin.DataAccess/Services/INavigations.cs index e8e74748..02e68470 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/IMenu.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess/Services/INavigations.cs @@ -5,12 +5,12 @@ namespace BootstrapAdmin.DataAccess.Services /// /// /// - public interface IMenu + public interface INavigations { /// /// /// /// - IEnumerable GetAdminMenusByUser(string userName); + List RetrieveAllMenus(string userName); } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/MenuService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess/Services/MenuService.cs deleted file mode 100644 index 7c634c4b..00000000 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/MenuService.cs +++ /dev/null @@ -1,64 +0,0 @@ -using BootstrapAdmin.DataAccess.Extensions; -using PetaPoco; - -namespace BootstrapAdmin.DataAccess.Services -{ - /// - /// - /// - class MenuService : IMenu - { - private IDatabase _db; - - /// - /// - /// - /// - public MenuService(IDatabase db) => _db = db; - - /// - /// - /// - /// - public IEnumerable GetAdminMenusByUser(string userName) - { - var menus = RetrieveAllMenus(userName).Where(m => m.Category == "0" && m.IsResource == 0); - return CascadeMenus(menus); - } - - /// - /// 获得带层次关系的菜单集合 - /// - /// 未层次化菜单集合 - /// 带层次化的菜单集合 - public static IEnumerable CascadeMenus(IEnumerable menus) - { - var root = menus.Where(m => m.ParentId == "0") - .OrderBy(m => m.Category).ThenBy(m => m.Application).ThenBy(m => m.Order) - .Select(m => m.Parse()) - .ToList(); - CascadeMenus(menus, root); - return root; - } - - private static void CascadeMenus(IEnumerable navs, List level) - { - level.ForEach(m => - { - m.Items = navs.Where(sub => sub.ParentId == m.Id).OrderBy(sub => sub.Order).Select(sub => sub.Parse()).ToList(); - CascadeMenus(navs, m.Items.ToList()); - }); - } - - /// - /// 获得指定用户名可访问的所有菜单集合 - /// - /// 当前用户名 - /// 未层次化的菜单集合 - private List RetrieveAllMenus(string userName) - { - var order = _db.Provider.EscapeSqlIdentifier("Order"); - return _db.Fetch($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID inner join (select nr.NavigationID from Users u inner join UserRole ur on ur.UserID = u.ID inner join NavigationRole nr on nr.RoleID = ur.RoleID where u.UserName = @UserName union select nr.NavigationID from Users u inner join UserGroup ug on u.ID = ug.UserID inner join RoleGroup rg on rg.GroupID = ug.GroupID inner join NavigationRole nr on nr.RoleID = rg.RoleID where u.UserName = @UserName union select n.ID from Navigations n where EXISTS (select UserName from Users u inner join UserRole ur on u.ID = ur.UserID inner join Roles r on ur.RoleID = r.ID where u.UserName = @UserName and r.RoleName = @RoleName)) nav on n.ID = nav.NavigationID", new { UserName = userName, Category = "菜单", RoleName = "Administrators" }); - } - } -} diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/NavigationsService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess/Services/NavigationsService.cs new file mode 100644 index 00000000..c18a3e26 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.DataAccess/Services/NavigationsService.cs @@ -0,0 +1,30 @@ +using BootstrapAdmin.DataAccess.Models; +using PetaPoco; + +namespace BootstrapAdmin.DataAccess.Services +{ + /// + /// + /// + class NavigationsService : INavigations + { + private IDatabase _db; + + /// + /// + /// + /// + public NavigationsService(IDatabase db) => _db = db; + + /// + /// 获得指定用户名可访问的所有菜单集合 + /// + /// 当前用户名 + /// 未层次化的菜单集合 + public List RetrieveAllMenus(string userName) + { + var order = _db.Provider.EscapeSqlIdentifier("Order"); + return _db.Fetch($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID inner join (select nr.NavigationID from Users u inner join UserRole ur on ur.UserID = u.ID inner join NavigationRole nr on nr.RoleID = ur.RoleID where u.UserName = @UserName union select nr.NavigationID from Users u inner join UserGroup ug on u.ID = ug.UserID inner join RoleGroup rg on rg.GroupID = ug.GroupID inner join NavigationRole nr on nr.RoleID = rg.RoleID where u.UserName = @UserName union select n.ID from Navigations n where EXISTS (select UserName from Users u inner join UserRole ur on u.ID = ur.UserID inner join Roles r on ur.RoleID = r.ID where u.UserName = @UserName and r.RoleName = @RoleName)) nav on n.ID = nav.NavigationID", new { UserName = userName, Category = "菜单", RoleName = "Administrators" }); + } + } +} diff --git a/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.csproj b/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.csproj index 6f5edc96..87ded732 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.csproj +++ b/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.csproj @@ -5,6 +5,10 @@ enable + + + + diff --git a/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.xml b/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.xml index 8eb70c9d..9316ee40 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.xml +++ b/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.xml @@ -83,6 +83,31 @@ + + + + + + + + + + + + + + + + + + + + + 获得带层次关系的菜单集合 + + 未层次化菜单集合 + 带层次化的菜单集合 + diff --git a/src/blazor/admin/BootstrapAdmin.Web/Extensions/MenuExtensions.cs b/src/blazor/admin/BootstrapAdmin.Web/Extensions/MenuExtensions.cs new file mode 100644 index 00000000..9277b170 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.Web/Extensions/MenuExtensions.cs @@ -0,0 +1,61 @@ +using BootstrapAdmin.DataAccess.Models; +using Microsoft.AspNetCore.Components.Routing; + +namespace BootstrapAdmin.Web.Extensions +{ + /// + /// + /// + public static class MenuExtensions + { + /// + /// + /// + /// + /// + public static MenuItem Parse(this DataAccess.Models.Navigations 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 ToAdminMenus(this List navigations) + { + var menus = navigations.Where(m => m.Category == "0" && 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/admin/BootstrapAdmin.Web/Models/DictsSearchModel.cs b/src/blazor/admin/BootstrapAdmin.Web/Models/DictsSearchModel.cs index b31f9306..2d64a657 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Models/DictsSearchModel.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Models/DictsSearchModel.cs @@ -32,17 +32,17 @@ namespace BootstrapAdmin.Web.Models if (!string.IsNullOrEmpty(Name)) { - ret.Add(new SearchFilterAction(nameof(Dict.Name), Name)); + ret.Add(new SearchFilterAction(nameof(Dicts.Name), Name)); } if (!string.IsNullOrEmpty(Category)) { - ret.Add(new SearchFilterAction(nameof(Dict.Category), Category)); + ret.Add(new SearchFilterAction(nameof(Dicts.Category), Category)); } if (Define.HasValue) { - ret.Add(new SearchFilterAction(nameof(Dict.Define), Define, FilterAction.Equal)); + ret.Add(new SearchFilterAction(nameof(Dicts.Define), Define, FilterAction.Equal)); } return ret; diff --git a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Dicts.razor b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Dicts.razor index 5655b23c..c9f9b477 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Dicts.razor +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Dicts.razor @@ -1,6 +1,6 @@ @page "/Admin/Dicts" - + diff --git a/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs index 75994be0..898d4c68 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs @@ -1,4 +1,5 @@ using BootstrapAdmin.DataAccess.Services; +using BootstrapAdmin.Web.Extensions; namespace BootstrapAdmin.Web.Shared { @@ -11,7 +12,7 @@ namespace BootstrapAdmin.Web.Shared [Inject] [NotNull] - private IMenu? MenuService { get; set; } + private INavigations? NavigationsService { get; set; } /// /// @@ -20,7 +21,7 @@ namespace BootstrapAdmin.Web.Shared { base.OnInitialized(); - MenuItems = MenuService.GetAdminMenusByUser("Admin"); + MenuItems = NavigationsService.RetrieveAllMenus("Admin").ToAdminMenus(); } } }