flat: 添加30分钟退出功能
This commit is contained in:
@@ -5,6 +5,7 @@ import './styles/common.scss';
|
|||||||
import './util/directive';
|
import './util/directive';
|
||||||
import '@smallwei/avue/lib/index.css';
|
import '@smallwei/avue/lib/index.css';
|
||||||
import 'element-ui/lib/theme-chalk/display.css';
|
import 'element-ui/lib/theme-chalk/display.css';
|
||||||
|
import './util/backTime'
|
||||||
|
|
||||||
import * as urls from '@/config/env';
|
import * as urls from '@/config/env';
|
||||||
import {iconfontUrl, iconfontVersion} from '@/config/env';
|
import {iconfontUrl, iconfontVersion} from '@/config/env';
|
||||||
|
|||||||
@@ -60,8 +60,12 @@ axios.interceptors.response.use(
|
|||||||
//如果在白名单里则自行catch逻辑处理
|
//如果在白名单里则自行catch逻辑处理
|
||||||
if (statusWhiteList.includes(status)) return Promise.reject(res);
|
if (statusWhiteList.includes(status)) return Promise.reject(res);
|
||||||
//如果是401则跳转到登录页面
|
//如果是401则跳转到登录页面
|
||||||
if (status === 401)
|
if (status === 401) {
|
||||||
store.dispatch('FedLogOut').then(() => router.push({path: '/login'}));
|
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统一处理
|
// 如果请求为500统一处理
|
||||||
const err = new Error(message)
|
const err = new Error(message)
|
||||||
err.response = res
|
err.response = res
|
||||||
|
|||||||
30
src/util/backTime.js
Normal file
30
src/util/backTime.js
Normal file
@@ -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"});
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user