diff --git a/src/views/modules/part/bomSearch3.vue b/src/views/modules/part/bomSearch3.vue index 5b3d432..992afed 100644 --- a/src/views/modules/part/bomSearch3.vue +++ b/src/views/modules/part/bomSearch3.vue @@ -50,7 +50,7 @@ 0) { this.$nextTick(() => { - this.$refs.tree.setCurrentKey(this.treeData[0].id) - this.handleNodeClick(this.treeData[0]) + // 如果有保存的节点ID,尝试恢复选中该节点 + if (currentNodeId) { + // 在新树中查找相同ID的节点 + const findNodeById = (nodes, targetId) => { + for (let node of nodes) { + if (node.id === targetId) { + return node + } + if (node.list && node.list.length > 0) { + const found = findNodeById(node.list, targetId) + if (found) return found + } + } + return null + } + + const targetNode = findNodeById(this.treeData, currentNodeId) + if (targetNode) { + // 找到了原来的节点,恢复选中 + this.$refs.tree.setCurrentKey(targetNode.id) + this.handleNodeClick(targetNode) + } else { + // 没找到,默认选中第一个 + this.$refs.tree.setCurrentKey(this.treeData[0].id) + this.handleNodeClick(this.treeData[0]) + } + } else { + // 没有保存的节点ID,默认选中第一个 + this.$refs.tree.setCurrentKey(this.treeData[0].id) + this.handleNodeClick(this.treeData[0]) + } }) } this.queryTreeLoading = false