Quellcode durchsuchen

修改超时时间及及登录问题

zhangliang2 vor 2 Jahren
Ursprung
Commit
de00d863da
1 geänderte Dateien mit 13 neuen und 2 gelöschten Zeilen
  1. 13 2
      src/axios/filter.js

+ 13 - 2
src/axios/filter.js

@@ -2,6 +2,7 @@ import axios from 'axios'
 import VueAxios from 'vue-axios'
 import Vue from 'vue'
 import router from '../router'
+import store from '../store'
 import ElementUI, {
     Loading
 } from 'element-ui';
@@ -42,7 +43,7 @@ Vue.use(VueAxios, axios);
 axios.defaults.baseURL = ''; //项目的的基础url
 axios.defaults.headers.common['Authorization'] = ""; //请求token信息配置
 axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; //请求type设置
-axios.defaults.timeout = 1000 * 48; //在超时前,所有请求都会等待相应秒数
+axios.defaults.timeout = 1000 * 60; //在超时前,所有请求都会等待相应秒数
 axios.defaults.withCredentials = true;
 let isInvalid1 = false //用于控制登录信息过期后弹窗时间的截流,截流时间为5s
 let isInvalid2 = false
@@ -52,6 +53,16 @@ axios.interceptors.request.use(function (config) {
     // 在发送请求之前处理
     // 判断token在前台session中是否存在
     config.headers.common['Authorization'] = localStorage.getItem('Authorization');
+
+    // 解决同一个浏览器中登录多个账户时,账户页面刷新后,页面数据更新为最后一个登录的账户。
+    // console.log(store.state.username);
+    // console.log(localStorage.getItem('username'));
+    if (store.state.username &&
+        localStorage.getItem('username') &&
+        store.state.username != localStorage.getItem('username')) {
+        window.location.reload();
+    }
+
     if (config.noLoading === true) { //如果noLoading为true,不加载loading画面
         console.log("noLoading");
     } else {
@@ -116,7 +127,7 @@ const instance = axios.create({
 
 instance.defaults.headers.common['Authorization'] = ""; //请求token信息配置
 instance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; //请求type设置
-instance.defaults.timeout = 1000 * 60 * 3; //在超时前,所有请求都会等待
+instance.defaults.timeout = 1000 * 60 * 6; //在超时前,所有请求都会等待
 instance.defaults.withCredentials = true;
 
 instance.interceptors.request.use(function (config) {