feat: add mix nav (#187)

feat: add mix nav
This commit is contained in:
啝裳
2022-02-14 22:09:39 +08:00
committed by GitHub
parent a2dde02994
commit ef05b2b614
21 changed files with 1313 additions and 843 deletions

View File

@@ -46,3 +46,22 @@ export function deleteChildren(menuTree, pathList = []) {
}
return menuTree;
}
// 创建层级关系
export function buildHierarchyTree(menuTree, pathList = []) {
if (!Array.isArray(menuTree)) {
console.warn("menuTree must be an array");
return;
}
if (!menuTree || menuTree.length === 0) return;
for (const [key, node] of menuTree.entries()) {
node.id = key;
node.parentId = pathList.length ? pathList[pathList.length - 1] : null;
node.pathList = [...pathList, node.id];
const hasChildren = node.children && node.children.length > 0;
if (hasChildren) {
buildHierarchyTree(node.children, node.pathList);
}
}
return menuTree;
}