From f49833f1e2700e6e0772e7ffcf97af5910af18fd Mon Sep 17 00:00:00 2001 From: WilliamXu96 <1091113110@qq.com> Date: Fri, 6 Jan 2023 17:36:47 +0800 Subject: [PATCH] =?UTF-8?q?[=E9=87=8D=E5=A4=A7=E6=94=B9=E8=BF=9B]=EF=BC=9A?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E7=A7=9F=E6=88=B7=E8=8F=9C=E5=8D=95=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TenantManagement/ITenantAppService.cs | 4 +- .../Dto/{MenusTreeDto.cs => MenusListDto.cs} | 5 +- .../IRoleMenusAppService.cs | 2 +- ...BaseServiceApplicationAutoMapperProfile.cs | 2 +- .../TenantManagement/TenantAppService.cs | 48 ++++++------- .../RoleMenusAppService.cs | 6 +- .../BaseService.Domain/Systems/Menu.cs | 2 +- .../BaseService.HttpApi.csproj | 2 +- .../Systems/RoleMenusController.cs | 2 +- .../Systems/TenantController.cs | 6 +- .../Business.Application.Contracts.csproj | 2 +- .../Business.HttpApi/Business.HttpApi.csproj | 2 +- WebApp/vue/src/views/role/index.vue | 5 -- WebApp/vue/src/views/tenant/index.vue | 68 ++++++------------- 14 files changed, 58 insertions(+), 98 deletions(-) rename BaseService/BaseService.Application.Contracts/Systems/UserRoleMenusManagement/Dto/{MenusTreeDto.cs => MenusListDto.cs} (78%) diff --git a/BaseService/BaseService.Application.Contracts/Systems/TenantManagement/ITenantAppService.cs b/BaseService/BaseService.Application.Contracts/Systems/TenantManagement/ITenantAppService.cs index 26877049..7e2f0175 100644 --- a/BaseService/BaseService.Application.Contracts/Systems/TenantManagement/ITenantAppService.cs +++ b/BaseService/BaseService.Application.Contracts/Systems/TenantManagement/ITenantAppService.cs @@ -11,8 +11,8 @@ public interface ITenantAppService : IApplicationService { Task UpdateTenantMenu(UpdateTenantMenuDto input); - Task> GetTenantMenusList(); + Task> GetTenantMenusList(); - Task> GetTenantMenuIds(Guid id); + Task> GetTenantMenusById(Guid id); } } diff --git a/BaseService/BaseService.Application.Contracts/Systems/UserRoleMenusManagement/Dto/MenusTreeDto.cs b/BaseService/BaseService.Application.Contracts/Systems/UserRoleMenusManagement/Dto/MenusListDto.cs similarity index 78% rename from BaseService/BaseService.Application.Contracts/Systems/UserRoleMenusManagement/Dto/MenusTreeDto.cs rename to BaseService/BaseService.Application.Contracts/Systems/UserRoleMenusManagement/Dto/MenusListDto.cs index ed6a8993..2df3a3c0 100644 --- a/BaseService/BaseService.Application.Contracts/Systems/UserRoleMenusManagement/Dto/MenusTreeDto.cs +++ b/BaseService/BaseService.Application.Contracts/Systems/UserRoleMenusManagement/Dto/MenusListDto.cs @@ -1,10 +1,9 @@ using System; -using System.Collections.Generic; using Volo.Abp.Application.Dtos; namespace BaseService.Systems.UserRoleMenusManagement.Dto { - public class MenusTreeDto : EntityDto + public class MenusListDto : EntityDto { public Guid? Pid { get; set; } @@ -15,5 +14,7 @@ public class MenusTreeDto : EntityDto public int Sort { get; set; } public string Permission { get; set; } + + public bool IsHost { get; set; } } } diff --git a/BaseService/BaseService.Application.Contracts/Systems/UserRoleMenusManagement/IRoleMenusAppService.cs b/BaseService/BaseService.Application.Contracts/Systems/UserRoleMenusManagement/IRoleMenusAppService.cs index c74fd00e..1d966907 100644 --- a/BaseService/BaseService.Application.Contracts/Systems/UserRoleMenusManagement/IRoleMenusAppService.cs +++ b/BaseService/BaseService.Application.Contracts/Systems/UserRoleMenusManagement/IRoleMenusAppService.cs @@ -12,7 +12,7 @@ public interface IRoleMenusAppService : IApplicationService Task> GetRoleMenuIds(Guid id); - Task> GetMenusList(); + Task> GetMenusList(); Task Update(UpdateRoleMenuDto input); } diff --git a/BaseService/BaseService.Application/BaseServiceApplicationAutoMapperProfile.cs b/BaseService/BaseService.Application/BaseServiceApplicationAutoMapperProfile.cs index 906ede7a..5e67342c 100644 --- a/BaseService/BaseService.Application/BaseServiceApplicationAutoMapperProfile.cs +++ b/BaseService/BaseService.Application/BaseServiceApplicationAutoMapperProfile.cs @@ -38,7 +38,7 @@ public BaseServiceApplicationAutoMapperProfile() CreateMap(); CreateMap(); - CreateMap(); + CreateMap(); } } } diff --git a/BaseService/BaseService.Application/Systems/TenantManagement/TenantAppService.cs b/BaseService/BaseService.Application/Systems/TenantManagement/TenantAppService.cs index 94fcac8e..6abc4c84 100644 --- a/BaseService/BaseService.Application/Systems/TenantManagement/TenantAppService.cs +++ b/BaseService/BaseService.Application/Systems/TenantManagement/TenantAppService.cs @@ -1,7 +1,6 @@ using BaseService.Systems.TenantManagement.Dto; using BaseService.Systems.UserRoleMenusManagement.Dto; using Microsoft.AspNetCore.Authorization; -using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -34,54 +33,47 @@ public TenantAppService( _roleMenuRepository = roleMenuRepository; } - public async Task> GetTenantMenusList() + public async Task> GetTenantMenusList() { var result = await _menuRepository.GetListAsync(_ => _.IsHost == false); - var dtos = ObjectMapper.Map, List>(result); - return new ListResultDto(dtos.OrderBy(_ => _.Sort).ToList()); + var dtos = ObjectMapper.Map, List>(result); + return new ListResultDto(dtos.OrderBy(_ => _.Sort).ToList()); } - public async Task> GetTenantMenuIds(Guid id) + public async Task> GetTenantMenusById(Guid id) { var tenant = await TenantRepository.GetAsync(id); using (CurrentTenant.Change(tenant.Id)) { - var menus = await _menuRepository.GetListAsync(); - return new ListResultDto(menus.Select(_ => _.Id).ToList()); + var result = await _menuRepository.GetListAsync(); + var dtos = ObjectMapper.Map, List>(result); + return new ListResultDto(dtos.OrderBy(_ => _.Sort).ToList()); } } public async Task UpdateTenantMenu(UpdateTenantMenuDto input) { var tenant = await TenantRepository.GetAsync(input.TenantId); - var menus = await (await _menuRepository.GetQueryableAsync()).Where(_ => input.MenuIds.Contains(_.Id)).ToListAsync(); using (CurrentTenant.Change(tenant.Id)) { - var tenantRoles = await RoleRepository.GetListAsync(); + + var menus = await _menuRepository.GetListAsync(); + var adminRole = (await RoleRepository.GetListAsync()).First(t => t.Name == "admin"); + //清除租户所有角色菜单,TODO:清除租户角色权限 - await _roleMenuRepository.DeleteAsync(_ => tenantRoles.Select(s => s.Id).Contains(_.RoleId)); + await _roleMenuRepository.DeleteAsync(_ => menus.Select(m => m.Id).Contains(_.MenuId)); foreach (var menu in menus) { - //添加租户菜单 - var menuId = GuidGenerator.Create(); - await _menuRepository.InsertAsync(new Menu(menuId) + if (input.MenuIds.Contains(menu.Id)) { - FormId = menu.FormId, - Pid = menu.Pid, - CategoryId = menu.CategoryId, - Name = menu.Name, - Label = menu.Label, - Sort = menu.Sort, - Path = menu.Path, - Component = menu.Component, - Permission = menu.Permission, - Icon = menu.Icon, - Hidden = menu.Hidden, - AlwaysShow = menu.AlwaysShow - }); - //添加租户admin角色菜单 - await _roleMenuRepository.InsertAsync(new RoleMenu(tenantRoles.FirstOrDefault(t => t.Name == "admin").Id, menuId)); + menu.IsHost = false; + //添加租户admin角色菜单 + await _roleMenuRepository.InsertAsync(new RoleMenu(adminRole.Id, menu.Id)); + } + else + menu.IsHost = true; + } } } diff --git a/BaseService/BaseService.Application/Systems/UserRoleMenusManagement/RoleMenusAppService.cs b/BaseService/BaseService.Application/Systems/UserRoleMenusManagement/RoleMenusAppService.cs index b21612bf..fd65d791 100644 --- a/BaseService/BaseService.Application/Systems/UserRoleMenusManagement/RoleMenusAppService.cs +++ b/BaseService/BaseService.Application/Systems/UserRoleMenusManagement/RoleMenusAppService.cs @@ -42,15 +42,15 @@ public async Task Update(UpdateRoleMenuDto input) } [Authorize(IdentityPermissions.Roles.Default)] - public async Task> GetMenusList() + public async Task> GetMenusList() { var result = new List(); if (!CurrentTenant.Id.HasValue) result = await _menuRepository.GetListAsync(); else result = await _menuRepository.GetListAsync(_ => _.IsHost == false); - var dtos = ObjectMapper.Map, List>(result); - return new ListResultDto(dtos.OrderBy(_ => _.Sort).ToList()); + var dtos = ObjectMapper.Map, List>(result); + return new ListResultDto(dtos.OrderBy(_ => _.Sort).ToList()); } /// diff --git a/BaseService/BaseService.Domain/Systems/Menu.cs b/BaseService/BaseService.Domain/Systems/Menu.cs index 7cbe492d..c44a74c1 100644 --- a/BaseService/BaseService.Domain/Systems/Menu.cs +++ b/BaseService/BaseService.Domain/Systems/Menu.cs @@ -37,7 +37,7 @@ public class Menu : AuditedAggregateRoot, ISoftDelete, IMultiTenant public bool AlwaysShow { get; set; } /// - /// 宿主菜单 + /// 是否宿主菜单,if(TenantId!=null&&IsHost==true):停用租户菜单 /// public bool IsHost { get; set; } diff --git a/BaseService/BaseService.HttpApi/BaseService.HttpApi.csproj b/BaseService/BaseService.HttpApi/BaseService.HttpApi.csproj index c91b86c6..f357c84e 100644 --- a/BaseService/BaseService.HttpApi/BaseService.HttpApi.csproj +++ b/BaseService/BaseService.HttpApi/BaseService.HttpApi.csproj @@ -22,7 +22,7 @@ - + diff --git a/BaseService/BaseService.HttpApi/Systems/RoleMenusController.cs b/BaseService/BaseService.HttpApi/Systems/RoleMenusController.cs index adbb807c..d1ec1c05 100644 --- a/BaseService/BaseService.HttpApi/Systems/RoleMenusController.cs +++ b/BaseService/BaseService.HttpApi/Systems/RoleMenusController.cs @@ -30,7 +30,7 @@ public Task Update(UpdateRoleMenuDto input) [HttpGet] [Route("list")] - public Task> GetMenusList() + public Task> GetMenusList() { return _roleMenusAppService.GetMenusList(); } diff --git a/BaseService/BaseService.HttpApi/Systems/TenantController.cs b/BaseService/BaseService.HttpApi/Systems/TenantController.cs index ff6bbc8b..e78891fc 100644 --- a/BaseService/BaseService.HttpApi/Systems/TenantController.cs +++ b/BaseService/BaseService.HttpApi/Systems/TenantController.cs @@ -22,14 +22,14 @@ public TenantController(ITenantAppService tenantAppService) [HttpGet] [Route("menu/{id}")] - public Task> GetTenantMenuIds(Guid id) + public Task> GetTenantMenusById(Guid id) { - return _tenantAppService.GetTenantMenuIds(id); + return _tenantAppService.GetTenantMenusById(id); } [HttpGet] [Route("menu-list")] - public Task> GetTenantMenusList() + public Task> GetTenantMenusList() { return _tenantAppService.GetTenantMenusList(); } diff --git a/MicroServices/Business/Business.Application.Contracts/Business.Application.Contracts.csproj b/MicroServices/Business/Business.Application.Contracts/Business.Application.Contracts.csproj index fd3dd284..344a0f26 100644 --- a/MicroServices/Business/Business.Application.Contracts/Business.Application.Contracts.csproj +++ b/MicroServices/Business/Business.Application.Contracts/Business.Application.Contracts.csproj @@ -3,7 +3,7 @@ net6.0 Business - 2.7.8 + 2.7.9 true XCZ XCZ diff --git a/MicroServices/Business/Business.HttpApi/Business.HttpApi.csproj b/MicroServices/Business/Business.HttpApi/Business.HttpApi.csproj index 58aacc7f..724cb8f6 100644 --- a/MicroServices/Business/Business.HttpApi/Business.HttpApi.csproj +++ b/MicroServices/Business/Business.HttpApi/Business.HttpApi.csproj @@ -4,7 +4,7 @@ net6.0 Business true - 2.7.8 + 2.7.9 XCZ.Business.HttpApi XCZ Business服务HttpApi远程依赖 diff --git a/WebApp/vue/src/views/role/index.vue b/WebApp/vue/src/views/role/index.vue index a32591d2..c506b864 100644 --- a/WebApp/vue/src/views/role/index.vue +++ b/WebApp/vue/src/views/role/index.vue @@ -396,11 +396,6 @@ export default { }, checkNode(data, state) { if (!data.pid) { - // if (state.checkedKeys.indexOf(data.id) === -1) { - // data.children.forEach(element => { - // this.$refs.tree.setChecked(element.id, false); - // }); - // } } else { if (state.checkedKeys.indexOf(data.id) > -1) { this.$refs.tree.setChecked(data.pid, true); diff --git a/WebApp/vue/src/views/tenant/index.vue b/WebApp/vue/src/views/tenant/index.vue index 0da992ec..3c036a79 100644 --- a/WebApp/vue/src/views/tenant/index.vue +++ b/WebApp/vue/src/views/tenant/index.vue @@ -8,10 +8,6 @@
新增 - 修改 - 删除
@@ -78,7 +74,7 @@ + class="permission-tree" /> @@ -129,18 +125,8 @@ export default { }, created() { this.getList(); - this.getMenuList(); }, methods: { - getMenuList() { - this.treeLoading = true; - this.$axios.gets("/api/base/tenant/menu-list").then((response) => { - this.menuData = response.items; - this.menus = response.items.filter((_) => _.pid == null); - this.setChildren(this.menus, response.items); - this.treeLoading = false; - }); - }, getList() { this.listLoading = true; this.listQuery.SkipCount = (this.page - 1) * this.listQuery.MaxResultCount; @@ -208,19 +194,6 @@ export default { this.savePerLoading = true; let params = {}; let checkedKeys = this.$refs.tree.getCheckedKeys(); - params.permissions = []; - this.menuData.forEach((element) => { - if (element.permission) { - let perm = {}; - perm.name = element.permission; - if (checkedKeys.indexOf(element.id) > -1) { - perm.isGranted = true; - } else { - perm.isGranted = false; - } - params.permissions.push(perm); - } - }); this.$axios .posts("/api/base/tenant/menu", { tenantId: this.multipleSelection[0].id, @@ -287,6 +260,25 @@ export default { } } }, + handleRowClick(row, column, event) { + if ( + this.multipleSelection.length == 1 && + this.multipleSelection[0].id == row.id + ) { + return; + } + this.treeLoading = true; + this.$refs.multipleTable.clearSelection(); + this.$refs.multipleTable.toggleRowSelection(row); + this.$axios.gets("/api/base/tenant/menu/" + row.id).then((response) => { + this.$refs.tree.setCheckedKeys(response.items); + this.menuData = response.items; + this.menus = response.items.filter((_) => _.pid == null); + this.setChildren(this.menus, response.items); + this.$refs.tree.setCheckedKeys(response.items.filter(_ => _.isHost == false).map(_ => _.id)); + this.treeLoading = false; + }); + }, checkedAll() { if (this.checked) { //全选 @@ -296,11 +288,6 @@ export default { this.$refs.tree.setCheckedKeys([]); } }, - checkNode(data, state) { - if (state.checkedKeys.indexOf(data.id) > -1) { - this.$refs.tree.setChecked(data.pid, true); - } - }, setChildren(roots, items) { roots.forEach((element) => { items.forEach((item) => { @@ -326,21 +313,6 @@ export default { handleSelectionChange(val) { this.multipleSelection = val; }, - handleRowClick(row, column, event) { - if ( - this.multipleSelection.length == 1 && - this.multipleSelection[0].id == row.id - ) { - return; - } - this.treeLoading = true; - this.$refs.multipleTable.clearSelection(); - this.$refs.multipleTable.toggleRowSelection(row); - this.$axios.gets("/api/base/tenant/menu/" + row.id).then((response) => { - this.$refs.tree.setCheckedKeys(response.items); - this.treeLoading = false; - }); - }, cancel() { this.form = Object.assign({}, defaultForm); this.dialogFormVisible = false;