角色添加、角色编辑关联菜单功能
This commit is contained in:
@@ -230,6 +230,13 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.MenuController.GetListByRoleId(System.Int64)">
|
||||
<summary>
|
||||
根据角色id获取该角色下全部菜单
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.RoleController">
|
||||
<summary>
|
||||
角色管理
|
||||
@@ -261,6 +268,12 @@
|
||||
<param name="roleDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.UpdateInfo(Yi.Framework.DTOModel.RoleInfoDto)">
|
||||
<summary>
|
||||
更新角色信息
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.TestController">
|
||||
<summary>
|
||||
测试控制器
|
||||
|
||||
@@ -61,5 +61,17 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
return Result.Success().SetData(await _iMenuService.GetMenuTreeAsync());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据角色id获取该角色下全部菜单
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
public async Task<Result> GetListByRoleId(long id)
|
||||
{
|
||||
return Result.Success().SetData(await _iMenuService.GetListByRoleId(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.Service;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
@@ -72,5 +73,15 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
return Result.Success().SetData(await _iRoleService.AddInfo(roleDto));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新角色信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> UpdateInfo(RoleInfoDto roleDto)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iRoleService.UpdateInfo(roleDto));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -10,5 +10,12 @@ namespace Yi.Framework.Interface
|
||||
{
|
||||
Task<List<MenuEntity>> GetMenuTreeAsync();
|
||||
Task<List<MenuEntity>> SelctGetList(MenuEntity menu);
|
||||
|
||||
/// <summary>
|
||||
/// 获取该角色id下的所有菜单
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<MenuEntity>> GetListByRoleId(long roleId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,5 +44,13 @@ namespace Yi.Framework.Interface
|
||||
/// <param name="roleDto"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> AddInfo(RoleInfoDto roleDto);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新角色关联菜单
|
||||
/// </summary>
|
||||
/// <param name="roleDto"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> UpdateInfo(RoleInfoDto roleDto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,5 +25,11 @@ namespace Yi.Framework.Service
|
||||
//复杂查询直接使用db代理
|
||||
return await _repository._Db.Queryable<MenuEntity>().Where(u => u.IsDeleted == false).ToTreeAsync(it => it.Children, it => it.ParentId, 0);
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<MenuEntity>> GetListByRoleId(long roleId)
|
||||
{
|
||||
return (await _repository._Db.Queryable<RoleEntity>().Includes(r => r.Menus).SingleAsync(r=>r.Id==roleId)).Menus;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,5 +75,13 @@ namespace Yi.Framework.Service
|
||||
var res2 = await GiveRoleSetMenu(new List<long> { res1 }, roleDto.MenuIds);
|
||||
return !0.Equals(res1) && res2;
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> UpdateInfo(RoleInfoDto roleDto)
|
||||
{
|
||||
var res1 = await _repository.UpdateIgnoreNullAsync(roleDto.Role);
|
||||
var res2 = await GiveRoleSetMenu(new List<long> { roleDto.Role.Id }, roleDto.MenuIds);
|
||||
return res1 && res2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export function treeselect() {
|
||||
// 根据角色ID查询菜单下拉树结构
|
||||
export function roleMenuTreeselect(roleId) {
|
||||
return request({
|
||||
url: '/system/menu/roleMenuTreeselect/' + roleId,
|
||||
url: '/menu/getListByRoleId/' + roleId,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ export function addRole(data) {
|
||||
// 修改角色
|
||||
export function updateRole(data) {
|
||||
return request({
|
||||
url: '/system/role',
|
||||
url: '/role/updateInfo',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
@@ -130,4 +130,5 @@ export function roleOptionselect() {
|
||||
url: '/role/getList',
|
||||
method: 'get'
|
||||
})
|
||||
|
||||
}
|
||||
@@ -188,7 +188,7 @@ const total = ref(0);
|
||||
const title = ref("");
|
||||
const dateRange = ref([]);
|
||||
const menuOptions = ref([]);
|
||||
const menuExpand = ref(false);
|
||||
const menuExpand = ref(true);
|
||||
const menuNodeAll = ref(false);
|
||||
const deptExpand = ref(true);
|
||||
const deptNodeAll = ref(false);
|
||||
@@ -302,7 +302,6 @@ function getMenuTreeselect() {
|
||||
options.push({ id: m.id, label: m.menuName, parentId: m.parentId, children: m.children })
|
||||
})
|
||||
menuOptions.value = proxy.handleTree(options);
|
||||
|
||||
})
|
||||
}
|
||||
/** 所有部门节点数据 */
|
||||
@@ -352,30 +351,37 @@ function handleAdd() {
|
||||
function handleUpdate(row) {
|
||||
reset();
|
||||
const roleId = row.id || ids.value;
|
||||
const roleMenu = getRoleMenuTreeselect(roleId);
|
||||
getRoleMenuTreeselect(roleId);
|
||||
getRole(roleId).then(response => {
|
||||
form.value = response.data;
|
||||
form.value.orderNum = Number(form.value.orderNum);
|
||||
form.value.role = response.data;
|
||||
form.value.role.orderNum = Number(form.value.role.orderNum);
|
||||
open.value = true;
|
||||
nextTick(() => {
|
||||
roleMenu.then((res) => {
|
||||
let checkedKeys = res.checkedKeys;
|
||||
checkedKeys.forEach((v) => {
|
||||
nextTick(() => {
|
||||
menuRef.value.setChecked(v, true, false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
title.value = "修改角色";
|
||||
});
|
||||
}
|
||||
/** 根据角色ID查询菜单树结构 */
|
||||
function getRoleMenuTreeselect(roleId) {
|
||||
return roleMenuTreeselect(roleId).then(response => {
|
||||
menuOptions.value = response.menus;
|
||||
return response;
|
||||
//1:获取该角色下的全部菜单id
|
||||
//2:获取全量菜单
|
||||
getMenuTreeselect();
|
||||
|
||||
roleMenuTreeselect(roleId).then(response => {
|
||||
|
||||
const menuIds = [];
|
||||
response.data.forEach(m => {
|
||||
menuIds.push(m.id)
|
||||
})
|
||||
|
||||
menuIds.forEach((v) => {
|
||||
nextTick(() => {
|
||||
menuRef.value.setChecked(v, true, false);
|
||||
});
|
||||
|
||||
//这里是要一个当前用户已拥有的菜单的id
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
/** 根据角色ID查询部门树结构 */
|
||||
function getDeptTree(roleId) {
|
||||
|
||||
Reference in New Issue
Block a user