show-time.vue 1.8 KB
<template>
  <view class="rectangle">
    <view class="time">{{activeTime}}</view>
    <view class="date">
      <view class="date-left">
        <text>{{date}}</text><text>{{year}}</text>
      </view>
      <view class="vertical-line"></view>
      <view class="day">{{weekDay}}</view>
    </view>
  </view>
</template>

<script>
  import dayjs from 'dayjs'
  export default {
    data() {
      return {
        activeTime: '',
        timer: null,
        year: '',
        date: '',
        weekDay: ''
      }
    },
    methods: {},
    mounted() {
      // HH 是12小时制  hh是24小时制
      this.activeTime = dayjs(new Date()).format('HH:mm:ss')
      this.timer = setInterval(() => {
        this.activeTime = dayjs(new Date()).format('HH:mm:ss')
      }, 1000)
      this.year = dayjs(new Date()).format('YYYY')
      this.date = dayjs(new Date()).format('MM/DD')
      let weeks = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
      let day = new Date().getDay()
      this.weekDay = weeks[day]
    },
    beforeDestroy() {
      clearInterval(this.timer)
    }
  }
</script>

<style lang="scss">
  .rectangle {
    @include flexCj();
    margin-top: 14rpx;
    width: 702rpx;
    height: 108rpx;
    padding: 0 28rpx;
    box-sizing: border-box;
    background: url('/static/rectangle.png') no-repeat;
    background-size: contain;

    .time {
      font-size: 40rpx;
      font-weight: bold;
    }

    .date {
      @include flexcenter();

      .date-left {
        @include flexColumn();
        font-size: 32rpx;
        font-weight: bold;
      }

      .vertical-line {
        width: 2rpx;
        height: 60rpx;
        background-color: #858180;
        margin: 0 14rpx 0 16rpx;
      }

      .day {
        width: 32rpx;
        font-size: 28rpx;
      }
    }
  }
</style>