show-time.vue
1.8 KB
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
<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>