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"}); + }); +}