yangfeng
2023-12-21 90020572d7922536f94df74bcee1ccc3393dd097
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<template>
  <div class="time-weather">
    <div class="weather">
      <div class="left">5℃</div>
      <div class="icon-view">
        <i class="el-icon-sunny"></i>
      </div>
      <div class="text-view">
        <div>晴转多云</div>
        <div>Beijing</div>
      </div>
    </div>
    <div class="divider-view">
      <el-divider direction="vertical"></el-divider>
    </div>
    <div class="timer">
      <div>{{ nowTime }}</div>
    </div>
    <div class="date">
      <div>{{ nowWeek }}</div>
      <div>{{ nowDate }}</div>
    </div>
  </div>
</template>
 
<script>
export default {
  components: {},
  props: {
    totalObject: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      nowTime: "", // 时间
      nowDate: "", // 日期
      nowWeek: "", // 星期
      timer: null,
    };
  },
  mounted() {
    this.getNowTime();
  },
  watch: {},
  beforeDestroy() {
    clearInterval(this.timer);
    this.timer = null;
  },
  methods: {
    // 获取当前日期时间
    getNowTime() {
      let speed = 1000;
      let that = this;
      let theNowTime = function () {
        that.timeNumber();
      };
      this.timer = setInterval(theNowTime, speed);
    },
    timeNumber() {
      let today = new Date();
      this.nowDate =
        today.getFullYear() +
        "-" +
        this.twoDigits(today.getMonth() + 1) +
        "-" +
        this.twoDigits(today.getDate());
      this.nowTime =
        this.twoDigits(today.getHours()) +
        ":" +
        this.twoDigits(today.getMinutes()) +
        ":" +
        this.twoDigits(today.getSeconds());
      let week = new Date().getDay();
      let weeks = [
        "Sunday",
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
      ];
 
      this.nowWeek = weeks[week];
    },
    twoDigits(val) {
      if (val < 10) return "0" + val;
      return val;
    },
  },
};
</script>
 
<style scoped lang="scss">
.time-weather {
  width: 100%;
  height: 100%;
  color: #1dd4ff;
  background: rgba(3, 10, 14, 0.9);
  display: flex;
  align-items: center;
  .weather {
    width: 33%;
    display: flex;
    align-items: center;
    .left {
      font-size: 28px;
    }
    .icon-view {
      font-size: 26px;
      margin-left: 6px;
    }
    .text-view {
      font-size: 12px;
      margin-left: 6px;
      color: #127c97;
    }
  }
  .timer {
    width: 33%;
    font-size: 28px;
    display: flex;
    justify-content: center;
  }
  .date {
    font-size: 12px;
    margin-left: 6px;
    color: #127c97;
  }
}
.divider-view {
  height: 100%;
  display: flex;
  align-items: center;
  .el-divider {
    background-color: #1dd4ff;
    height: calc(100% - 20px);
  }
}
</style>