diff --git a/src/utils/request.js b/src/utils/request.js index 19eab38c..0e2947fd 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -1,10 +1,12 @@ import axios from 'axios' import Cookies from 'js-cookie' import router from '@/router' +import Vue from 'vue' import qs from 'qs' import { clearLoginInfo } from '@/utils' import isPlainObject from 'lodash/isPlainObject' +var lastTime = null // 最后一次点击的时间 const http = axios.create({ baseURL: window.SITE_CONFIG['apiURL'], timeout: 1000 * 180, @@ -15,6 +17,18 @@ const http = axios.create({ * 请求拦截 */ http.interceptors.request.use(config => { + if (lastTime) { + if (new Date().getTime() - lastTime > (30 * 60 * 1000)) { + Vue.prototype.$alert('停留时间过长', '请重新登录', { + confirmButtonText: '确定', + callback: action => { + clearLoginInfo() + router.replace({ name: 'login' }) + } + }) + } + } + lastTime = new Date().getTime() config.headers['Accept-Language'] = Cookies.get('language') || 'zh-CN' config.headers['token'] = Cookies.get('token') || '' // 默认参数