Browse Source

修改路由问题

dusenyao 2 days ago
parent
commit
e17d1ad639
3 changed files with 16 additions and 5 deletions
  1. 0 2
      src/layouts/default/header/index.vue
  2. 14 2
      src/router/guard/index.js
  3. 2 1
      src/views/login/index.vue

+ 0 - 2
src/layouts/default/header/index.vue

@@ -54,13 +54,11 @@ export default {
         { key: 'personal_center', name: '个人中心' },
       ],
       ORG_MANAGER: [
-        { key: 'home', name: '主页' },
         { key: 'project_manage/org/project', name: '项目管理' },
         { key: 'user_manage_org', name: '用户管理' },
         { key: 'personal_center', name: '个人中心' },
       ],
       ADMIN: [
-        { key: 'home', name: '主页' },
         { key: 'org_manage', name: '机构管理' },
         { key: 'user_manage', name: '用户管理' },
         { key: 'system_config', name: '系统配置' },

+ 14 - 2
src/router/guard/index.js

@@ -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)) {
       // 在登录白名单中,直接进入

+ 2 - 1
src/views/login/index.vue

@@ -53,6 +53,7 @@
 import md5 from 'md5';
 import { GetLogo } from '@/api/app';
 import { setConfig, getLocalStore, setLocalStore } from '@/utils/auth';
+import { getUserTypeToJump } from '@/router/guard';
 import { updateBaseURL } from '@/utils/http';
 
 import UserAgreement from './userAgreement.vue';
@@ -112,7 +113,7 @@ export default {
         this.$store
           .dispatch('user/login', _form)
           .then((user_type) => {
-            this.$router.push({ path: '/home' });
+            this.$router.push({ path: getUserTypeToJump(user_type) });
           })
           .catch(() => {});
       });