瀏覽代碼

修复 默认首页

魏熙美 6 年之前
父節點
當前提交
1646e4f189
共有 2 個檔案被更改,包括 29 行新增5 行删除
  1. 18
    4
      src/router.js
  2. 11
    1
      src/utils/index.js

+ 18
- 4
src/router.js 查看文件

13
   {
13
   {
14
     path: '/',
14
     path: '/',
15
     name: 'index',
15
     name: 'index',
16
-    redirect: '/dashboard',
16
+    redirect: '/exception/indexWelcome', // /dashboard
17
     component: () => import('@/layout/index.vue'),
17
     component: () => import('@/layout/index.vue'),
18
     children: [
18
     children: [
19
       ...pages,
19
       ...pages,
39
         name: 'norights',
39
         name: 'norights',
40
         component: () => import('@/views/NoRights.vue'),
40
         component: () => import('@/views/NoRights.vue'),
41
       },
41
       },
42
-      {
43
-        path: 'indexWelcome',
42
+      { // 显示欢迎语
43
+        path: '/exception/indexWelcome',
44
         name: 'indexWelcome',
44
         name: 'indexWelcome',
45
         component: () => import('@/views/indexWelcome.vue'),
45
         component: () => import('@/views/indexWelcome.vue'),
46
+        meta: {
47
+          menuShow: false,
48
+          title: '欢迎语',
49
+        },
46
       },
50
       },
47
     ]
51
     ]
48
   },
52
   },
58
 router.beforeEach((to, from, next) => {
62
 router.beforeEach((to, from, next) => {
59
   NProgress.start()
63
   NProgress.start()
60
 
64
 
61
-  console.log(to)
62
   const toLogin = { name: 'login', query: { from: to.name } }
65
   const toLogin = { name: 'login', query: { from: to.name } }
63
   const toIndex = { name: 'index' }
66
   const toIndex = { name: 'index' }
64
   const to403 = { name: 'norights' }
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
   store.dispatch('getUser').then(() => {
80
   store.dispatch('getUser').then(() => {
81
+
68
     // 校验权限
82
     // 校验权限
69
     if (checkAuthority(store.state, to.name)) {
83
     if (checkAuthority(store.state, to.name)) {
70
       return to.name === 'login' || to.fullPath.indexOf('/exception') > -1 ? next(toIndex) : next()
84
       return to.name === 'login' || to.fullPath.indexOf('/exception') > -1 ? next(toIndex) : next()

+ 11
- 1
src/utils/index.js 查看文件

1
 import axios from 'axios'
1
 import axios from 'axios'
2
 import httpCode from './httpcode'
2
 import httpCode from './httpcode'
3
 import { error } from './message'
3
 import { error } from './message'
4
+import router from '../router'
4
 
5
 
5
 // 替换 url 中的参数
6
 // 替换 url 中的参数
6
 export const replaceApiParams = (api, params) => {
7
 export const replaceApiParams = (api, params) => {
48
         const { code, message: result, data: returnval } = data
49
         const { code, message: result, data: returnval } = data
49
         if (code === httpCode.HTTP_UNAUTHORIZED) {
50
         if (code === httpCode.HTTP_UNAUTHORIZED) {
50
           // const router = require('../router').default
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
           reject("请先登录系统")
62
           reject("请先登录系统")
53
           return undefined
63
           return undefined
54
         }
64
         }