refactor: refactor async routes
This commit is contained in:
@@ -2,10 +2,15 @@ import { defineStore } from 'pinia'
|
||||
import { asyncRoutes, basicRoutes } from '@/router/routes'
|
||||
|
||||
function hasPermission(route, role) {
|
||||
// * 不需要权限直接返回true
|
||||
if (!route.meta?.requireAuth) return true
|
||||
|
||||
const routeRole = route.meta?.role ? route.meta.role : []
|
||||
if (!role.length || !routeRole.length) {
|
||||
return false
|
||||
}
|
||||
|
||||
// * 登录用户没有角色或者路由没有设置角色判定为没有权限
|
||||
if (!role.length || !routeRole.length) return false
|
||||
|
||||
// * 路由指定的角色包含任一登录用户角色则判定有权限
|
||||
return role.some((item) => routeRole.includes(item))
|
||||
}
|
||||
|
||||
|
@@ -3,4 +3,4 @@ import { sStorage } from '@/utils/cache'
|
||||
export const activeTag = sStorage.get('activeTag')
|
||||
export const tags = sStorage.get('tags')
|
||||
|
||||
export const WITHOUT_TAG_PATHS = ['/404', '/login', '/redirect']
|
||||
export const WITHOUT_TAG_PATHS = ['/404', '/login']
|
||||
|
Reference in New Issue
Block a user