<template>
  <div class="layouts">
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  data() {
    return {};
  },
  created() {
    this.isTimeOut();
  },
  methods: {
    // 返回首页
    startTimer() {
      let that = this;
      clearInterval(that.timeOut);
      this.timeOut = setTimeout(function () {
        that.$router.push({ path: "/" });
      }, 1000 * 60 * 2);
    },
    // 无任何操作返回首页
    isTimeOut() {
      if (this.$route.path == "/" || this.$route.path == "/home") {
        return;
      }
      this.startTimer();
      document.body.addEventListener("mousemove", this.startTimer);
      document.body.addEventListener("mouseup", this.startTimer);
      document.body.addEventListener("keyup", this.startTimer);
      document.body.addEventListener("click", this.startTimer);
      document.body.addEventListener("touchend", this.startTimer);
    },
  },
  beforeDestroy() {
    document.body.removeEventListener("mousemove", this.startTimer);
    document.body.removeEventListener("mouseup", this.startTimer);
    document.body.removeEventListener("keyup", this.startTimer);
    document.body.removeEventListener("click", this.startTimer);
    document.body.removeEventListener("touchend", this.startTimer);
    clearTimeout(this.timeOut);
  },
};
</script>

<style lang="less">
.layouts {
  width: 100%;
  height: 100%;
}
</style>
