<template>
  <div class="page">
    <div class="head" @click="goIndex">
      <div class="text_left">
        <span>2023-08-01</span>
        <span>17:18:29</span>
        <span>星期三</span>
      </div>
      <div class="text_right">
        <span>刷新时间：{{ countDown }}s</span>
      </div>
    </div>
    <router-view style="height: 90%" v-if="isRouterAlive"></router-view>
  </div>
</template>

<script>
import axios from "axios";
window.axios = axios
window.$ = window.jQuery = require('materialize-css/node_modules/jquery/dist/jquery.js')
require('materialize-css')
export default {
  name: 'app',
  data() {
    return {
      countDown: 10,
      isRouterAlive: true,
      countDownTimer: null,
    }
  },
  methods: {
    goIndex() {
      this.$router.push({path: '/'})
    },
    reload() {
      this.isRouterAlive = false
      this.$nextTick(function () {
        this.isRouterAlive = true
      })
    }
  },
  mounted() {
    // 倒计时器
    this.countDownTimer = setInterval(() => {
      this.countDown--
      if (this.countDown <= 0) {
        this.reload()
        this.countDown = 10
      }
    }, 1000)
  },
  beforeDestroy() {
    // 倒计时器
    if (this.countDownTimer) {
      clearInterval(this.countDownTimer)
    }
  }
}
</script>

<style>
@import "../../../node_modules/materialize-css/bin/materialize.css";

#app {
}

@media only screen and (max-width: 992px) {
  header, main, footer {
    padding-left: 0;
  }
}
</style>
