<template>
<div id="app">
<router-view />
</div>
</template>
<script>
export default {
name: "App",
data() {
return {
timer: null,
};
},
mounted() {
this.clearTimer();
this.startTimer();
},
beforeDestroy() {
this.clearTimer();
},
methods: {
startTimer() {
this.timer = setTimeout(() => {
this.logout();
}, 120 * 60 * 1000);
},
clearTimer() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
},
resetTimer() {
this.clearTimer();
this.startTimer();
},
async logout() {
await this.$store.dispatch("user/logout");
this.$router.push(`/login?redirect=${this.$route.fullPath}`);
},
handleClick() {
this.resetTimer();
},
handleKeyDown() {
this.resetTimer();
},
},
mounted() {
document.addEventListener("click", this.handleClick);
},
beforeDestroy() {
document.removeEventListener("click", this.handleClick);
},
};
</script>