前言
以uniapp项目为例
解决思路:
1、增加全局触屏事件
2、配置页面静默最大时长
3、增加定时器记录静默时长,采取递减模式,当时长为0时,清除定时器并返回主页
4、这里注意如果是用户主动操作页面跳转也需要清除定时器
具体实现
1. 增加全局触屏事件
touchScreen()
touchScreen(){
console.log("触摸事件");
this.count=config.pageTimeOut;
},
2. 配置页面静默最大时长
3. 增加定时器记录静默时长
onReady() {
//启动定时任务
var that=this;
that.timer=setInterval(function(){
console.log(that.count)
if(that.count==0){
clearInterval(that.timer);
//返回主页
that.home();
return
}
that.count=that.count-1;
},config.pageTimeOut*60000);
},