5.1日 暂定 水电表管理
This commit is contained in:
@@ -44,14 +44,12 @@ router.beforeEach(async (to, from) => {
|
||||
if (isWhiteList(to.path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (userStore.roles.length === 0 && !isDynamicRoutesAdded) {
|
||||
if (userStore.roles.length === 0) {
|
||||
isRelogin.show = true;
|
||||
|
||||
// 获取用户信息
|
||||
const [err, res] = await tos(userStore.getInfo());
|
||||
if (err) {
|
||||
console.error('❌ 获取用户信息失败:', err);
|
||||
await userStore.logout();
|
||||
ElMessage.error(err);
|
||||
isDynamicRoutesAdded = false;
|
||||
@@ -59,7 +57,7 @@ router.beforeEach(async (to, from) => {
|
||||
}
|
||||
|
||||
isRelogin.show = false;
|
||||
|
||||
permissionStore.resetRoutes();
|
||||
// 生成动态路由
|
||||
const accessRoutes = await permissionStore.generateRoutes();
|
||||
|
||||
@@ -74,36 +72,27 @@ router.beforeEach(async (to, from) => {
|
||||
isDynamicRoutesAdded = true;
|
||||
|
||||
// 管理员登录强制跳转
|
||||
if (res.user.userId === 1 && from.path === '/login') {
|
||||
console.log('👑 管理员登录,跳转到社区列表');
|
||||
if (from.path === '/login') {
|
||||
return { path: '/community/communitylist', replace: true };
|
||||
} else {
|
||||
// 重新进入当前路由(让新添加的路由生效)
|
||||
console.log('🔄 重新跳转目标页面:', to.path);
|
||||
return { ...to, replace: true };
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================
|
||||
// ✅ 已经初始化完成 → 直接放行!
|
||||
// ==============================================
|
||||
console.log('✅ 已完成初始化,直接放行');
|
||||
return;
|
||||
} else {
|
||||
// 未登录
|
||||
isDynamicRoutesAdded = false;
|
||||
console.log('🔒 未登录,跳转到登录页');
|
||||
|
||||
if (isWhiteList(to.path)) {
|
||||
return;
|
||||
} else {
|
||||
NProgress.done();
|
||||
return `/login?redirect=${to.fullPath}`;
|
||||
return `/login`;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
router.afterEach(() => {
|
||||
NProgress.done();
|
||||
console.log('✅ 跳转完成\n\n');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user