<template>
  <div>{{ dateYear }} {{ dateWeek }} {{ dateDay }}</div>
</template>

<script>
import { formatTime } from '../utils/index.js'
export default {
  data() {
    return {
      timing: null,
      timing2: null,
      dateDay: null,
      dateYear: null,
      dateWeek: null,
      weekday: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
      pollingTime: 60000 * window.Glod.pollingMinute // 轮询毫秒数
    }
  },
  mounted() {
    this.timeFn()
    this.loadData()
  },
  beforeDestroy() {
    clearInterval(this.timing)
    clearInterval(this.timing2)
  },
  methods: {
    timeFn() {
      this.timing = setInterval(() => {
        this.dateDay = formatTime(new Date(), 'HH: mm: ss')
        this.dateYear = formatTime(new Date(), 'yyyy-MM-dd')
        this.dateWeek = this.weekday[new Date().getDay()]
      }, 1000)
    },
    loadData() {
      this.timing2 = setInterval(() => {
        this.$parent.getTableData()
      }, this.pollingTime)
    }
  }
}
</script>
