思路:
页面在设定时间内无任何操作(鼠标的点击、滑动、路由的切换、是否请求接口等),跳转到登录页,在跳转前把url存起来,点击登录的时候用。
下面介绍其中的一种方法,鼠标的滑动时间:(用到base64加密)
<template>
<div id="app" @mouseover="OperatingWebsite()">
<router-view/>
</div>
</template>
<script>
export default {
data() {
return {
currentTime: new Date().getTime()
};
},
methods: {
OperatingWebsite() {
let currentTime = this.currentTime;
console.log(currentTime, "currentTime");
let lastTime = new Date().getTime();
console.log(lastTime, "lastTime");
let timeOut = 10 * 60 * 1000; //设置时间 10分钟
if (lastTime - currentTime > timeOut) {
// 未操作页面,跳转登录页面
this.currentTime = new Date().getTime();
const fullPath = this.$route.fullPath;
const query = this.$Base64.encode(fullPath);
this.$router.push({
path: "/user",
query: {
type: query
}
});
} else {
this.currentTime = new Date().getTime();
}
// const truthPathQuery = this.$route.query.type;
// const truthPath = this.$Base64.decode(truthPathQuery); //点击登录的时候跳转这个地址
}
}
};