From c9d5b54166dc83ef152afd6a24b529aa36a5c589 Mon Sep 17 00:00:00 2001 From: lideqin <694785430@qq.com> Date: Fri, 21 Jun 2024 11:43:09 +0800 Subject: [PATCH] =?UTF-8?q?[update]=20=E4=BC=81=E6=A0=87=E5=B7=A6=E4=BE=A7?= =?UTF-8?q?=E6=A0=91=E6=96=B0=E5=A2=9E=E5=AE=8C=E5=B7=A6=E4=BE=A7=E6=A0=91?= =?UTF-8?q?=E5=B1=95=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../standard/EnterpriseStandardList.vue | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/views/enterpriseStandardLibrary/standard/EnterpriseStandardList.vue b/src/views/enterpriseStandardLibrary/standard/EnterpriseStandardList.vue index 5ac5e72..7953f4a 100644 --- a/src/views/enterpriseStandardLibrary/standard/EnterpriseStandardList.vue +++ b/src/views/enterpriseStandardLibrary/standard/EnterpriseStandardList.vue @@ -338,7 +338,18 @@ export default { this.filters.nodeCode = null if (res.success) { this.treeData = res.result || [] - this.expandedKeys = [this.treeData[0].key] + // this.expandedKeys = [this.treeData[0].key] + if (this.expandedKeys.length <= 0) { + // 根节点默认展开 + this.expandedKeys = [this.treeData[0].key] + } else { + const treeDataList = this.getTreeDataList(this.treeData) + const treeDataListKeys = treeDataList.map(item => item.key) + // 不是叶子结点的结点 + const notLeafKeys = treeDataList.filter(item => !item.leaf).map(item => item.key) + // 还存在的树节点并且还有子节点的展开节点依然展开 + this.expandedKeys = this.expandedKeys.filter(item => treeDataListKeys.includes(item) && notLeafKeys.includes(item)) + } } else { this.treeData = [] } @@ -349,6 +360,17 @@ export default { this.treeLoading = false }) }, + getTreeDataList (treeData) { + let treeDataList = [] + for (const item of treeData) { + treeDataList.push(item) + if (item.children && item.children.length > 0) { + const list = this.getTreeDataList(item.children) + treeDataList = treeDataList.concat(list) + } + } + return treeDataList + }, // 左侧树搜索 handleTreeSearch () { this.treeData = []