fix: 修复路由meta.auth设置为''/[]时,权限判断为无权限的问题

后端返回路由数据时,auth字段通常会以空字符串或者空数组用来表示不需要权限校验
This commit is contained in:
hooray 2023-02-22 21:02:18 +08:00
parent b3a590d92d
commit 6a0b659750
2 changed files with 18 additions and 10 deletions

View File

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

View File

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