|
@@ -6,6 +6,17 @@ NProgress.configure({ showSpinner: false });
|
|
|
|
|
|
const whiteList = ['/login', '/image_change', '/register']; // 重定向白名单
|
|
|
|
|
|
+// 用户类型对应的跳转路径
|
|
|
+export const userTypeToJump = {
|
|
|
+ USER: '/',
|
|
|
+ ORG_MANAGER: '/project_manage/org/project',
|
|
|
+ ADMIN: '/org_manage',
|
|
|
+};
|
|
|
+
|
|
|
+export function getUserTypeToJump(type) {
|
|
|
+ return userTypeToJump[type] || '/';
|
|
|
+}
|
|
|
+
|
|
|
export function setupRouterGuard(router) {
|
|
|
// 全局前置守卫
|
|
|
router.beforeEach(async (to, from, next) => {
|
|
@@ -13,13 +24,14 @@ export function setupRouterGuard(router) {
|
|
|
|
|
|
const token = getToken();
|
|
|
|
|
|
+ const userType = token?.user_type ?? '';
|
|
|
+
|
|
|
if (token) {
|
|
|
if (to.path === '/login') {
|
|
|
- next({ path: '/home' });
|
|
|
+ next({ path: getUserTypeToJump(userType) });
|
|
|
NProgress.done();
|
|
|
return;
|
|
|
}
|
|
|
- next();
|
|
|
return;
|
|
|
} else if (whiteList.includes(to.path)) {
|
|
|
// 在登录白名单中,直接进入
|