权限重构

This commit is contained in:
Teo
2025-08-28 03:35:18 +08:00
parent f637e65635
commit b59bd89e43
15 changed files with 293 additions and 89 deletions

View File

@ -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已完成
}