[update 88384] 解决父子关联回显但是没有勾上子节点
This commit is contained in:
@@ -136,6 +136,10 @@ export default {
|
||||
permissionIds: that.checkedKeys.join(','),
|
||||
lastpermissionIds: that.defaultCheckedKeys.join(',')
|
||||
}
|
||||
// 只勾选父节点确定后,再次打开点击父子关联时,节点只是回显,没有被真实勾上,这里需要拿到所有子集的id
|
||||
if (!that.checkStrictly) {
|
||||
params.permissionIds = that.collectAllRelatedKeys(this.treeData, [...that.checkedKeys]).join(',')
|
||||
}
|
||||
that.loading = true
|
||||
console.log('请求参数:', params)
|
||||
saveRolePermission(params).then((res) => {
|
||||
@@ -166,6 +170,36 @@ export default {
|
||||
console.log(this.defaultCheckedKeys)
|
||||
})
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 返回父子关联的keys
|
||||
* @param tree - 树结构
|
||||
* @param keys - 当前勾选的keys
|
||||
* @return {any[]} - 返回所有父子关联的key
|
||||
*/
|
||||
collectAllRelatedKeys (tree, keys) {
|
||||
const result = new Set() // 使用集合来避免重复
|
||||
function findAndCollectNodes (nodes) {
|
||||
for (const node of nodes) {
|
||||
if (keys.includes(node.key)) {
|
||||
collectAllDescendants(node)
|
||||
} else if (node.children) {
|
||||
findAndCollectNodes(node.children)
|
||||
}
|
||||
}
|
||||
}
|
||||
function collectAllDescendants (node) {
|
||||
if (!result.has(node.key)) {
|
||||
result.add(node.key)
|
||||
}
|
||||
if (node.children) {
|
||||
for (const child of node.children) {
|
||||
collectAllDescendants(child)
|
||||
}
|
||||
}
|
||||
}
|
||||
findAndCollectNodes(tree)
|
||||
return Array.from(result)
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
||||
Reference in New Issue
Block a user