Ver código fonte

修复 默认首页

魏熙美 6 anos atrás
pai
commit
1646e4f189
2 arquivos alterados com 29 adições e 5 exclusões
  1. 18
    4
      src/router.js
  2. 11
    1
      src/utils/index.js

+ 18
- 4
src/router.js Ver arquivo

@@ -13,7 +13,7 @@ const routes = [
13 13
   {
14 14
     path: '/',
15 15
     name: 'index',
16
-    redirect: '/dashboard',
16
+    redirect: '/exception/indexWelcome', // /dashboard
17 17
     component: () => import('@/layout/index.vue'),
18 18
     children: [
19 19
       ...pages,
@@ -39,10 +39,14 @@ const routes = [
39 39
         name: 'norights',
40 40
         component: () => import('@/views/NoRights.vue'),
41 41
       },
42
-      {
43
-        path: 'indexWelcome',
42
+      { // 显示欢迎语
43
+        path: '/exception/indexWelcome',
44 44
         name: 'indexWelcome',
45 45
         component: () => import('@/views/indexWelcome.vue'),
46
+        meta: {
47
+          menuShow: false,
48
+          title: '欢迎语',
49
+        },
46 50
       },
47 51
     ]
48 52
   },
@@ -58,13 +62,23 @@ const router = new VueRouter({ routes })
58 62
 router.beforeEach((to, from, next) => {
59 63
   NProgress.start()
60 64
 
61
-  console.log(to)
62 65
   const toLogin = { name: 'login', query: { from: to.name } }
63 66
   const toIndex = { name: 'index' }
64 67
   const to403 = { name: 'norights' }
65 68
 
69
+  // console.log(to)
70
+  /**
71
+   *  在 utils/index.js 文件里面,有一段代码是 获取用户信息的请求,
72
+   *  当后端返回状态码 401 ,就跳转到 login页面,会出现无限死循环,不停的跳转 login 页面
73
+   *  所以在这里判断 如果是路由是 login 就直接进行下一步
74
+   */
75
+  if (to.name === 'login') {
76
+    return next()
77
+  }
78
+
66 79
   // 尝试去获取人员
67 80
   store.dispatch('getUser').then(() => {
81
+
68 82
     // 校验权限
69 83
     if (checkAuthority(store.state, to.name)) {
70 84
       return to.name === 'login' || to.fullPath.indexOf('/exception') > -1 ? next(toIndex) : next()

+ 11
- 1
src/utils/index.js Ver arquivo

@@ -1,6 +1,7 @@
1 1
 import axios from 'axios'
2 2
 import httpCode from './httpcode'
3 3
 import { error } from './message'
4
+import router from '../router'
4 5
 
5 6
 // 替换 url 中的参数
6 7
 export const replaceApiParams = (api, params) => {
@@ -48,7 +49,16 @@ export const request = filters => (api, dt) => {
48 49
         const { code, message: result, data: returnval } = data
49 50
         if (code === httpCode.HTTP_UNAUTHORIZED) {
50 51
           // const router = require('../router').default
51
-          // router.push({name: 'login'})
52
+
53
+          /**
54
+              后端返回 401 状态码,就跳转到 login 页面
55
+              这里会出现无限死循环,不停的跳转 login 页面
56
+              在 router.js 文件里面,加了行代码
57
+              if (to.name === 'login') {
58
+                return next()
59
+              }
60
+          **/
61
+          router.push({name: 'login'})
52 62
           reject("请先登录系统")
53 63
           return undefined
54 64
         }