Skip to content

Commit

Permalink
feat: 修改角色授权树向下级联选择的UI交互
Browse files Browse the repository at this point in the history
  • Loading branch information
WangJunZzz authored Apr 21, 2023
2 parents 61de47b + 1b4e71e commit 50eab11
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ private PermissionOutput BuildTreeData(List<PermissionGroupDto> input)
? L[$"Permission:SystemManagement"]
: group.DisplayName
};
result.Grants.Add(group.Name);
if (group.Permissions.Any(p => p.IsGranted == true && p.Name.StartsWith(group.Name)))
{
result.Grants.Add(group.Name);
}
// 获取所有已授权和未授权权限集合
foreach (var item in group.Permissions)
{
Expand All @@ -71,12 +74,12 @@ private PermissionOutput BuildTreeData(List<PermissionGroupDto> input)
{
result.Grants.Add(item.Name);
}
else
{
// 只要没有授权的,就移除顶级的分组
result.Grants.Remove(group.Name);
result.Grants.Remove(item.ParentName);
}
//else
//{
// // 只要没有授权的,就移除顶级的分组
// result.Grants.Remove(group.Name);
// result.Grants.Remove(item.ParentName);
//}
}

// 递归菜单
Expand Down
18 changes: 16 additions & 2 deletions vben28/src/views/admin/roles/PermissionAbpRole.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<BasicDrawer @register="registerDrawer" :maskClosable="false" :title="t('routes.admin.roleManagement_permission')" width="20%">
<BasicTree :treeData="allPermissionsRef" checkable ref="treeRef" style="margin-bottom: 50px" />
<BasicTree :treeData="allPermissionsRef" @check="handleCheck" :checkStrictly="'false'" checkable ref="treeRef" style="margin-bottom: 50px" />
<div
:style="{
position: 'absolute',
Expand Down Expand Up @@ -79,7 +79,7 @@ export default defineComponent({
totalRolePermissionsRef.forEach((item:string)=>{
let permisstion = new UpdatePermissionDto();
permisstion.name = item;
if((keys as []).some(e=>e==item)){
if((keys.checked as []).some(e=>e==item)){
permisstion.isGranted = true;
permisstions.push(permisstion);
}else{
Expand All @@ -97,13 +97,27 @@ export default defineComponent({
message.success(t('common.operationSuccess'));
}
};
// 自定义级联选中
const handleCheck = (checkedKeys, e) => {
if (e.checked === true) {
// 新增权限时,向下级联选中
var filteredKeys = totalRolePermissionsRef.filter(key => key.startsWith(e.node.key));
checkedKeys.checked = checkedKeys.checked.concat(filteredKeys.filter(key => checkedKeys.checked.indexOf(key) === -1));
} else {
// 取消权限时,向下级联反选
checkedKeys.checked = checkedKeys.checked.filter(key => !key.startsWith(e.node.key));
}
}
return {
t,
registerDrawer,
allPermissionsRef,
submitRolePermisstionAsync,
closeDrawer,
treeRef,
handleCheck,
};
},
});
Expand Down

0 comments on commit 50eab11

Please sign in to comment.