refactor: routes sort

This commit is contained in:
张传龙 2022-08-08 15:44:16 +08:00
parent 0bb2a904e7
commit 63c1f2f132
6 changed files with 10 additions and 10 deletions

View File

@ -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

View File

@ -25,7 +25,7 @@ export const basicRoutes = [
meta: {
title: '外部链接',
icon: 'mdi:link-variant',
index: 2,
order: 2,
},
children: [
{

View File

@ -8,7 +8,7 @@ export default {
meta: {
title: '错误页',
icon: 'mdi:alert-circle-outline',
index: 99,
order: 99,
},
children: [
{

View File

@ -10,7 +10,7 @@ export default {
icon: 'mdi:menu',
role: ['admin'],
requireAuth: true,
index: 3,
order: 3,
},
children: [
{

View File

@ -8,7 +8,7 @@ export default {
meta: {
title: '基础功能测试',
icon: 'mdi:menu',
index: 1,
order: 1,
},
children: [
{

View File

@ -13,7 +13,7 @@ export default {
meta: {
title: '工作台',
icon: 'mdi:home',
index: 0,
order: 0,
},
},
],