From efd12be8e6a414c740ed6df7f0e3c684800970e7 Mon Sep 17 00:00:00 2001 From: zhaoy <137053305@qq.com> Date: Mon, 8 Jan 2024 10:34:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=A0=91=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../System/Dtos/MenuRouteDtoOutput.cs | 54 +++++++++++++++++++ .../System/Interface/IMenuService.cs | 1 + .../System/MenuServices.cs | 9 +++- .../System/Services/MenuService.cs | 44 +++++++++++++++ .../BPA.SAAS.Manage.Web.Entry.csproj.user | 2 +- 5 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 BPA.SAAS.Manage.Application/System/Dtos/MenuRouteDtoOutput.cs diff --git a/BPA.SAAS.Manage.Application/System/Dtos/MenuRouteDtoOutput.cs b/BPA.SAAS.Manage.Application/System/Dtos/MenuRouteDtoOutput.cs new file mode 100644 index 0000000..57c1b80 --- /dev/null +++ b/BPA.SAAS.Manage.Application/System/Dtos/MenuRouteDtoOutput.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.System.Dtos +{ + public class MenuRouteDtoOutput + { + + public string Id { get; set; } + /// + /// 组件 + /// + public string Component { get; set; } + /// + /// 路劲 + /// + public string Path { get; set; } + /// + /// 图标 + /// + public string Icon { get; set; } + /// + /// 名称 + /// + public string Name { get; set; } + /// + /// 路由 + /// + public List Routes { get; set; } + } + public class MenuRouteChildDtoOutput + { + public string Id { get; set; } + /// + /// 组件 + /// + public string Component { get; set; } + /// + /// 路劲 + /// + public string Path { get; set; } + /// + /// 名称 + /// + public string Name { get; set; } + /// + /// 路由 + /// + public List Routes { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/System/Interface/IMenuService.cs b/BPA.SAAS.Manage.Application/System/Interface/IMenuService.cs index f0578bb..36106d7 100644 --- a/BPA.SAAS.Manage.Application/System/Interface/IMenuService.cs +++ b/BPA.SAAS.Manage.Application/System/Interface/IMenuService.cs @@ -14,6 +14,7 @@ namespace BPA.SAAS.Manage.Application.System.Interface Task Update(MenuDtoInput input); Task Delete(List input); Task> MenuTree(string getType); + Task> DymicMenuTree(); Task Enable(string Id); Task Disable(string Id); } diff --git a/BPA.SAAS.Manage.Application/System/MenuServices.cs b/BPA.SAAS.Manage.Application/System/MenuServices.cs index cd8548a..71718e4 100644 --- a/BPA.SAAS.Manage.Application/System/MenuServices.cs +++ b/BPA.SAAS.Manage.Application/System/MenuServices.cs @@ -54,13 +54,18 @@ namespace BPA.SAAS.Manage.Application.System /// /// 查询菜单树 /// - /// + /// /// - [HttpGet("/api/menu/menutree")] + [HttpGet("/api/menu/menutrees")] public async Task> MenuTree(string getType) { return await _menuService.MenuTree(getType); } + [HttpGet("/api/menu/menutree")] + public async Task> DymicMenuTree() + { + return await _menuService.DymicMenuTree(); + } [HttpGet("/api/menu/enable")] public async Task Enable(string Id) { diff --git a/BPA.SAAS.Manage.Application/System/Services/MenuService.cs b/BPA.SAAS.Manage.Application/System/Services/MenuService.cs index 4567a8e..f2aa9af 100644 --- a/BPA.SAAS.Manage.Application/System/Services/MenuService.cs +++ b/BPA.SAAS.Manage.Application/System/Services/MenuService.cs @@ -226,6 +226,50 @@ namespace BPA.SAAS.Manage.Application.System.Services } /// + /// 动态菜单(菜单树) + /// + /// + public async Task> DymicMenuTree() + { + var UserId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + var IsAdmin = App.User.FindFirst(ClaimConst.CLAINM_SUPERADMIN)?.Value; + var account = App.User.FindFirst(ClaimConst.CLAINM_ACCOUNT)?.Value; + + if (UserId == null) + return null; + List AllMenus = new List(); + if (IsAdmin == "1" && account == "admin") + AllMenus =await _db.Queryable().Where(t => t.IsDeleted == 0 && t.Status == 0).OrderBy(t => t.Sort).ToListAsync(); + else + AllMenus =await _db.Queryable().LeftJoin((t, x) => t.Id == x.SysMenuId).LeftJoin((t, x, y) => x.SysRoleId == y.SysRoleId) + .Where((t, x, y) => y.SysUserId == UserId && t.Status == 0).Select(t => t).ToListAsync(); + //菜单去重 + AllMenus = AllMenus.Where((x, i) => AllMenus.FindIndex(z => z.Id == x.Id) == i).ToList(); + var data = AllMenus.Where(t => t.Pid == null || t.Pid == "").OrderBy(t => t.Sort).Select(t => new MenuRouteDtoOutput + { + Id = t.Id, + Component = t.Component, + Icon = t.Icon, + Name = t.Name, + Path = t.Router, + Routes = AllMenus.Where(x => x.Pid == t.Id).Select(x => new MenuRouteChildDtoOutput + { + Id = t.Id, + Component = x.Component, + Name = x.Name, + Path = x.Router, + Routes = AllMenus.Where(y => y.Pid == x.Id).Select(y => new MenuRouteChildDtoOutput + { + Id = t.Id, + Component = y.Component, + Name = y.Name, + Path = y.Router + }).ToList() + }).ToList() + }).ToList(); + return data; + } + /// /// 启用 /// /// diff --git a/BPA.SAAS.Manage.Web.Entry/BPA.SAAS.Manage.Web.Entry.csproj.user b/BPA.SAAS.Manage.Web.Entry/BPA.SAAS.Manage.Web.Entry.csproj.user index 96e7a74..cf47803 100644 --- a/BPA.SAAS.Manage.Web.Entry/BPA.SAAS.Manage.Web.Entry.csproj.user +++ b/BPA.SAAS.Manage.Web.Entry/BPA.SAAS.Manage.Web.Entry.csproj.user @@ -4,6 +4,6 @@ ProjectDebugger - Docker + BPA.SAAS.Manage.Web.Entry \ No newline at end of file