From 00740699c2836b3cff9fec4f1a69751a2ec73a5c Mon Sep 17 00:00:00 2001 From: zhaoyongnian <541231643@qq.com> Date: Mon, 21 Nov 2022 16:25:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=81=9C=E7=95=99=E6=97=B6=E9=97=B4=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/request.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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') || '' // 默认参数