fix(components): [tree] dragging a node will deselect the node (#14830)

* fix(components): [tree] Dragging a node will deselect the node(#13912)

* fix(components): [tree] Dragging a node will deselect the node (#13912)

* fix(components): [tree] Dragging a node will deselect the node (#13912)

The Node class adds a method to set the checked state, which only affects the parent node state.

* refactor: optimized code

* fix(components): [tree] Dragging  a node will deselect the node (#13912)

checkStrictly is true no need reInitCheckek

* fix(components): [tree] Dragging a node will deselect the node (#13912)
This commit is contained in:
Alixhan
2024-03-29 16:58:47 +08:00
committed by GitHub
parent b3c423ff11
commit 7f7dae2fa0
3 changed files with 28 additions and 0 deletions

View File

@@ -558,6 +558,20 @@ class Node {
}
}
}
eachNode(callback: (node: Node) => void) {
const arr: Node[] = [this]
while (arr.length) {
const node = arr.shift()!
arr.unshift(...node.childNodes)
callback(node)
}
}
reInitChecked() {
if (this.store.checkStrictly) return
reInitChecked(this)
}
}
export default Node

View File

@@ -180,6 +180,15 @@ export function useDragNodeHandler({ props, ctx, el$, dropIndicator$, store }) {
}
if (dropType !== 'none') {
store.value.registerNode(draggingNodeCopy)
if (store.value.key) {
//restore checkbox state after dragging
draggingNode.node.eachNode((node) => {
store.value.nodesMap[node.data[store.value.key]]?.setChecked(
node.checked,
!store.value.checkStrictly
)
})
}
}
removeClass(dropNode.$el, ns.is('drop-inner'))

View File

@@ -183,6 +183,11 @@ export default defineComponent({
}
)
watch(
() => props.node.childNodes.length,
() => props.node.reInitChecked()
)
watch(
() => props.node.expanded,
(val) => {