Commit 15354a47 authored by tianhongyang's avatar tianhongyang

生成菜单递归 卡死优化

parent 5165b094
......@@ -1064,17 +1064,13 @@ export function findAncestors(data, targetId, idKey = "id", childrenKey = "child
export function addTreeLevel(tree, startLevel = 1, removeEmptyChildren = true) {
if (tree instanceof Array && tree?.length) {
tree.forEach(node => {
addTreeLevel(node, startLevel, removeEmptyChildren);
node["level"] = startLevel;
if (node?.children) {
addTreeLevel(node.children, startLevel + 1, removeEmptyChildren);
removeEmptyChildren && !node.children?.length ? delete node.children : null;
}
});
} else if (Object.prototype.toString.call(tree) == "[object Object]") {
tree["level"] = startLevel;
if (tree?.children) {
addTreeLevel(tree.children, startLevel + 1, removeEmptyChildren);
removeEmptyChildren && !tree.children?.length ? delete tree.children : null;
}
}
return tree;
}
......@@ -1086,15 +1082,11 @@ export function addTreeLevel(tree, startLevel = 1, removeEmptyChildren = true) {
export function addNodeParent(tree, parent = null) {
if (tree instanceof Array && tree?.length) {
tree.forEach(node => {
addNodeParent(node, parent);
node["parent"] = parent ? parent : JSON.parse(JSON.stringify(parent));
if (node.children instanceof Array && node.children.length) {
addNodeParent(node.children, node);
}
});
} else if (Object.prototype.toString.call(tree) == "[object Object]") {
tree["parent"] = JSON.parse(JSON.stringify(parent));
if (tree?.children?.length) {
addNodeParent(tree.children, tree);
}
}
return tree;
}
\ No newline at end of file
......@@ -120,12 +120,11 @@ export default {
// 合并默认配置
const _options = this.mergeMenuOptions(JSON.parse(JSON.stringify(this.menuOptions)));
this.tempMenuOptions = _options;
console.log(this.tempMenuOptions);
// 映射配置
// const resultData = this.mapDataByMenuOptions(JSON.parse(JSON.stringify(this.comMenuTree)), _options);
// if (resultData) {
// this.tempMenuTree = resultData;
// }
const resultData = this.mapDataByMenuOptions(JSON.parse(JSON.stringify(this.comMenuTree)), _options);
if (resultData) {
this.tempMenuTree = resultData;
}
}
},
mergeMenuOptions(options) {
......@@ -188,7 +187,8 @@ export default {
// 添加层级
const levelResult = addTreeLevel(mapedData);
const parentResult = addNodeParent(levelResult);
return parentResult;
console.log(parentResult);
// return parentResult;
}
}
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment