gaoluyang
4 小时以前 b3c02cc20a3493388ee66aa06b17d288933de7d3
1.产品维护产品大类新增时层级不做限制
已修改1个文件
79 ■■■■ 文件已修改
src/views/basicData/product/index.vue 79 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/basicData/product/index.vue
@@ -177,7 +177,7 @@
</template>
<script setup>
import { ref } from "vue";
import { nextTick, ref } from "vue";
import { ElMessageBox } from "element-plus";
import {
  addOrEditProduct,
@@ -194,7 +194,7 @@
const containerRef = ref(null);
const treeKey = ref(0);
const expandedKeySet = new Set();
const EXPANDED_STORAGE_KEY = "basicData_product_tree_expanded_keys";
const EXPANDED_STORAGE_KEY = "basicData_product_tree_expanded_keys_v2";
const loadExpandedKeys = () => {
  if (typeof window === "undefined") {
@@ -220,6 +220,64 @@
};
loadExpandedKeys().forEach((key) => expandedKeySet.add(key));
const syncExpandedKeysFromTree = () => {
  const keys = [];
  const walk = (nodes) => {
    (nodes || []).forEach((item) => {
      if (item.expanded && item.data?.id !== undefined) {
        keys.push(item.data.id);
      }
      if (item.childNodes && item.childNodes.length) {
        walk(item.childNodes);
      }
    });
  };
  walk(tree.value?.root?.childNodes);
  expandedKeySet.clear();
  keys.forEach((key) => expandedKeySet.add(key));
  expandedKeys.value = keys;
  saveExpandedKeys();
};
const normalizeExpandedKeys = (treeData) => {
  const parentMap = new Map();
  const walk = (nodes, parentId = null) => {
    (nodes || []).forEach((item) => {
      parentMap.set(item.id, parentId);
      if (item.children && item.children.length) {
        walk(item.children, item.id);
      }
    });
  };
  walk(treeData);
  const normalizedKeys = Array.from(expandedKeySet).filter((key) => {
    if (!parentMap.has(key)) {
      return false;
    }
    let currentId = key;
    while (parentMap.has(currentId)) {
      const parentId = parentMap.get(currentId);
      if (!parentId) {
        return true;
      }
      if (!expandedKeySet.has(parentId)) {
        return false;
      }
      currentId = parentId;
    }
    return true;
  });
  if (normalizedKeys.length !== expandedKeySet.size) {
    expandedKeySet.clear();
    normalizedKeys.forEach((key) => expandedKeySet.add(key));
    saveExpandedKeys();
  }
};
const productDia = ref(false);
const modelDia = ref(false);
@@ -290,8 +348,12 @@
  productTreeList()
    .then((res) => {
      list.value = res || [];
      normalizeExpandedKeys(list.value);
      expandedKeys.value = Array.from(expandedKeySet);
      treeKey.value += 1;
      nextTick(() => {
        tree.value?.setDefaultExpandedKeys?.(expandedKeys.value);
      });
    })
    .catch((err) => {
      console.error(err);
@@ -301,14 +363,13 @@
    });
};
const handleNodeExpand = (data) => {
  expandedKeySet.add(data.id);
  expandedKeys.value = Array.from(expandedKeySet);
  saveExpandedKeys();
  nextTick(syncExpandedKeysFromTree);
};
const handleNodeCollapse = (data) => {
  expandedKeySet.delete(data.id);
  expandedKeys.value = Array.from(expandedKeySet);
  saveExpandedKeys();
const handleNodeCollapse = (data, node) => {
  node?.eachNode?.((item) => {
    item.collapse();
  });
  nextTick(syncExpandedKeysFromTree);
};
// 过滤产品树
const searchFilter = () => {