From 7987a18c70d649d87efbda0212f6e8c7891be533 Mon Sep 17 00:00:00 2001 From: xiaoxian521 <1923740402@qq.com> Date: Tue, 6 Dec 2022 21:08:41 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E8=B7=AF=E7=94=B1=20?= =?UTF-8?q?`rank`=EF=BC=8C=E5=BD=93`rank`=20=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E6=A0=B9=E6=8D=AE=E9=A1=BA=E5=BA=8F=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=9B=E5=BB=BA=EF=BC=8C=E9=A6=96=E9=A1=B5=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E6=B0=B8=E8=BF=9C=E5=9C=A8=E7=AC=AC=E4=B8=80=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- src/router/modules/error.ts | 1 + src/router/utils.ts | 21 ++++++++++++--------- src/views/empty/index.vue | 8 ++++++-- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index aec325824..0dc47c807 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@logicflow/extension": "^1.1.30", "@pureadmin/descriptions": "^1.1.0", "@pureadmin/table": "^1.8.3", - "@pureadmin/utils": "^1.7.4", + "@pureadmin/utils": "^1.7.5", "@vueuse/core": "^9.6.0", "@vueuse/motion": "2.0.0-beta.12", "@wangeditor/editor": "^5.1.21", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bb9267ede..45604a667 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,7 +16,7 @@ specifiers: "@pureadmin/descriptions": ^1.1.0 "@pureadmin/table": ^1.8.3 "@pureadmin/theme": ^2.4.0 - "@pureadmin/utils": ^1.7.4 + "@pureadmin/utils": ^1.7.5 "@types/element-resize-detector": 1.1.3 "@types/intro.js": ^5.1.0 "@types/js-cookie": ^3.0.1 @@ -124,7 +124,7 @@ dependencies: "@logicflow/extension": 1.1.31 "@pureadmin/descriptions": 1.1.1_element-plus@2.2.26 "@pureadmin/table": 1.8.3_element-plus@2.2.26 - "@pureadmin/utils": 1.7.4_aotapuqn7htzdjltsyimavekky + "@pureadmin/utils": 1.7.5_aotapuqn7htzdjltsyimavekky "@vueuse/core": 9.6.0_vue@3.2.45 "@vueuse/motion": 2.0.0-beta.12_vue@3.2.45 "@wangeditor/editor": 5.1.23 @@ -1294,10 +1294,10 @@ packages: string-hash: 1.1.3 dev: true - /@pureadmin/utils/1.7.4_aotapuqn7htzdjltsyimavekky: + /@pureadmin/utils/1.7.5_aotapuqn7htzdjltsyimavekky: resolution: { - integrity: sha512-uJNHcb2sO7R2avALf+v4TGyuZtJix0Wpw/kMb6eO4C003ZQImuGGi9WlxHaOlESrMyFHZ1AjWm5AqLwJLnpVlw== + integrity: sha512-WqjtvMD67egsIJuPYx9V9aaXG3iYOTMj48XPfYxBzWTuUSvGkEj9M+3P1IrgG6GZQlK8dCPqaog8B0vujLjYJA== } peerDependencies: dayjs: "*" diff --git a/src/router/modules/error.ts b/src/router/modules/error.ts index 37b27479f..22ee97f31 100644 --- a/src/router/modules/error.ts +++ b/src/router/modules/error.ts @@ -6,6 +6,7 @@ export default { redirect: "/error/403", meta: { icon: "informationLine", + // showLink: false, title: $t("menus.hsabnormal"), rank: error }, diff --git a/src/router/utils.ts b/src/router/utils.ts index 7590db510..3510d59a2 100644 --- a/src/router/utils.ts +++ b/src/router/utils.ts @@ -13,6 +13,7 @@ import { useTimeoutFn } from "@vueuse/core"; import { RouteConfigs } from "@/layout/types"; import { isString, + isAllEmpty, storageSession, isIncludeAllChildren } from "@pureadmin/utils"; @@ -28,19 +29,21 @@ const modulesRoutes = import.meta.glob("/src/views/**/*.{vue,tsx}"); // 动态路由 import { getAsyncRoutes } from "@/api/routes"; +function handRank(ramk: number, name: string, path: string) { + return isAllEmpty(ramk) || (ramk === 0 && name !== "Home" && path !== "/") + ? true + : false; +} + /** 按照路由中meta下的rank等级升序来排序路由 */ function ascending(arr: any[]) { - arr.forEach(v => { - if (v?.meta?.rank === null) v.meta.rank = undefined; - if (v?.meta?.rank === 0) { - if (v.name !== "Home" && v.path !== "/") { - console.warn("rank only the home page can be 0"); - } - } + arr.forEach((v, index) => { + // 当rank不存在时,根据顺序自动创建,首页路由永远在第一位 + if (handRank(v?.meta?.rank, v.name, v.path)) v.meta.rank = index + 2; }); return arr.sort( (a: { meta: { rank: number } }, b: { meta: { rank: number } }) => { - return a?.meta?.rank - b?.meta?.rank; + return a?.meta.rank - b?.meta.rank; } ); } @@ -252,7 +255,7 @@ function formatTwoStageRoutes(routesList: RouteRecordRaw[]) { children: [] }); } else { - newRoutesList[0].children.push({ ...v }); + newRoutesList[0]?.children.push({ ...v }); } }); return newRoutesList; diff --git a/src/views/empty/index.vue b/src/views/empty/index.vue index 0fe3ed4e6..bc42d4b29 100644 --- a/src/views/empty/index.vue +++ b/src/views/empty/index.vue @@ -7,8 +7,12 @@ defineOptions({