This commit is contained in:
sjl
2024-11-21 10:05:44 +08:00
parent b992b2653a
commit 4de59336b2
17 changed files with 224 additions and 76 deletions

View File

@@ -146,10 +146,14 @@ const open = async (sign: string, data: Role.RoleBO, AllFunction: Function.ResFu
const allIds = getAllIds(AllFunction);
// 匹配 roleFunctions 中的 id 并设置 checkedKeys
const checkedKeys = allIds.filter(id => roleFunctions.some(roleFunc => roleFunc.id === id));
// 过滤出叶子节点
const leafCheckedKeys = filterLeafNodes(AllFunction, checkedKeys);
// 设置 functionList 和 checkedKeys
functionList.value = AllFunction;
checkedKeysRef.value = checkedKeys;
checkedKeysRef.value = leafCheckedKeys;
// nextTick(() => {
// // 触发一次更新,确保表单中的数据被更新
// dialogFormRef.value?.validate();
@@ -166,14 +170,32 @@ const open = async (sign: string, data: Role.RoleBO, AllFunction: Function.ResFu
}
}
const filterLeafNodes = (functions: Function.ResFunction[], checkedKeys: string[]): string[] => {
const leafNodes: string[] = [];
const isLeafNode = (func: Function.ResFunction) => !func.children || func.children.length === 0;
const traverse = (funcs: Function.ResFunction[]) => {
for (const func of funcs) {
if (isLeafNode(func)) {
if (checkedKeys.includes(func.id)) {
leafNodes.push(func.id);
}
} else {
traverse(func.children);
}
}
};
traverse(functions);
return leafNodes;
};
const getAllIds = (functions: Function.ResFunction[]): string[] => {
const ids: string[] = [];
const traverse = (func: Function.ResFunction) => {
ids.push(func.id);
if (func.children && func.children.length > 0) {
func.children.forEach(child => traverse(child));
func.children.forEach((child: any) => traverse(child));
}
};