mo 2 years ago
parent
commit
29d215afa3
2 changed files with 8 additions and 6 deletions
  1. 1 0
      src/store/modules/user.js
  2. 7 6
      src/utils/request.js

+ 1 - 0
src/store/modules/user.js

@@ -82,6 +82,7 @@ const user = {
     FedLogOut({ commit }) {
       return new Promise(resolve => {
         commit('SET_TOKEN', '')
+        commit('SET_ROLES', [])
         removeToken()
         resolve()
       })

+ 7 - 6
src/utils/request.js

@@ -4,6 +4,7 @@ import store from '../store'
 import { getToken } from '@/utils/auth'
 import cleanDeep from 'clean-deep'
 import qs from 'qs'
+import router from '../router'
 
 // 创建axios实例
 const service = axios.create({
@@ -45,7 +46,7 @@ service.interceptors.request.use(config => {
 
 // respone拦截器
 service.interceptors.response.use(
-  response => {
+async  response => {
   /**
   * code为非200是抛错 可结合自己业务进行修改
   */
@@ -60,17 +61,17 @@ service.interceptors.response.use(
 
       // 401:未登录;
       if (res.code === 401 || res.code === 403) {
-        location.reload()
+        // 清理缓存 跳到登录页面
+               await  store.dispatch('FedLogOut')
+               location.reload()
+
         // location = window.location.origin;
         // MessageBox.confirm('登录过期请重新登录', '确定登出', {
         //   confirmButtonText: '重新登录',
         //   cancelButtonText: '取消',
         //   type: 'warning'
         // }).then(() => {
-        //   store.dispatch('FedLogOut').then(() => {
-        //      location.reload()// 为了重新实例化vue-router对象 避免bug
-        //     location.href = window.location.hostname;
-        //   })
+
 
         // })
       }