物业之前,新工作台
This commit is contained in:
@@ -31,8 +31,7 @@ router.beforeEach(async (to, from, next) => {
|
||||
if (useUserStore().roles.length === 0) {
|
||||
isRelogin.show = true;
|
||||
// 判断当前用户是否已拉取完user_info信息
|
||||
const [data, err] = await tos(useUserStore().getInfo());
|
||||
console.log(data);
|
||||
const [err, res] = await tos(useUserStore().getInfo());
|
||||
if (err) {
|
||||
await useUserStore().logout();
|
||||
ElMessage.error(err);
|
||||
@@ -46,8 +45,13 @@ router.beforeEach(async (to, from, next) => {
|
||||
router.addRoute(route); // 动态添加可访问路由表
|
||||
}
|
||||
});
|
||||
// @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已完成
|
||||
if (res.user.userId === 1 && from.path === '/login') {
|
||||
// 管理员 → 强制跳转到社区列表
|
||||
next('/community/communitylist');
|
||||
} else {
|
||||
// 普通用户 → 正常跳转目标页
|
||||
next(to.fullPath);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
next();
|
||||
@@ -59,8 +63,7 @@ router.beforeEach(async (to, from, next) => {
|
||||
// 在免登录白名单,直接进入
|
||||
next();
|
||||
} else {
|
||||
const redirect = encodeURIComponent(to.fullPath || '/');
|
||||
next(`/login?redirect=${redirect}`); // 否则全部重定向到登录页
|
||||
next(`/login`); // 否则全部重定向到登录页
|
||||
NProgress.done();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user