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 { currentRoute } = router
const menuOptions = computed(() => { 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) { function resolvePath(basePath, path) {
@ -44,7 +44,7 @@ function getMenuItem(route, basePath = '') {
key: route.name, key: route.name,
path: resolvePath(basePath, route.path), path: resolvePath(basePath, route.path),
icon: route.meta?.icon ? renderIcon(route.meta?.icon, { size: 16 }) : renderIcon('mdi:circle-outline', { size: 8 }), 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) : [] const visibleChildren = route.children ? route.children.filter((item) => item.name && !item.isHidden) : []
@ -61,19 +61,19 @@ function getMenuItem(route, basePath = '') {
icon: singleRoute.meta?.icon icon: singleRoute.meta?.icon
? renderIcon(singleRoute.meta?.icon, { size: 16 }) ? renderIcon(singleRoute.meta?.icon, { size: 16 })
: renderIcon('mdi:circle-outline', { size: 8 }), : renderIcon('mdi:circle-outline', { size: 8 }),
index: menuItem.index, order: menuItem.order,
} }
const visibleItems = singleRoute.children ? singleRoute.children.filter((item) => item.name && !item.isHidden) : [] const visibleItems = singleRoute.children ? singleRoute.children.filter((item) => item.name && !item.isHidden) : []
if (visibleItems.length === 1) { if (visibleItems.length === 1) {
menuItem = getMenuItem(visibleItems[0], menuItem.path) menuItem = getMenuItem(visibleItems[0], menuItem.path)
} else if (visibleItems.length > 1) { } 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 { } else {
menuItem.children = visibleChildren menuItem.children = visibleChildren
.map((item) => getMenuItem(item, menuItem.path)) .map((item) => getMenuItem(item, menuItem.path))
.sort((a, b) => a.index - b.index) .sort((a, b) => a.order - b.order)
} }
return menuItem return menuItem

View File

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

View File

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

View File

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

View File

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

View File

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