From 6a0b65975023553992c6f65851af067f034679f5 Mon Sep 17 00:00:00 2001 From: hooray <304327508@qq.com> Date: Wed, 22 Feb 2023 21:02:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=B7=AF=E7=94=B1`met?= =?UTF-8?q?a.auth`=E8=AE=BE=E7=BD=AE=E4=B8=BA`''`/`[]`=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=9D=83=E9=99=90=E5=88=A4=E6=96=AD=E4=B8=BA=E6=97=A0=E6=9D=83?= =?UTF-8?q?=E9=99=90=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后端返回路由数据时,auth字段通常会以空字符串或者空数组用来表示不需要权限校验 --- src/store/modules/menu.ts | 14 +++++++++----- src/store/modules/route.ts | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/store/modules/menu.ts b/src/store/modules/menu.ts index c9462fe..26c6994 100644 --- a/src/store/modules/menu.ts +++ b/src/store/modules/menu.ts @@ -99,11 +99,15 @@ const useMenuStore = defineStore( let isAuth = false if (menu.meta && menu.meta.auth) { isAuth = permissions.some((auth) => { - return typeof menu.meta?.auth === 'string' - ? menu.meta.auth === auth - : typeof menu.meta?.auth === 'object' - ? menu.meta.auth.includes(auth) - : false + if (typeof menu.meta?.auth === 'string') { + return menu.meta.auth !== '' ? menu.meta.auth === auth : true + } + else if (typeof menu.meta?.auth === 'object') { + return menu.meta.auth.length > 0 ? menu.meta.auth.includes(auth) : true + } + else { + return false + } }) } else { diff --git a/src/store/modules/route.ts b/src/store/modules/route.ts index 9f133ed..23d282f 100644 --- a/src/store/modules/route.ts +++ b/src/store/modules/route.ts @@ -111,11 +111,15 @@ const useRouteStore = defineStore( let isAuth = false if (route.meta?.auth) { isAuth = permissions.some((auth) => { - return typeof route.meta?.auth === 'string' - ? route.meta.auth === auth - : typeof route.meta?.auth === 'object' - ? route.meta.auth.includes(auth) - : false + if (typeof route.meta?.auth === 'string') { + return route.meta.auth !== '' ? route.meta.auth === auth : true + } + else if (typeof route.meta?.auth === 'object') { + return route.meta.auth.length > 0 ? route.meta.auth.includes(auth) : true + } + else { + return false + } }) } else {