From 25fae681ae75bb03c5db7fb3c25489c223eb5424 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Mon, 24 Jan 2022 01:06:43 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E5=AD=97?= =?UTF-8?q?=E5=85=B8=E8=A1=A8=E4=B8=AD=E8=8F=9C=E5=8D=95=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/SQLite/InitData.sql | 2 -- .../EnumNavigationCategory.cs | 4 ++-- .../Services/NavigationService.cs | 2 +- .../Services/UserService.cs | 2 +- .../BootstrapAdmin.Web/BootstrapAdmin.db | Bin 217088 -> 217088 bytes .../Extensions/MenuExtensions.cs | 20 +++++------------- .../Shared/MainLayout.razor.cs | 2 +- 7 files changed, 10 insertions(+), 22 deletions(-) diff --git a/db/SQLite/InitData.sql b/db/SQLite/InitData.sql index 803188fd..45c39201 100644 --- a/db/SQLite/InitData.sql +++ b/db/SQLite/InitData.sql @@ -5,8 +5,6 @@ INSERT INTO Users (UserName, Password, PassSalt, DisplayName, RegisterTime, Appr INSERT INTO Users (UserName, Password, PassSalt, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, [Description], [App]) values ('User', 'tXG/yNffpnm6cThrCH7wf6jN1ic3VHvLoY4OrzKtrZ4=', 'c5cIrRMn8XjB84M/D/X7Lg9uUqQFmYNEdxb/4HWH8OLa4pNZ', '测试账号', datetime(CURRENT_TIMESTAMP, 'localtime'), datetime(CURRENT_TIMESTAMP, 'localtime'), 'system', '系统默认创建', 'Demo'); DELETE From Dicts Where Define = 0; -INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('菜单', '系统菜单', '0', 0); -INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('菜单', '外部菜单', '1', 0); INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('应用程序', '后台管理', 'BA', 0); INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('网站设置', '网站标题', '后台管理系统', 0); INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('网站设置', '网站页脚', '2016 © 通用后台管理系统', 0); diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumNavigationCategory.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumNavigationCategory.cs index 68ed3f36..06763f6c 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumNavigationCategory.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumNavigationCategory.cs @@ -10,12 +10,12 @@ public enum EnumNavigationCategory /// /// 系统使用 /// - [Description("系统使用")] + [Description("后台菜单")] System, /// /// 用户自定义 /// - [Description("自定义")] + [Description("前台菜单")] Customer } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/NavigationService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/NavigationService.cs index 2653328f..b4f70a84 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/NavigationService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/NavigationService.cs @@ -29,7 +29,7 @@ class NavigationService : INavigation return CacheManager.GetOrAdd($"{nameof(NavigationService)}-{nameof(GetAllMenus)}-{userName}", entry => { var order = Database.Provider.EscapeSqlIdentifier("Order"); - return Database.Fetch($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = @Define 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 ORDER BY n.Application, n.{order}", new { UserName = userName, Category = "菜单", RoleName = "Administrators", Define = EnumDictDefine.System }); + return Database.Fetch($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application from Navigations n 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 ORDER BY n.Application, n.{order}", new { UserName = userName, RoleName = "Administrators" }); }); } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/UserService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/UserService.cs index 73478ec1..c4be47a4 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/UserService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/UserService.cs @@ -68,7 +68,7 @@ class UserService : IUser /// /// /// - public List GetRoles(string userName) => Database.Fetch($"select r.RoleName from Roles r inner join UserRole ur on r.ID=ur.RoleID inner join Users u on ur.UserID = u.ID and u.UserName = @0 union select r.RoleName from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID and u.UserName=@0", userName); + public List GetRoles(string userName) => Database.Fetch($"select r.RoleName from Roles r inner join UserRole ur on r.ID=ur.RoleID inner join Users u on ur.UserID = u.ID and u.UserName = @0 union select r.RoleName from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID and u.UserName = @0", userName); /// /// diff --git a/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.db b/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.db index 079d3c5bab170f970cee4e7aa6f9c849f7a32d89..040ea33cb58d941afb599563dc0a5bb9ed0d9e63 100644 GIT binary patch delta 461 zcmZozz}v8ZcY-u;3j+g#DG-CfL=AJsmW>I^_}R*s_{#VlHw!9k=AFD>cB?1@L!%p` z0E2jHuDY?Yq#;PPtl;DevU4WClNaDh$|+6NOD-;Ua@=e$e{=(j0}BW1WS$EROf2!6 zyDoTev-6)|&{Q=Poc#Wl{N^9GFEFzJ^;=A?xg-H%$ZURbU#5UVfPXp2Skvh|0gQ4? z{L7~=Y-5z!?h(Kk&(8)FH)&F6UmMT3eQi8b_yuMmhQ8_S2F&toOzw<141JRY1(H}A zqnZ?^D{f|z5;RdTFt9SUv@$f(Gcz=|ur!#ya5N1;67f55OW)E#r2ZOK FH2^gPd!zsW delta 432 zcmZozz}v8ZcY-u;4Fdy%DHJnK)G%kP*_g15pRI(6uY})mv!KFe-pTuAw+c0SFbXh; zr{<~~8%r7jl{3grJ}*0W@;i9}o}`@8RK4WlVwcq1{LS|AM>lXdv2d{RKjA+ynd3sk z=AH{~-0VONnyQ9^li%Nx-~8kD1!g8GrpZ;8q?sAn7&gDSFH^w5&%YLAs>yVo07f}R zq3H|S7-hG66fmapx37(7+`cxRDf|L6KeOs|b^~Vl&4L2|nOGXbn`EaKnlsC9_b_JO z!NUjA4+8wh`P=wiw(~hKC-91-=A;=pIa+aZGcp=7%F6SL^9%A!?(Ws&v*hAtkz zL4?4jvrXRIr@?2$3K5b9sbZb{qEC&_oCPAJ3KC+OEZwgSbRkd(=q#`sm?sDKoAB8) Vf!&}97Gjz_rQeK^bMonaQvekHVp;$I diff --git a/src/blazor/admin/BootstrapAdmin.Web/Extensions/MenuExtensions.cs b/src/blazor/admin/BootstrapAdmin.Web/Extensions/MenuExtensions.cs index ec9f96c0..cde686e9 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Extensions/MenuExtensions.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Extensions/MenuExtensions.cs @@ -16,7 +16,7 @@ namespace BootstrapAdmin.Web.Extensions public static MenuItem Parse(this DataAccess.Models.Navigation menu) => new() { Text = menu.Name, - Url = menu.Url.Replace("~", ""), + Url = menu.Url.Replace("~/", "/"), Icon = menu.Icon, Match = NavLinkMatch.All, Target = menu.Target, @@ -24,21 +24,11 @@ namespace BootstrapAdmin.Web.Extensions 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 ToAdminMenus(this List navigations) + public static IEnumerable ToMenus(this IEnumerable navigations) { var menus = navigations.Where(m => m.Category == EnumNavigationCategory.System && m.IsResource == 0); return CascadeMenus(menus); @@ -52,9 +42,9 @@ namespace BootstrapAdmin.Web.Extensions 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(); + .OrderBy(m => m.Category).ThenBy(m => m.Application).ThenBy(m => m.Order) + .Select(m => m.Parse()) + .ToList(); CascadeMenus(navigations, root); return root; } diff --git a/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs index 2d612b03..c007216a 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs @@ -133,7 +133,7 @@ namespace BootstrapAdmin.Web.Shared Context.DisplayName = DisplayName; Icon = string.IsNullOrEmpty(user?.Icon) ? "/images/uploader/default.jpg" : GetIcon(user.Icon); - MenuItems = NavigationsService.GetAllMenus(UserName).ToAdminMenus(); + MenuItems = NavigationsService.GetAllMenus(UserName).ToMenus(); } Title = DictsService.GetWebTitle();