refactor: refactor async routes

This commit is contained in:
张传龙
2022-08-07 22:25:28 +08:00
parent 869a68812c
commit ef3aaa5be5
10 changed files with 159 additions and 182 deletions

View File

@@ -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))
}

View File

@@ -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']