指定时间页面没操作跳转页面
this.app = new Vue({
el: '#app',
data () {
return {
count: 0,
outTime: 0
}
},
async created() {
let timeData = await api.call('BackendServer', 'get_config', 'time')
this.outTime = Number(timeData.go_screen_save_time)
},
async mounted() {
this.isTimeOut()
},
beforeDestroy() {
if (this.timeOut) {
clearInterval(this.timeOut)
}
},
methods: {
async startTimer() {
let self = this
self.count = 0
self.myStopTime()
self.timeOut = setInterval(self.go, 1000)
},
async go() {
let self = this
self.count++
if (self.count === self.outTime * 60) {
执行代码(比如跳转页面)
}
},
isTimeOut() {
let self = this
if (self.currentPage === 'Login') {
self.startTimer()
}
document.body.onmouseup = self.startTimer
document.body.onmousemove = self.startTimer
document.body.onclick = self.startTimer
document.body.ontouchend = self.startTimer
document.body.onkeyup = self.startTimer
document.body.onkeydown = self.startTimer
document.body.onkeypress = self.startTimer
},
myStopTime() {
if (this.timeOut) {
clearInterval(this.timeOut)
}
},
}
})
网友评论