<template>
<view @click="clickDiv">
</view>
</template>
<script>
export default {
data() {
return {
lastTime: null, // 最后一次点击的时间
currentTime: null, // 当前点击的时间
timeOut: 1 * 60 * 1000, // 设置超时时间:1分钟
timeInterval: "",
pageHide: 0, //页面切屏次数
cutScreenCounts: 5, //页面切屏最大次数
};
},
onHide() {
this.pageHide++;
// 达到切屏最大次数后执行一些操作
if (this.pageHide > this.cutScreenCounts) {
}
},
methods: {
clickDiv() {
if (this.timeInterval == "") {
// 5秒钟检测一次
this.timeInterval = setInterval(this.isTimeOut, 5000);
}
this.lastTime = new Date().getTime();
},
isTimeOut() {
this.currentTime = new Date().getTime(); // 当前时间
// 判断上次最后一次点击的时间和这次点击的时间间隔是否大于规定的时间
if (this.currentTime - this.lastTime > this.timeOut) {
//页面长时间没操作,要执行的一些操作
}
},
},
};
</script>
uniapp 检测页面长时间未操作、以及切屏次数达到一定次数后,执行一些方法。
最新推荐文章于 2024-04-26 15:15:34 发布