fix: 优化子路由设置

This commit is contained in:
2024-08-04 14:31:29 +08:00
parent 0a596f3fdc
commit f54caed4da
2 changed files with 10380 additions and 1 deletions

10371
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -45,10 +45,16 @@ const transformComponentView = (component: string) => {
const formatAsyncRoutes = (menus: RouteItem[]) => {
if (!menus.length) return []
menus.sort((a, b) => (a?.sort ?? 0) - (b?.sort ?? 0)) // 排序
const pathMap = new Map()
const routes = mapTree(menus, (item) => {
pathMap.set(item.id, item.path)
if (item.children && item.children.length) {
item.children.sort((a, b) => (a?.sort ?? 0) - (b?.sort ?? 0)) // 排序
}
// 部分子菜单,例如:通知公告新增、查看详情,需要选中其父菜单
if (item.parentId && item.type === 2 && item.permission) {
item.activeMenu = pathMap.get(item.parentId)
}
return {
path: item.path,
name: item.name ?? transformPathToName(item.path),
@@ -58,7 +64,9 @@ const formatAsyncRoutes = (menus: RouteItem[]) => {
title: item.title,
hidden: item.isHidden,
keepAlive: item.isCache,
icon: item.icon
icon: item.icon,
showInTabs: item.showInTabs,
activeMenu: item.activeMenu
}
}
})