Преглед изворни кода

修复:后台登录态失效时login页面刷新问题

萤火科技 пре 1 година
родитељ
комит
71cc5b58f4
3 измењених фајлова са 16 додато и 19 уклоњено
  1. 3 8
      src/config/router.config.js
  2. 9 8
      src/permission.js
  3. 4 3
      src/utils/request.js

+ 3 - 8
src/config/router.config.js

@@ -72,12 +72,7 @@ export const asyncRouterMap = [
             path: '/setting/timer',
             component: () => import(/* webpackChunkName: "setting" */ '@/views/setting/timer'),
             meta: { title: '定时任务', keepAlive: false, permission: ['setting'] }
-          },
-          // {
-          //   path: '/setting/queue',
-          //   component: () => import(/* webpackChunkName: "setting" */ '@/views/setting/queue'),
-          //   meta: { title: '队列服务', keepAlive: false, permission: ['setting'] }
-          // },
+          }
         ]
       },
 
@@ -111,14 +106,14 @@ export const asyncRouterMap = [
  */
 export const constantRouterMap = [
   {
+    name: 'login',
     path: '/user',
     component: UserLayout,
     redirect: '/user/login',
     hidden: true,
     children: [
       {
-        // name: 'Login',
-        path: 'login',
+        path: '/user/login',
         meta: { title: '超级管理后台' },
         component: () => import(/* webpackChunkName: "user" */ '@/views/user/Login')
       }

+ 9 - 8
src/permission.js

@@ -47,14 +47,15 @@ router.beforeEach((to, from, next) => {
               }
             })
           })
-          .catch(() => {
-            notification.error({
-              message: '错误',
-              description: '请求用户信息失败,请重试'
-            })
-            store.dispatch('Logout').then(() => {
-              next({ path: '/user/login', query: { redirect: to.fullPath } })
-            })
+          .catch(err => {
+            // notification.error({
+            //   message: '错误',
+            //   description: '请求用户信息失败,请重试'
+            // })
+            // // 失败时,获取用户信息失败时,调用登出,来清空历史保留信息
+            // store.dispatch('Logout').then(() => {
+            //   next({ path: loginRoutePath, query: { redirect: to.fullPath } })
+            // })
           })
       }
       next()

+ 4 - 3
src/utils/request.js

@@ -5,6 +5,7 @@ import notification from 'ant-design-vue/es/notification'
 import message from 'ant-design-vue/es/message'
 import { VueAxios } from './axios'
 import { ACCESS_TOKEN } from '@/store/mutation-types'
+// import Vue from '../main'
 
 // 站点配置文件
 // window.serverConfig => public/config.js
@@ -44,13 +45,13 @@ service.interceptors.response.use((response) => {
   if (result.status === 401) {
     store.dispatch('Logout').then(() => {
       notification.error({
+        key: 'notLoggedMessage',
         message: '错误',
         description: result.message,
         duration: 3
       })
-      setTimeout(() => {
-        window.location.reload()
-      }, 1200)
+      // Vue.$router.push({ path: '/passport/login' }) // 会报错重复注册路由, 改用下面reload的方式
+      setTimeout(() => window.location.reload(), 1500)
     })
     return Promise.reject(result)
   }