vue 单页面设置锁屏自动唤起

锁屏状态用cookies存储(localStorage.getItem(),localStorage.setItem())
思路内容:

1.规定时间——需要定时器
 2.无操作——监控页面上的点击、触摸、滑动等事件
 3.返回首页——切换路由

进入页面时,开启定时器,当页面有点击、触摸、滑动等事件时重新设定定时器,时间一到自动唤起锁屏。

data:{
  return{
      timeout:''
  }
},
 created: function() {
             this.isTimeOut();
        },
methods:{
         //锁屏定时器
             startTimer() {
                 var that = this;
                 clearInterval(that.timeout);
                 that.timeout = setInterval(function() {
                     that.btnLockScreen();//打开锁屏
                 }, 1000 * 60 * 15)
             },
             //是否超时
             isTimeOut() {
                 var that = this;

                 //监听鼠标、键盘\点击\触屏
                 document.body.onmouseup = that.startTimer;
                 document.body.onmousemove = that.startTimer;
                 document.body.onkeyup = that.startTimer;
                 document.body.onclick = that.startTimer;
                 document.body.ontouchend = that.startTimer;
             }
}

参考网址:https://blog.csdn.net/weixin_30790841/article/details/95047908?utm_medium=distribute.pc_relevant.none-task-blog-OPENSEARCH-1.control&dist_request_id=88ab1254-96f5-42f3-a72f-24b3d8c41c1e&depth_1-utm_source=distribute.pc_relevant.none-task-blog-OPENSEARCH-1.control

你可能感兴趣的:(vue 单页面设置锁屏自动唤起)