From 0fca4eca794dba7ac8a6f89d4ce2636de00fd413 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期四, 09 四月 2026 15:27:29 +0800
Subject: [PATCH] 中兴实强 1.产品维护产品大类新增时层级不做限制
---
src/views/basicData/product/index.vue | 52 +++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/src/views/basicData/product/index.vue b/src/views/basicData/product/index.vue
index d9ae4a5..6b07c14 100644
--- a/src/views/basicData/product/index.vue
+++ b/src/views/basicData/product/index.vue
@@ -25,6 +25,9 @@
:data="list"
@node-click="handleNodeClick"
:expand-on-click-node="false"
+ @node-expand="handleNodeExpand"
+ @node-collapse="handleNodeCollapse"
+ :key="treeKey"
:default-expanded-keys="expandedKeys"
:filter-node-method="filterNode"
:props="{ children: 'children', label: 'label' }"
@@ -189,6 +192,34 @@
const { proxy } = getCurrentInstance();
const tree = ref(null);
const containerRef = ref(null);
+const treeKey = ref(0);
+const expandedKeySet = new Set();
+const EXPANDED_STORAGE_KEY = "basicData_product_tree_expanded_keys";
+
+const loadExpandedKeys = () => {
+ if (typeof window === "undefined") {
+ return [];
+ }
+ try {
+ const saved = localStorage.getItem(EXPANDED_STORAGE_KEY);
+ return saved ? JSON.parse(saved) : [];
+ } catch (error) {
+ console.error(error);
+ return [];
+ }
+};
+
+const saveExpandedKeys = () => {
+ if (typeof window === "undefined") {
+ return;
+ }
+ localStorage.setItem(
+ EXPANDED_STORAGE_KEY,
+ JSON.stringify(Array.from(expandedKeySet))
+ );
+};
+
+loadExpandedKeys().forEach((key) => expandedKeySet.add(key));
const productDia = ref(false);
const modelDia = ref(false);
@@ -258,16 +289,27 @@
treeLoad.value = true;
productTreeList()
.then((res) => {
- list.value = res;
- list.value.forEach((a) => {
- expandedKeys.value.push(a.label);
- });
- treeLoad.value = false;
+ list.value = res || [];
+ expandedKeys.value = Array.from(expandedKeySet);
+ treeKey.value += 1;
})
.catch((err) => {
+ console.error(err);
+ })
+ .finally(() => {
treeLoad.value = false;
});
};
+const handleNodeExpand = (data) => {
+ expandedKeySet.add(data.id);
+ expandedKeys.value = Array.from(expandedKeySet);
+ saveExpandedKeys();
+};
+const handleNodeCollapse = (data) => {
+ expandedKeySet.delete(data.id);
+ expandedKeys.value = Array.from(expandedKeySet);
+ saveExpandedKeys();
+};
// 杩囨护浜у搧鏍�
const searchFilter = () => {
proxy.$refs.tree.filter(search.value);
--
Gitblit v1.9.3