From 9151b2d29760a4a69ba8992337f1c27450edd5f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E4=BC=A0=E9=BE=99?= Date: Fri, 3 Jun 2022 22:42:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=8F=9C=E5=8D=95=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/components/sidebar/components/SideMenu.vue | 10 +++++++--- src/router/routes/index.js | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/layout/components/sidebar/components/SideMenu.vue b/src/layout/components/sidebar/components/SideMenu.vue index bb18508..8fb4c67 100644 --- a/src/layout/components/sidebar/components/SideMenu.vue +++ b/src/layout/components/sidebar/components/SideMenu.vue @@ -27,7 +27,7 @@ const appStore = useAppStore() const { currentRoute } = router const menuOptions = computed(() => { - return permissionStore.menus.map((item) => getMenuItem(item)) + return permissionStore.menus.map((item) => getMenuItem(item)).sort((a, b) => a.index - b.index) }) function resolvePath(basePath, path) { @@ -47,6 +47,7 @@ function getMenuItem(route, basePath = '') { key: route.name, path: resolvePath(basePath, route.path), icon: route.meta?.icon ? renderIcon(route.meta?.icon, { size: 16 }) : renderIcon(IconCircle, { size: 8 }), + index: route.meta?.index || 0, } const visibleChildren = route.children ? route.children.filter((item) => item.name && !item.isHidden) : [] @@ -63,16 +64,19 @@ function getMenuItem(route, basePath = '') { icon: singleRoute.meta?.icon ? renderIcon(singleRoute.meta?.icon, { size: 16 }) : renderIcon(IconCircle, { size: 8 }), + index: menuItem.index, } 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)) + menuItem.children = visibleItems.map((item) => getMenuItem(item, menuItem.path)).sort((a, b) => a.index - b.index) } } else { - menuItem.children = visibleChildren.map((item) => getMenuItem(item, menuItem.path)) + menuItem.children = visibleChildren + .map((item) => getMenuItem(item, menuItem.path)) + .sort((a, b) => a.index - b.index) } return menuItem diff --git a/src/router/routes/index.js b/src/router/routes/index.js index 960bdb0..81f144c 100644 --- a/src/router/routes/index.js +++ b/src/router/routes/index.js @@ -72,6 +72,7 @@ export const basicRoutes = [ meta: { title: '错误页', icon: IconAlert, + index: 4, }, children: [ {