From c8390037155bb1ad5a66138a450786ff7bb0e9d8 Mon Sep 17 00:00:00 2001 From: Apcallover <1503963513@qq.com> Date: Fri, 10 May 2024 16:45:20 +0800 Subject: [PATCH] =?UTF-8?q?flat:=20=E6=B7=BB=E5=8A=A030=E5=88=86=E9=92=9F?= =?UTF-8?q?=E9=80=80=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 1 + src/router/axios.js | 8 ++++++-- src/util/backTime.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/util/backTime.js diff --git a/src/main.js b/src/main.js index 67e16db..c73f3f7 100644 --- a/src/main.js +++ b/src/main.js @@ -5,6 +5,7 @@ import './styles/common.scss'; import './util/directive'; import '@smallwei/avue/lib/index.css'; import 'element-ui/lib/theme-chalk/display.css'; +import './util/backTime' import * as urls from '@/config/env'; import {iconfontUrl, iconfontVersion} from '@/config/env'; diff --git a/src/router/axios.js b/src/router/axios.js index ba6ae22..05dacd5 100644 --- a/src/router/axios.js +++ b/src/router/axios.js @@ -60,8 +60,12 @@ axios.interceptors.response.use( //如果在白名单里则自行catch逻辑处理 if (statusWhiteList.includes(status)) return Promise.reject(res); //如果是401则跳转到登录页面 - if (status === 401) - store.dispatch('FedLogOut').then(() => router.push({path: '/login'})); + if (status === 401) { + store.dispatch('FedLogOut').then(() => { + window.location.href = 'http://10.160.7.216:9920/casserver/login?service=http://10.165.0.77/manage/login&stService=http%3A%2F%2F10.165.0.77%2Fmanage%2Flogin' + }); + // store.dispatch('FedLogOut').then(() => router.push({path: '/login'})); + } // 如果请求为500统一处理 const err = new Error(message) err.response = res diff --git a/src/util/backTime.js b/src/util/backTime.js new file mode 100644 index 0000000..9c52352 --- /dev/null +++ b/src/util/backTime.js @@ -0,0 +1,30 @@ +const MAX_IDLE_TIME = 30 * 60 * 1000; +let lastActionTime = new Date(); +import store from "@/store"; +import router from "@/router/router"; + +function updateLastActionTime() { + lastActionTime = new Date(); +} + +// 定义一个计时器 +let timeoutId = setTimeout(() => { + console.log('用户已经很长时间没有操作了!'); + backLogOut() +}, MAX_IDLE_TIME); + +// 监听页面上任何一个元素的点击事件 +document.addEventListener('click', () => { + updateLastActionTime(); + clearTimeout(timeoutId); + timeoutId = setTimeout(() => { + console.log('用户已经很长时间没有操作了!'); + backLogOut() + }, MAX_IDLE_TIME); +}); + +function backLogOut() { + store.dispatch("LogOut").then(() => { + router.push({path: "/login"}); + }); +}