diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml
index a674189e..60fa3dc0 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml
@@ -230,6 +230,13 @@
+
+
+ 根据角色id获取该角色下全部菜单
+
+
+
+
角色管理
@@ -261,6 +268,12 @@
+
+
+ 更新角色信息
+
+
+
测试控制器
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs
index 8d82e8c6..d714b507 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs
@@ -61,5 +61,17 @@ namespace Yi.Framework.ApiMicroservice.Controllers
{
return Result.Success().SetData(await _iMenuService.GetMenuTreeAsync());
}
+
+ ///
+ /// 根据角色id获取该角色下全部菜单
+ ///
+ ///
+ ///
+ [HttpGet]
+ [Route("{id}")]
+ public async Task GetListByRoleId(long id)
+ {
+ return Result.Success().SetData(await _iMenuService.GetListByRoleId(id));
+ }
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs
index 72d28dce..2998a260 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs
@@ -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));
}
+
+ ///
+ /// 更新角色信息
+ ///
+ ///
+ [HttpPut]
+ public async Task UpdateInfo(RoleInfoDto roleDto)
+ {
+ return Result.Success().SetStatus(await _iRoleService.UpdateInfo(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 ee4bac05..e3c17b1a 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.Interface/IMenuService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IMenuService.cs
index 28427488..19592ce7 100644
--- a/Yi.Framework.Net6/Yi.Framework.Interface/IMenuService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Interface/IMenuService.cs
@@ -10,5 +10,12 @@ namespace Yi.Framework.Interface
{
Task> GetMenuTreeAsync();
Task> SelctGetList(MenuEntity menu);
+
+ ///
+ /// 获取该角色id下的所有菜单
+ ///
+ ///
+ ///
+ Task> GetListByRoleId(long roleId);
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs
index 4414bc1a..fde0871c 100644
--- a/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs
@@ -44,5 +44,13 @@ namespace Yi.Framework.Interface
///
///
Task AddInfo(RoleInfoDto roleDto);
+
+
+ ///
+ /// 更新角色关联菜单
+ ///
+ ///
+ ///
+ Task UpdateInfo(RoleInfoDto roleDto);
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/MenuService.cs b/Yi.Framework.Net6/Yi.Framework.Service/MenuService.cs
index 9448fa44..f76ecdaa 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/MenuService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/MenuService.cs
@@ -25,5 +25,11 @@ namespace Yi.Framework.Service
//复杂查询直接使用db代理
return await _repository._Db.Queryable().Where(u => u.IsDeleted == false).ToTreeAsync(it => it.Children, it => it.ParentId, 0);
}
+
+
+ public async Task> GetListByRoleId(long roleId)
+ {
+ return (await _repository._Db.Queryable().Includes(r => r.Menus).SingleAsync(r=>r.Id==roleId)).Menus;
+ }
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs b/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs
index bd51a930..b808dc17 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs
@@ -75,5 +75,13 @@ namespace Yi.Framework.Service
var res2 = await GiveRoleSetMenu(new List { res1 }, roleDto.MenuIds);
return !0.Equals(res1) && res2;
}
+
+
+ public async Task UpdateInfo(RoleInfoDto roleDto)
+ {
+ var res1 = await _repository.UpdateIgnoreNullAsync(roleDto.Role);
+ var res2 = await GiveRoleSetMenu(new List { roleDto.Role.Id }, roleDto.MenuIds);
+ return res1 && res2;
+ }
}
}
diff --git a/Yi.Vue3.X.RuoYi/src/api/system/menu.js b/Yi.Vue3.X.RuoYi/src/api/system/menu.js
index 5c04e404..f4a0818d 100644
--- a/Yi.Vue3.X.RuoYi/src/api/system/menu.js
+++ b/Yi.Vue3.X.RuoYi/src/api/system/menu.js
@@ -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'
})
}
diff --git a/Yi.Vue3.X.RuoYi/src/api/system/role.js b/Yi.Vue3.X.RuoYi/src/api/system/role.js
index 27d4ae14..ae522368 100644
--- a/Yi.Vue3.X.RuoYi/src/api/system/role.js
+++ b/Yi.Vue3.X.RuoYi/src/api/system/role.js
@@ -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'
})
+
}
\ No newline at end of file
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 75e3237b..5757f026 100644
--- a/Yi.Vue3.X.RuoYi/src/views/system/role/index.vue
+++ b/Yi.Vue3.X.RuoYi/src/views/system/role/index.vue
@@ -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,145 +351,152 @@ 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) {
- return deptTreeSelect(roleId).then(response => {
- deptOptions.value = response.depts;
- return response;
- });
-}
+ return deptTreeSelect(roleId).then(response => {
+ deptOptions.value = response.depts;
+ return response;
+ });
+ }
/** 树权限(展开/折叠)*/
function handleCheckedTreeExpand(value, type) {
- if (type == "menu") {
- let treeList = menuOptions.value;
- for (let i = 0; i < treeList.length; i++) {
- menuRef.value.store.nodesMap[treeList[i].id].expanded = value;
+ if (type == "menu") {
+ let treeList = menuOptions.value;
+ for (let i = 0; i < treeList.length; i++) {
+ menuRef.value.store.nodesMap[treeList[i].id].expanded = value;
+ }
+ } else if (type == "dept") {
+ let treeList = deptOptions.value;
+ for (let i = 0; i < treeList.length; i++) {
+ deptRef.value.store.nodesMap[treeList[i].id].expanded = value;
+ }
+ }
}
- } else if (type == "dept") {
- let treeList = deptOptions.value;
- for (let i = 0; i < treeList.length; i++) {
- deptRef.value.store.nodesMap[treeList[i].id].expanded = value;
- }
- }
-}
/** 树权限(全选/全不选) */
function handleCheckedTreeNodeAll(value, type) {
- if (type == "menu") {
- menuRef.value.setCheckedNodes(value ? menuOptions.value : []);
- } else if (type == "dept") {
- deptRef.value.setCheckedNodes(value ? deptOptions.value : []);
- }
-}
+ if (type == "menu") {
+ menuRef.value.setCheckedNodes(value ? menuOptions.value : []);
+ } else if (type == "dept") {
+ deptRef.value.setCheckedNodes(value ? deptOptions.value : []);
+ }
+ }
/** 树权限(父子联动) */
function handleCheckedTreeConnect(value, type) {
- if (type == "menu") {
- form.value.menuCheckStrictly = value ? true : false;
- } else if (type == "dept") {
- form.value.deptCheckStrictly = value ? true : false;
- }
-}
+ if (type == "menu") {
+ form.value.menuCheckStrictly = value ? true : false;
+ } else if (type == "dept") {
+ form.value.deptCheckStrictly = value ? true : false;
+ }
+ }
/** 所有菜单节点数据 */
function getMenuAllCheckedKeys() {
- // 目前被选中的菜单节点
- let checkedKeys = menuRef.value.getCheckedKeys();
- // 半选中的菜单节点
- let halfCheckedKeys = menuRef.value.getHalfCheckedKeys();
- checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
- return checkedKeys;
-}
+ // 目前被选中的菜单节点
+ let checkedKeys = menuRef.value.getCheckedKeys();
+ // 半选中的菜单节点
+ let halfCheckedKeys = menuRef.value.getHalfCheckedKeys();
+ checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
+ return checkedKeys;
+ }
/** 提交按钮 */
function submitForm() {
- proxy.$refs["roleRef"].validate(valid => {
- if (valid) {
- if (form.value.role.id != undefined) {
- form.value.menuIds = getMenuAllCheckedKeys();
- updateRole(form.value).then(response => {
- proxy.$modal.msgSuccess("修改成功");
- open.value = false;
- getList();
+ proxy.$refs["roleRef"].validate(valid => {
+ if (valid) {
+ if (form.value.role.id != undefined) {
+ form.value.menuIds = getMenuAllCheckedKeys();
+ updateRole(form.value).then(response => {
+ proxy.$modal.msgSuccess("修改成功");
+ open.value = false;
+ getList();
+ });
+ } else {
+ form.value.menuIds = getMenuAllCheckedKeys();
+ addRole(form.value).then(response => {
+ proxy.$modal.msgSuccess("新增成功");
+ open.value = false;
+ getList();
+ });
+ }
+ }
+ });
+ }
+/** 取消按钮 */
+function cancel() {
+ open.value = false;
+ reset();
+ }
+/** 选择角色权限范围触发 */
+function dataScopeSelectChange(value) {
+ if (value !== "2") {
+ deptRef.value.setCheckedKeys([]);
+ }
+ }
+/** 分配数据权限操作 */
+function handleDataScope(row) {
+ reset();
+ const deptTreeSelect = getDeptTree(row.id);
+ getRole(row.id).then(response => {
+ form.value = response.data;
+ openDataScope.value = true;
+ nextTick(() => {
+ deptTreeSelect.then(res => {
+ nextTick(() => {
+ if (deptRef.value) {
+ deptRef.value.setCheckedKeys(res.checkedKeys);
+ }
+ });
+ });
});
- } else {
- form.value.menuIds = getMenuAllCheckedKeys();
- addRole(form.value).then(response => {
- proxy.$modal.msgSuccess("新增成功");
- open.value = false;
+ title.value = "分配数据权限";
+ });
+ }
+/** 提交按钮(数据权限) */
+function submitDataScope() {
+ if (form.value.id != undefined) {
+ form.value.deptIds = getDeptAllCheckedKeys();
+ dataScope(form.value).then(response => {
+ proxy.$modal.msgSuccess("修改成功");
+ openDataScope.value = false;
getList();
});
}
}
- });
-}
-/** 取消按钮 */
-function cancel() {
- open.value = false;
- reset();
-}
-/** 选择角色权限范围触发 */
-function dataScopeSelectChange(value) {
- if (value !== "2") {
- deptRef.value.setCheckedKeys([]);
- }
-}
-/** 分配数据权限操作 */
-function handleDataScope(row) {
- reset();
- const deptTreeSelect = getDeptTree(row.id);
- getRole(row.id).then(response => {
- form.value = response.data;
- openDataScope.value = true;
- nextTick(() => {
- deptTreeSelect.then(res => {
- nextTick(() => {
- if (deptRef.value) {
- deptRef.value.setCheckedKeys(res.checkedKeys);
- }
- });
- });
- });
- title.value = "分配数据权限";
- });
-}
-/** 提交按钮(数据权限) */
-function submitDataScope() {
- if (form.value.id != undefined) {
- form.value.deptIds = getDeptAllCheckedKeys();
- dataScope(form.value).then(response => {
- proxy.$modal.msgSuccess("修改成功");
- openDataScope.value = false;
- getList();
- });
- }
-}
/** 取消按钮(数据权限)*/
function cancelDataScope() {
- openDataScope.value = false;
- reset();
-}
+ openDataScope.value = false;
+ reset();
+ }
getList();