91 lines
2.2 KiB
Vue
91 lines
2.2 KiB
Vue
<template>
|
|
<div id="app" @click="getLastTime">
|
|
<router-view/>
|
|
</div>
|
|
</template>
|
|
<script>
|
|
import { mapState } from 'vuex'
|
|
export default {
|
|
name: 'App',
|
|
data(){
|
|
return {
|
|
routeName: null,
|
|
lastTime:localStorage.getItem("lastTime"),
|
|
currentTime: new Date().getTime(),
|
|
timeOut :5*60*1000 //设置超时时间: 5分
|
|
}
|
|
},
|
|
|
|
mounted: function() {
|
|
var _this=this;
|
|
clearInterval(window['checkLoginTime']);
|
|
setTimeout(function(){
|
|
|
|
if(_this.routeName!="login"&&_this.webconfig.isSetExpired&&_this.routeName!="play_tel"){
|
|
window['checkLoginTime']= window.setInterval(_this.checkTimeout, 10000);
|
|
}
|
|
},0)
|
|
|
|
|
|
|
|
},
|
|
methods: {
|
|
getLastTime:function(){
|
|
|
|
var _this=this;
|
|
if(_this.routeName!="login"&&_this.webconfig.isSetExpired&&_this.routeName!="play_tel"){
|
|
localStorage.setItem("lastTime", new Date().getTime());
|
|
/* 定时器 间隔30秒检测是否长时间未操作页面 */
|
|
clearInterval(window['checkLoginTime']);
|
|
window['checkLoginTime'] = window.setInterval(_this.checkTimeout, 10000);
|
|
// debugger;
|
|
}
|
|
},
|
|
checkTimeout() {
|
|
|
|
var _this=this;
|
|
_this.currentTime = new Date().getTime(); //更新当前时间
|
|
_this.lastTime = localStorage.getItem("lastTime");
|
|
if (Number(_this.currentTime) - Number(_this.lastTime) > _this.timeOut) { //判断是否超时
|
|
console.log("超时");
|
|
this.$message.error('长时间没操作,请重新登录!');
|
|
this.$cookies.remove('userInfo');
|
|
this.$router.push('/');
|
|
localStorage.removeItem('lastTime');
|
|
clearInterval(window['checkLoginTime']);
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
}
|
|
|
|
},
|
|
computed: {
|
|
...mapState(['webconfig'])
|
|
},
|
|
watch:{
|
|
|
|
$route:{
|
|
handler: function(newData){
|
|
var _this=this;
|
|
this.routeName=newData.name;
|
|
var table_id=0;
|
|
// 判断台名 传tab_id
|
|
if(newData.name=='play'){
|
|
table_id=parseInt(this.$route.query.table);
|
|
}else{
|
|
table_id=0;
|
|
}
|
|
this.$store.dispatch('updateKeepline',table_id);
|
|
},
|
|
immediate:true
|
|
},
|
|
}
|
|
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
|
|
</style>
|