无操作退出

// 引入路由和storage工具函数
import storage from '@/utils/storage'
import router from "@/router/index"
import store from '@/store'


let lastTime = new Date().getTime()
let currentTime = new Date().getTime()
let timeOut = 2* 60 * 1000 //设置超时时间: 5分钟

window.onload = function () {
    window.document.onmousedown = function () {
        store.commit("gigi/set_lasttime",new Date().getTime())
    }
};

function checkTimeout() {
    console.log("开始检查")
    currentTime = new Date().getTime()    //更新当前时间
    lastTime = store.state.gigi.lasttime

    if (currentTime - lastTime > timeOut) { //判断是否超时
        console.log(currentTime);
        console.log(lastTime);
        console.log("已超时")
        // 清除storage的数据(登陆信息和token)
        // 退出应用
        wx.closeWindow()

    //
    }else{
        console.log("未超时")
    }
}

export default function () {
    /* 定时器 间隔30秒检测是否长时间未操作页面 */
    window.setInterval(checkTimeout, 30000);
}

main.js

 

import Astrict from '@/utils/astrict'
Vue.use(Astrict)

 

posted @ 2022-12-07 18:23  820820820  阅读(30)  评论(0)    收藏  举报