<template>
  <Header>
    <dv-decoration-8 class="left" />
    <dv-decoration-5 class="center" />
    <dv-decoration-8 class="right" :reverse="true" />
    <div class="centerTitle">{{$route.meta.title}}</div>
    <dv-decoration-7 class="dateBox"><span>{{ curTime }}</span></dv-decoration-7>
  </Header>
</template>

<script>
import dayjs from 'dayjs';
export default {
  data() {
    return {
      curTime: '',
      dayOfWeekText: '',
    };
  },
  methods: {
    // 获取星期
    getWeek() {
      const dayOfWeek = dayjs().day();
      switch (dayOfWeek) {
        case 0:
          this.dayOfWeekText = '星期日';
          break;
        case 1:
          this.dayOfWeekText = '星期一';
          break;
        case 2:
          this.dayOfWeekText = '星期二';
          break;
        case 3:
          this.dayOfWeekText = '星期三';
          break;
        case 4:
          this.dayOfWeekText = '星期四';
          break;
        case 5:
          this.dayOfWeekText = '星期五';
          break;
        case 6:
          this.dayOfWeekText = '星期六';
          break;
      }
    },
    // 更新当前时间
    updateTime() {
      this.curTime = dayjs().format(`YYYY-MM-DD HH:mm:ss ${this.dayOfWeekText}`);
    },
  },
  created() {
    this.getWeek();
    this.updateTime();
    this.timer = setInterval(this.updateTime, 1000);
  },
  beforeDestroy() {
    clearInterval(this.timer);
  },
};
</script>

<style lang="scss" scoped>
Header {
  display: flex;
  justify-content: space-between;
  flex-shrink: 0;
  height: 100px;
  position: relative;
  .left {
    width: 25%;
    height: 60px;
  }
  .center {
    width: 40%;
    height: 60px;
    margin-top: 30px;
  }
  .right {
    width: 25%;
    height: 60px;
  }
  .centerTitle {
    position: absolute;
    font-size: 30px;
    font-weight: 700;
    left: 50%;
    top: 15px;
    transform: translateX(-50%);
  }
  .dateBox {
    position: absolute;
    width: 18%;
    height: 60px;
    font-size: 16px;
    font-weight: 700;
    right: 9%;
    top: 27px;
    span{
      margin: 0 8px;
    }
  }
}
</style>
