mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-12-25 22:30:19 +08:00
fix(projects): 修复路由命名为包含关系时导致导航数据出错的问题
This commit is contained in:
@@ -63,18 +63,29 @@ export function translateMenuLabel(menus: App.GlobalMenuOption[]): App.GlobalMen
|
||||
* @param menus - 菜单数据
|
||||
*/
|
||||
export function getActiveKeyPathsOfMenus(activeKey: string, menus: App.GlobalMenuOption[]) {
|
||||
const keys = menus.map(menu => getActiveKeyPathsOfMenu(activeKey, menu)).flat(1);
|
||||
return keys;
|
||||
}
|
||||
|
||||
function getActiveKeyPathsOfMenu(activeKey: string, menu: App.GlobalMenuOption) {
|
||||
const keys: string[] = [];
|
||||
if (activeKey.startsWith(menu.routeName)) {
|
||||
keys.push(menu.routeName);
|
||||
}
|
||||
if (menu.children) {
|
||||
keys.push(...menu.children.map(item => getActiveKeyPathsOfMenu(activeKey, item as App.GlobalMenuOption)).flat(1));
|
||||
const keys = [] as any;
|
||||
const lists = [] as any;
|
||||
function traverse(list: any, parent = null) {
|
||||
list.forEach((t: any) => {
|
||||
lists.push(t);
|
||||
if (parent) {
|
||||
t.parent = parent;
|
||||
}
|
||||
if (t.children) {
|
||||
traverse(t.children, t);
|
||||
}
|
||||
});
|
||||
}
|
||||
traverse(JSON.parse(JSON.stringify(menus)));
|
||||
lists.forEach((t: App.GlobalMenuOption) => {
|
||||
if (t.routeName === activeKey) {
|
||||
let temp = t;
|
||||
while (temp) {
|
||||
keys.push(temp.routeName);
|
||||
temp = temp.parent as App.GlobalMenuOption;
|
||||
}
|
||||
}
|
||||
});
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user