权限重构
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import $cache from '@/plugins/cache';
|
||||
import { to as tos } from 'await-to-js';
|
||||
import router from './router';
|
||||
import NProgress from 'nprogress';
|
||||
@ -29,7 +30,7 @@ router.beforeEach(async (to, from, next) => {
|
||||
} else if (isWhiteList(to.path)) {
|
||||
next();
|
||||
} else {
|
||||
if (useUserStore().roles.length === 0) {
|
||||
if (useUserStore().roles.length === 0 || $cache.local.getJSON('isCheckRole')) {
|
||||
isRelogin.show = true;
|
||||
// 判断当前用户是否已拉取完user_info信息
|
||||
const [err] = await tos(useUserStore().getInfo());
|
||||
@ -44,8 +45,11 @@ router.beforeEach(async (to, from, next) => {
|
||||
accessRoutes.forEach((route) => {
|
||||
if (!isHttp(route.path)) {
|
||||
router.addRoute(route); // 动态添加可访问路由表
|
||||
console.log('🚀 ~ route:', route);
|
||||
}
|
||||
});
|
||||
$cache.local.remove('isCheckRole');
|
||||
|
||||
// @ts-expect-error hack方法 确保addRoutes已完成
|
||||
next({ path: to.path, replace: true, params: to.params, query: to.query, hash: to.hash, name: to.name as string }); // hack方法 确保addRoutes已完成
|
||||
}
|
||||
|
Reference in New Issue
Block a user