From d52258f8df4be39c81da1500ad77ec01b0527878 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Wed, 26 Nov 2025 15:41:34 +0800 Subject: [PATCH] =?UTF-8?q?BOM=E5=A4=8D=E5=88=B6=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E4=B8=B4=E6=97=B6=E8=A1=A8tree=E7=BB=93=E6=9E=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/modules/part/bomSearch3.vue | 2 +- src/views/modules/part/copy_bom_modal.vue | 36 +++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) 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