修改分配权限

This commit is contained in:
陈红丽 2024-11-21 14:27:29 +08:00
parent b0b71128b9
commit 95450339ae
2 changed files with 58 additions and 9 deletions

View File

@ -178,8 +178,7 @@
const results: SearchResult[] = [];
menu.forEach((item) => {
const { title, path, key, icon, children, meta } = item;
const combinedPath = currentPath ? `${currentPath}/${path}` : path;
const combinedPath = path ? path : currentPath;
const combinedName = accumulatedName ? `${accumulatedName} > ${title}` : title;
if (!meta?.hidden && reg.test(title) && !children?.length) {

View File

@ -24,6 +24,7 @@
:height="600"
:checked-keys="checkedKeys"
:expanded-keys="expandedKeys"
:indeterminate-keys="halfCheckedIds"
@update:checked-keys="onChangePermissionsTree"
ref="treeRef"
@update:expanded-keys="handleExpands"
@ -68,6 +69,7 @@
const expandFlag = ref(false);
const allMenuIds = ref([]);
const checkedKeys = ref([]);
const halfCheckedIds = ref([]);
const expandedKeys = ref([]);
const menuArray = ref<any[]>([]);
const menuTree = ref<any[]>([]);
@ -101,8 +103,8 @@
//
const getDeptAllCheckedKeys = () => {
const checkedKeys = treeRef.value?.getCheckedData();
const halfCheckedKeys = treeRef.value?.getIndeterminateData()!;
const checkedKeys = treeRef.value?.getCheckedData().keys;
const halfCheckedKeys = treeRef.value?.getIndeterminateData().keys;
checkedKeys?.unshift.apply(checkedKeys, halfCheckedKeys);
return checkedKeys;
};
@ -121,7 +123,7 @@
/**
* 关闭窗体
*/
const dialogClose = () => {
const handleClose = () => {
emit('update:visible', false);
};
@ -145,13 +147,61 @@
const data = await getRoleMenuList(props.roleId);
menuTree.value = buildTree(data);
menuArray.value = data;
checkedKeys.value = [];
menuArray.value.map((item) => {
if (item.checked) {
checkedKeys.value.push(item.id);
allMenuIds.value.push(item.id);
});
const keys = checkTree(menuTree.value, 0, [], []);
checkedKeys.value = keys.checkedIds;
halfCheckedIds.value = keys.halfCheckedIds;
};
/**
* 选中树结构
* @param nodes 节点
* @param parentId 上级ID
* @param checkedIds 选中ID集合
* @param halfCheckedIds
*/
function checkTree(nodes, parentId = null, checkedIds, halfCheckedIds) {
nodes.forEach((node) => {
let allChildrenChecked = true;
let someChildrenChecked = false;
//
if (node.children && node.children.length > 0) {
checkTree(node.children, node.id, checkedIds, halfCheckedIds); //
//
node.children.forEach((child) => {
if (child.checked) {
someChildrenChecked = true;
// IDcheckedIds
// checked
halfCheckedIds.push(child.id); //
} else {
allChildrenChecked = false;
}
});
};
//
if (allChildrenChecked) {
//
checkedIds.push(node.id);
} else if (someChildrenChecked) {
//
halfCheckedIds.push(parentId || node.id); // parentId
}
//
// 使
//
} else {
// checked
if (node.checked) {
checkedIds.push(node.id);
}
}
});
return { checkedIds, halfCheckedIds };
}
/**
* 钩子函数