refactor: routes sort
This commit is contained in:
parent
0bb2a904e7
commit
63c1f2f132
@ -24,7 +24,7 @@ const appStore = useAppStore()
|
||||
const { currentRoute } = router
|
||||
|
||||
const menuOptions = computed(() => {
|
||||
return permissionStore.menus.map((item) => getMenuItem(item)).sort((a, b) => a.index - b.index)
|
||||
return permissionStore.menus.map((item) => getMenuItem(item)).sort((a, b) => a.order - b.order)
|
||||
})
|
||||
|
||||
function resolvePath(basePath, path) {
|
||||
@ -44,7 +44,7 @@ function getMenuItem(route, basePath = '') {
|
||||
key: route.name,
|
||||
path: resolvePath(basePath, route.path),
|
||||
icon: route.meta?.icon ? renderIcon(route.meta?.icon, { size: 16 }) : renderIcon('mdi:circle-outline', { size: 8 }),
|
||||
index: route.meta?.index || 0,
|
||||
order: route.meta?.order || 0,
|
||||
}
|
||||
|
||||
const visibleChildren = route.children ? route.children.filter((item) => item.name && !item.isHidden) : []
|
||||
@ -61,19 +61,19 @@ function getMenuItem(route, basePath = '') {
|
||||
icon: singleRoute.meta?.icon
|
||||
? renderIcon(singleRoute.meta?.icon, { size: 16 })
|
||||
: renderIcon('mdi:circle-outline', { size: 8 }),
|
||||
index: menuItem.index,
|
||||
order: menuItem.order,
|
||||
}
|
||||
const visibleItems = singleRoute.children ? singleRoute.children.filter((item) => item.name && !item.isHidden) : []
|
||||
|
||||
if (visibleItems.length === 1) {
|
||||
menuItem = getMenuItem(visibleItems[0], menuItem.path)
|
||||
} else if (visibleItems.length > 1) {
|
||||
menuItem.children = visibleItems.map((item) => getMenuItem(item, menuItem.path)).sort((a, b) => a.index - b.index)
|
||||
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.index - b.index)
|
||||
.sort((a, b) => a.order - b.order)
|
||||
}
|
||||
|
||||
return menuItem
|
||||
|
@ -25,7 +25,7 @@ export const basicRoutes = [
|
||||
meta: {
|
||||
title: '外部链接',
|
||||
icon: 'mdi:link-variant',
|
||||
index: 2,
|
||||
order: 2,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
|
@ -8,7 +8,7 @@ export default {
|
||||
meta: {
|
||||
title: '错误页',
|
||||
icon: 'mdi:alert-circle-outline',
|
||||
index: 99,
|
||||
order: 99,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
|
@ -10,7 +10,7 @@ export default {
|
||||
icon: 'mdi:menu',
|
||||
role: ['admin'],
|
||||
requireAuth: true,
|
||||
index: 3,
|
||||
order: 3,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
|
@ -8,7 +8,7 @@ export default {
|
||||
meta: {
|
||||
title: '基础功能测试',
|
||||
icon: 'mdi:menu',
|
||||
index: 1,
|
||||
order: 1,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ export default {
|
||||
meta: {
|
||||
title: '工作台',
|
||||
icon: 'mdi:home',
|
||||
index: 0,
|
||||
order: 0,
|
||||
},
|
||||
},
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user