diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Role/RoleCreateInputVo.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Role/RoleCreateInputVo.cs index 42aebb71..41a64dc4 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Role/RoleCreateInputVo.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Role/RoleCreateInputVo.cs @@ -15,8 +15,8 @@ namespace Yi.Framework.Rbac.Application.Contracts.Dtos.Role public int OrderNum { get; set; } - public List DeptIds { get; set; } + public List? DeptIds { get; set; } - public List MenuIds { get; set; } + public List? MenuIds { get; set; } } } diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/MenuService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/MenuService.cs index 3d5b7baa..f7ec4e4d 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/MenuService.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/MenuService.cs @@ -1,3 +1,4 @@ +using Microsoft.AspNetCore.Mvc; using SqlSugar; using Volo.Abp.Application.Dtos; using Yi.Framework.Ddd.Application; @@ -5,6 +6,7 @@ using Yi.Framework.Rbac.Application.Contracts.Dtos.Menu; using Yi.Framework.Rbac.Application.Contracts.IServices; using Yi.Framework.Rbac.Domain.Entities; using Yi.Framework.Rbac.Domain.Shared.Consts; +using Yi.Framework.Rbac.Domain.Shared.Dtos; using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.Rbac.Application.Services.System @@ -43,5 +45,31 @@ namespace Yi.Framework.Rbac.Application.Services.System return await MapToGetListOutputDtosAsync(entities); } + + /// + /// 获取所有菜单 + /// + /// + /// + [Route("menu/list")] + public async Task> GetAllListAsync(MenuGetListInputVo input) + { + var entities = await _repository._DbQueryable.WhereIF(!string.IsNullOrEmpty(input.MenuName), x => x.MenuName.Contains(input.MenuName!)) + .WhereIF(input.State is not null, x => x.State == input.State) + .Where(x=>x.MenuSource==input.MenuSource) + .OrderByDescending(x => x.OrderNum) + .ToListAsync(); + return await MapToGetListOutputDtosAsync(entities); + } + + /// + /// 获取菜单树 + /// + /// + public async Task> GetTreeAsync() + { + var menuList = await _repository._DbQueryable.ToListAsync(); + return menuList.TreeDtoBuild(); + } } } diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain.Shared/Dtos/MenuTreeDto.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain.Shared/Dtos/MenuTreeDto.cs new file mode 100644 index 00000000..c6d390e4 --- /dev/null +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain.Shared/Dtos/MenuTreeDto.cs @@ -0,0 +1,16 @@ +using Yi.Framework.Core.Helper; +using Yi.Framework.Rbac.Domain.Shared.Enums; + +namespace Yi.Framework.Rbac.Domain.Shared.Dtos; + +public class MenuTreeDto: TreeHelper.ITreeModel +{ + public Guid Id { get; set; } + public Guid ParentId { get; set; } + public int OrderNum { get; set; } + public string MenuName { get; set; } = string.Empty; + public MenuTypeEnum MenuType { get; set; } = MenuTypeEnum.Menu; + public string? MenuIcon { get; set; } + + public List? Children { get; set; } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/MenuAggregateRoot.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/MenuAggregateRoot.cs index 20935733..56f540ee 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/MenuAggregateRoot.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/MenuAggregateRoot.cs @@ -285,5 +285,30 @@ namespace Yi.Framework.Rbac.Domain.Entities return rootRouters; } + + /// + /// 构建菜单树表 + /// + /// + /// + public static List TreeDtoBuild(this List menus) + { + List treeDtos = new(); + foreach (var m in menus) + { + var treeDto = new MenuTreeDto + { + Id = m.Id, + ParentId = m.ParentId, + OrderNum = m.OrderNum, + MenuName = m.MenuName, + MenuType = m.MenuType, + MenuIcon = m.MenuIcon + }; + treeDtos.Add(treeDto); + } + + return TreeHelper.SetTree(treeDtos); + } } } \ No newline at end of file