|
@@ -159,9 +159,8 @@ const ElTreeLoadNode = async () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-//被选择的
|
|
|
-const ElTreeCheckChange = async(data, nodes) => {
|
|
|
-
|
|
|
+//被选择的//被选择的
|
|
|
+const ElTreeCheckChange = async (data, nodes) => {
|
|
|
if (props.onlyChildrenCheck) {
|
|
|
const treeRef = ElTreeRef.value?.treeRef
|
|
|
if (treeRef) {
|
|
@@ -180,33 +179,40 @@ const ElTreeCheckChange = async(data, nodes) => {
|
|
|
return keys
|
|
|
}
|
|
|
|
|
|
+ // 获取当前已选中的节点
|
|
|
+ const checkedKeys = treeRef.getCheckedKeys()
|
|
|
+
|
|
|
if (!isChecked) {
|
|
|
// 取消选中时
|
|
|
if (!data.notExsitChild) {
|
|
|
// 如果是父节点,递归取消选中当前节点及其所有子节点
|
|
|
const allChildKeys = getAllChildrenKeys(currentNode)
|
|
|
- treeRef.setCheckedKeys([])
|
|
|
+ // 从已选中的节点中移除当前节点及其子节点
|
|
|
+ const newCheckedKeys = checkedKeys.filter(key =>
|
|
|
+ key !== data.pKeyId && !allChildKeys.includes(key),
|
|
|
+ )
|
|
|
+ treeRef.setCheckedKeys(newCheckedKeys)
|
|
|
} else {
|
|
|
// 如果是最底层节点,只取消选中当前节点
|
|
|
- treeRef.setCheckedKeys([])
|
|
|
+ const newCheckedKeys = checkedKeys.filter(key => key !== data.pKeyId)
|
|
|
+ treeRef.setCheckedKeys(newCheckedKeys)
|
|
|
}
|
|
|
} else {
|
|
|
// 选中时
|
|
|
if (!data.notExsitChild) {
|
|
|
// 如果是父节点,递归选中当前节点及其所有子节点
|
|
|
const allChildKeys = getAllChildrenKeys(currentNode)
|
|
|
- treeRef.setCheckedKeys([data.pKeyId, ...allChildKeys])
|
|
|
+ treeRef.setCheckedKeys([...new Set([...checkedKeys, data.pKeyId, ...allChildKeys])])
|
|
|
} else {
|
|
|
// 如果是最底层节点,只选中当前节点
|
|
|
- treeRef.setCheckedKeys([data.pKeyId])
|
|
|
+ treeRef.setCheckedKeys([...checkedKeys, data.pKeyId])
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // emit('check-change', nodes)
|
|
|
await nextTick(() => {
|
|
|
- ElTreeCheckedKeys()
|
|
|
- })
|
|
|
+ ElTreeCheckedKeys()
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
//处理节点
|