소스 검색

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

萤火科技 1 년 전
부모
커밋
520a74d897
4개의 변경된 파일과 24개의 추가작업 그리고 26개의 파일을 삭제
  1. 2 2
      src/config/router.config.js
  2. 3 1
      src/main.js
  3. 9 9
      src/permission.js
  4. 10 14
      src/utils/request.js

+ 2 - 2
src/config/router.config.js

@@ -677,14 +677,14 @@ export const constantRouterMap = [
 
   // 用户登录页
   {
+    name: 'login',
     path: '/passport',
     component: UserLayout,
     redirect: '/passport/login',
     hidden: true,
     children: [
       {
-        path: 'login',
-        name: 'login',
+        path: '/passport/login',
         component: () => import(/* webpackChunkName: "passport" */ '@/views/passport/Login')
       }
     ]

+ 3 - 1
src/main.js

@@ -28,10 +28,12 @@ Vue.component('page-header-wrapper', PageHeaderWrapper)
 window.umi_plugin_ant_themeVar = themePluginConfig.theme
 
 
-new Vue({
+const vue = new Vue({
   router,
   store,
   i18n,
   created: bootstrap,
   render: h => h(App)
 }).$mount('#app')
+
+export default vue

+ 9 - 9
src/permission.js

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

+ 10 - 14
src/utils/request.js

@@ -6,6 +6,7 @@ import message from 'ant-design-vue/es/message'
 import { VueAxios } from './axios'
 import { isObject } from './util'
 import { ACCESS_TOKEN } from '@/store/mutation-types'
+// import Vue from '../main'
 
 // 站点配置文件
 // window.publicConfig => public/config.js
@@ -32,9 +33,6 @@ service.interceptors.request.use(config => {
   return config
 })
 
-// 是否显示未登录提示
-let notLoggedMessage = false
-
 // 接口响应拦截
 service.interceptors.response.use((response) => {
   const result = response.data
@@ -50,18 +48,16 @@ service.interceptors.response.use((response) => {
   }
   // 鉴权失败: 未登录
   if (result.status === 401) {
-    if (!notLoggedMessage) {
-      notLoggedMessage = true
-      store.dispatch('Logout').then(() => {
-        notification.error({
-          key: 'notLoggedMessage',
-          message: '错误',
-          description: result.message,
-          duration: 3
-        })
-        setTimeout(() => window.location.reload(), 1500)
+    store.dispatch('Logout').then(() => {
+      notification.error({
+        key: 'notLoggedMessage',
+        message: '错误',
+        description: result.message,
+        duration: 3
       })
-    }
+      // Vue.$router.push({ path: '/passport/login' }) // 会报错重复注册路由, 改用下面reload的方式
+      setTimeout(() => window.location.reload(), 1500)
+    })
     return Promise.reject(result)
   }
   return result