diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml index 889d2c7d..a674189e 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml @@ -254,6 +254,13 @@ + + + 添加角色包含菜单 + + + + 测试控制器 diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs index b4b38a18..72d28dce 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs @@ -60,5 +60,17 @@ namespace Yi.Framework.ApiMicroservice.Controllers { return Result.Success().SetData(await _iRoleService.GetInMenuByRoleId(RoleId)); } + + /// + /// 添加角色包含菜单 + /// + /// + /// + + [HttpPost] + public async Task AddInfo(RoleInfoDto roleDto) + { + return Result.Success().SetData(await _iRoleService.AddInfo(roleDto)); + } } } diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db index b1bfb457..ee4bac05 100644 Binary files a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db differ diff --git a/Yi.Framework.Net6/Yi.Framework.DTOModel/RoleInfoDto.cs b/Yi.Framework.Net6/Yi.Framework.DTOModel/RoleInfoDto.cs new file mode 100644 index 00000000..7d972ee3 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.DTOModel/RoleInfoDto.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Model.Models; + +namespace Yi.Framework.DTOModel +{ + public class RoleInfoDto + { + public RoleEntity Role { get; set; } + public List DeptIds { get; set; } + public List MenuIds { get; set; } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.DTOModel/UserInfoDto.cs b/Yi.Framework.Net6/Yi.Framework.DTOModel/UserInfoDto.cs index 51616402..983e7135 100644 --- a/Yi.Framework.Net6/Yi.Framework.DTOModel/UserInfoDto.cs +++ b/Yi.Framework.Net6/Yi.Framework.DTOModel/UserInfoDto.cs @@ -11,7 +11,7 @@ namespace Yi.Framework.DTOModel { public UserEntity User { get; set; } public List RoleIds { get; set; } - public List PostId { get; set; } + public List PostIds { get; set; } public long? DeptId { get; set; } } } diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs index a59666b3..4414bc1a 100644 --- a/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Yi.Framework.Common.Models; +using Yi.Framework.DTOModel; using Yi.Framework.Model.Models; using Yi.Framework.Repository; @@ -36,5 +37,12 @@ namespace Yi.Framework.Interface /// /// Task>> SelctPageList(RoleEntity role, PageParModel page); + + /// + /// 添加角色关联菜单 + /// + /// + /// + Task AddInfo(RoleInfoDto roleDto); } } diff --git a/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs b/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs index 0bd24471..bd51a930 100644 --- a/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs @@ -1,8 +1,10 @@ using SqlSugar; using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Yi.Framework.Common.Models; +using Yi.Framework.DTOModel; using Yi.Framework.Interface; using Yi.Framework.Model.Models; using Yi.Framework.Repository; @@ -20,13 +22,13 @@ namespace Yi.Framework.Service var _repositoryRoleMenu= _repository.ChangeRepository>(); //多次操作,需要事务确保原子性 return await _repositoryRoleMenu.UseTranAsync(async () => - { + { //删除用户之前所有的用户角色关系(物理删除,没有恢复的必要) + await _repositoryRoleMenu.DeleteAsync(u => roleIds.Contains((long)u.RoleId) ); //遍历用户 foreach (var roleId in roleIds) { - //删除用户之前所有的用户角色关系(物理删除,没有恢复的必要) - await _repositoryRoleMenu.DeleteAsync(u => u.RoleId==roleId); + //添加新的关系 List roleMenuEntity = new(); @@ -64,5 +66,14 @@ namespace Yi.Framework.Service return new PageModel>(data, total); } + + + + public async Task AddInfo(RoleInfoDto roleDto) + { + var res1 = await _repository.InsertReturnSnowflakeIdAsync(roleDto.Role); + var res2 = await GiveRoleSetMenu(new List { res1 }, roleDto.MenuIds); + return !0.Equals(res1) && res2; + } } } diff --git a/Yi.Vue3.X.RuoYi/src/api/system/role.js b/Yi.Vue3.X.RuoYi/src/api/system/role.js index 5f65dfe0..27d4ae14 100644 --- a/Yi.Vue3.X.RuoYi/src/api/system/role.js +++ b/Yi.Vue3.X.RuoYi/src/api/system/role.js @@ -9,10 +9,12 @@ export function listRole(query) { }) } + + // 查询角色详细 export function getRole(roleId) { return request({ - url: '/system/role/' + roleId, + url: '/role/getById/' + roleId, method: 'get' }) } @@ -20,7 +22,7 @@ export function getRole(roleId) { // 新增角色 export function addRole(data) { return request({ - url: '/system/role', + url: '/role/addInfo', method: 'post', data: data }) @@ -59,9 +61,14 @@ export function changeRoleStatus(roleId, status) { // 删除角色 export function delRole(roleId) { + if("string"==typeof(roleId)) + { + roleId=[roleId]; + } return request({ - url: '/system/role/' + roleId, - method: 'delete' + url: '/role/delList', + method: 'delete', + data:roleId }) } diff --git a/Yi.Vue3.X.RuoYi/src/views/system/role/index.vue b/Yi.Vue3.X.RuoYi/src/views/system/role/index.vue index 275dec07..75e3237b 100644 --- a/Yi.Vue3.X.RuoYi/src/views/system/role/index.vue +++ b/Yi.Vue3.X.RuoYi/src/views/system/role/index.vue @@ -1,269 +1,177 @@