<template>
  <div></div>
</template>

<script>
export default {
  name: 'Back',
  data () {
    return {
      lockTime: this.$store.getters.lockTime,
      timeOut: null,
      actions: ['mouseup', 'mousemove', 'keyup', 'click', 'touchend']
    }
  },
  mounted () {
    if (Number(this.lockTime) !== 0) {
      this.isTimeOut()
    }
  },
  methods: {
    startTimer () {
      // console.log('8')
      clearInterval(this.timeOut)
      this.timeOut = setInterval(() => {
        this.$router.push({path: '/'})
        // console.log('time', 1000 * 6 * this.lockTime)
      }, 1000 * 60 * this.lockTime)
    },
    isTimeOut () {
      this.startTimer()
      this.actions.forEach(item => {
        document.body.addEventListener(item, this.startTimer)
      })
    }
  },
  beforeDestroy () {
    this.actions.forEach(item => {
      // console.log(item)
      document.body.removeEventListener(item, this.startTimer)
    })
    clearInterval(this.timeOut)
    this.timeOut = null
  }
}
</script>
