超时登出
var lastTime = new Date().getTime();
var currentTime = new Date().getTime();
var timeOut = 20 * 60 * 1000;
window.onload = function () {
window.document.onmousedown = function () {
localStorage.setItem("lastTime",new Date().getTime());
}
};
function checkTimeout() {
currentTime = new Date().getTime();
lastTime = localStorage.getItem("lastTime");
console.log(currentTime - lastTime);
console.log(timeOut);
if (currentTime - lastTime > timeOut) {
var url = window.location.href;
var newUrl=url.match(/(\S*)#/)[1];
console.log("超时登出啦!!!!")
window.open(newUrl + '#/login','_self');
}
}
window.setInterval(checkTimeout, 30000);
然后在main.js中引入