Skip to content

Commit

Permalink
fix: 修复主导航 children 为空时报错
Browse files Browse the repository at this point in the history
  • Loading branch information
hooray committed Jun 24, 2024
1 parent 57fcd27 commit 9e444c8
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/store/modules/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,26 @@ const useMenuStore = defineStore(
function convertRouteToMenu(routes: Route.recordMainRaw[]): Menu.recordMainRaw[] {
const returnMenus: Menu.recordMainRaw[] = []
routes.forEach((item) => {
if (settingsStore.settings.menu.mode === 'single') {
returnMenus.length === 0 && returnMenus.push({
meta: {},
children: [],
})
returnMenus[0].children.push(...convertRouteToMenuRecursive(item.children))
}
else {
const menuItem: Menu.recordMainRaw = {
meta: {
title: item?.meta?.title,
icon: item?.meta?.icon,
auth: item?.meta?.auth,
},
children: [],
if (item.children.length > 0) {
if (settingsStore.settings.menu.mode === 'single') {
returnMenus.length === 0 && returnMenus.push({
meta: {},
children: [],
})
returnMenus[0].children.push(...convertRouteToMenuRecursive(item.children))
}
else {
const menuItem: Menu.recordMainRaw = {
meta: {
title: item?.meta?.title,
icon: item?.meta?.icon,
auth: item?.meta?.auth,
},
children: [],
}
menuItem.children = convertRouteToMenuRecursive(item.children)
returnMenus.push(menuItem)
}
menuItem.children = convertRouteToMenuRecursive(item.children)
returnMenus.push(menuItem)
}
})
return returnMenus
Expand Down

0 comments on commit 9e444c8

Please sign in to comment.