function getMenuItem(route, basePath = '') {
let menuItem = {
label: (route.meta && route.meta.title) || route.name,
key: route.name,
path: resolvePath(basePath, route.path),
icon: getIcon(route.meta),
order: route.meta?.order || 0,
}
const visibleChildren = route.children
? route.children.filter((item) => item.name && !item.isHidden)
: []
if (!visibleChildren.length) return menuItem
menuItem.children = visibleChildren
.map((item) => getMenuItem(item, menuItem.path))
.sort((a, b) => a.order - b.order)
// if (visibleChildren.length === 1) {
// // 单个子路由处理
// const singleRoute = visibleChildren[0]
// menuItem = {
// ...menuItem,
// label: singleRoute.meta?.title || singleRoute.name,
// key: singleRoute.name,
// path: resolvePath(menuItem.path, singleRoute.path),
// icon: getIcon(singleRoute.meta),
// }
// const visibleItems = singleRoute.children
// ? singleRoute.children.filter((item) => item.name && !item.isHidden)
// : []
// if (visibleItems.length === 1) {
// menuItem.children = getMenuItem(visibleItems[0], menuItem.path)
// } else if (visibleItems.length > 1) {
// menuItem.children = visibleItems
// .map((item) => getMenuItem(item, menuItem.path))
// .sort((a, b) => a.order - b.order)
// }
// } else {
// menuItem.children = visibleChildren
// .map((item) => getMenuItem(item, menuItem.path))
// .sort((a, b) => a.order - b.order)
// }
return menuItem
}
function getMenuItem(route, basePath = '') {
let menuItem = {
label: (route.meta && route.meta.title) || route.name,
key: route.name,
path: resolvePath(basePath, route.path),
icon: getIcon(route.meta),
order: route.meta?.order || 0,
}
const visibleChildren = route.children
? route.children.filter((item) => item.name && !item.isHidden)
: []
if (!visibleChildren.length) return menuItem
menuItem.children = visibleChildren
.map((item) => getMenuItem(item, menuItem.path))
.sort((a, b) => a.order - b.order)
// if (visibleChildren.length === 1) {
// // 单个子路由处理
// const singleRoute = visibleChildren[0]
// menuItem = {
// ...menuItem,
// label: singleRoute.meta?.title || singleRoute.name,
// key: singleRoute.name,
// path: resolvePath(menuItem.path, singleRoute.path),
// icon: getIcon(singleRoute.meta),
// }
// const visibleItems = singleRoute.children
// ? singleRoute.children.filter((item) => item.name && !item.isHidden)
// : []
// if (visibleItems.length === 1) {
// menuItem.children = getMenuItem(visibleItems[0], menuItem.path)
// } else if (visibleItems.length > 1) {
// menuItem.children = visibleItems
// .map((item) => getMenuItem(item, menuItem.path))
// .sort((a, b) => a.order - b.order)
// }
// } else {
// menuItem.children = visibleChildren
// .map((item) => getMenuItem(item, menuItem.path))
// .sort((a, b) => a.order - b.order)
// }
return menuItem
}