diff --git a/src/layout/components/Navbar.vue b/src/layout/components/Navbar.vue index 6219bf6..9b9f6f4 100644 --- a/src/layout/components/Navbar.vue +++ b/src/layout/components/Navbar.vue @@ -5,7 +5,7 @@
- +
查询 diff --git a/src/utils/common.js b/src/utils/common.js index ad543eb..fc1bbba 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -337,8 +337,10 @@ let base = { return form }, // 根据pid 重组树形结构 - buildTree(flatData) { - // 创建一个映射表,用于存储每个 id 对应的数据项 + buildTree(flatData,pidName) { + // 创建一个映射表,用于存储每个 id 对应的数据项 + let pid = pidName ? pidName : 'pid' + console.log("pid",pid) const idMap = {}; flatData.forEach(item => { idMap[item.id] = item; @@ -348,12 +350,12 @@ let base = { flatData.forEach(item => { // 如果没有父节点,则将该项添加到根节点集合中 - if (parseInt(item.pid) === 0) { + if (!item[pid] || parseInt(item[pid]) === 0) { rootNodes.push(item); } else { // 否则,将该项添加到父节点的 children 数组中 - if(idMap[item.pid]){ - const parent = idMap[item.pid]; + if(idMap[item[pid]]){ + const parent = idMap[item[pid]]; // console.log("par",parent) if (!parent.hasOwnProperty('children')) { parent.children = []; diff --git a/src/views/catalog/index.vue b/src/views/catalog/index.vue index d6a9a0f..2e922a4 100644 --- a/src/views/catalog/index.vue +++ b/src/views/catalog/index.vue @@ -23,7 +23,7 @@
- +