mali-applet-ui 1.1.70 → 1.1.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="ml-countdown">
|
|
3
|
+
<slot name="prefix">
|
|
4
|
+
<view v-if="prefixText" class="ml-countdown-prefix">{{ prefixText || '' }}</view>
|
|
5
|
+
</slot>
|
|
6
|
+
<slot :secondVals="secondVals" :currVals="currVals" :timeDiffObj="timeDiffObj" :timeFormats="timeFormats" :timeLabels="timeLabels">
|
|
7
|
+
<view class="ml-countdown-item" :class="[`time-${type}`]" v-for="(type) in timeFormats" :key="type">
|
|
8
|
+
<text class="ml-countdown-time-num">{{ timeDiffObj[type] || 0 }}</text>
|
|
9
|
+
<text class="ml-countdown-time-label">{{ timeLabels[type] || '' }}</text>
|
|
10
|
+
</view>
|
|
11
|
+
</slot>
|
|
12
|
+
<slot name="suffix">
|
|
13
|
+
<view v-if="suffixText" class="ml-countdown-suffix">{{ suffixText || '' }}</view>
|
|
14
|
+
</slot>
|
|
15
|
+
</view>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script>
|
|
19
|
+
import XEUtils from 'xe-utils'
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
name: 'MlCountdown',
|
|
23
|
+
props: {
|
|
24
|
+
value: [Number, String],
|
|
25
|
+
formats: Array,
|
|
26
|
+
prefixText: String,
|
|
27
|
+
suffixText: String
|
|
28
|
+
},
|
|
29
|
+
data () {
|
|
30
|
+
return {
|
|
31
|
+
secondVals: 0,
|
|
32
|
+
currVals: 0,
|
|
33
|
+
timeLabels: {
|
|
34
|
+
yyyy: '年',
|
|
35
|
+
MM: '月',
|
|
36
|
+
dd: '天',
|
|
37
|
+
HH: '时',
|
|
38
|
+
mm: '分',
|
|
39
|
+
ss: '秒'
|
|
40
|
+
},
|
|
41
|
+
htime: null
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
computed: {
|
|
45
|
+
timeDiffObj () {
|
|
46
|
+
return XEUtils.getDateDiff(Date.now(), Date.now() + this.currVals)
|
|
47
|
+
},
|
|
48
|
+
timeFormats () {
|
|
49
|
+
if (this.formats && this.formats.length) {
|
|
50
|
+
return this.formats
|
|
51
|
+
}
|
|
52
|
+
if (this.secondVals >= 31622400000) {
|
|
53
|
+
return ['yyyy', 'MM', 'dd', 'HH', 'mm', 'ss']
|
|
54
|
+
}
|
|
55
|
+
if (this.secondVals >= 2678400000) {
|
|
56
|
+
return ['MM', 'dd', 'HH', 'mm', 'ss']
|
|
57
|
+
}
|
|
58
|
+
if (this.secondVals >= 86400000) {
|
|
59
|
+
return ['dd', 'HH', 'mm', 'ss']
|
|
60
|
+
}
|
|
61
|
+
return ['HH', 'mm', 'ss']
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
watch: {
|
|
65
|
+
value () {
|
|
66
|
+
this.updateVal()
|
|
67
|
+
this.stop()
|
|
68
|
+
this.start()
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
created () {
|
|
72
|
+
this.updateVal()
|
|
73
|
+
this.start()
|
|
74
|
+
},
|
|
75
|
+
beforeDestroy () {
|
|
76
|
+
this.stop()
|
|
77
|
+
},
|
|
78
|
+
methods: {
|
|
79
|
+
updateVal () {
|
|
80
|
+
this.secondVals = XEUtils.toNumber(this.value || 0)
|
|
81
|
+
this.currVals = this.secondVals
|
|
82
|
+
},
|
|
83
|
+
handleTime () {
|
|
84
|
+
if (this.currVals > 1000) {
|
|
85
|
+
this.currVals -= 1000
|
|
86
|
+
this.htime = setTimeout(this.handleTime, 1000)
|
|
87
|
+
} else {
|
|
88
|
+
this.currVals = 0
|
|
89
|
+
this.stop()
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
start () {
|
|
93
|
+
this.$emit('start', {})
|
|
94
|
+
this.handleTime()
|
|
95
|
+
},
|
|
96
|
+
stop () {
|
|
97
|
+
if (this.htime != null) {
|
|
98
|
+
this.$emit('stop', {})
|
|
99
|
+
clearTimeout(this.htime)
|
|
100
|
+
this.htime = null
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
</script>
|
|
106
|
+
|
|
107
|
+
<style lang="scss">
|
|
108
|
+
.ml-countdown {
|
|
109
|
+
padding: 0 16rpx;
|
|
110
|
+
.ml-countdown-prefix {
|
|
111
|
+
display: inline-block;
|
|
112
|
+
padding-right: 16rpx;
|
|
113
|
+
}
|
|
114
|
+
.ml-countdown-item {
|
|
115
|
+
display: inline-block;
|
|
116
|
+
}
|
|
117
|
+
.ml-countdown-suffix {
|
|
118
|
+
display: inline-block;
|
|
119
|
+
padding-left: 16rpx;
|
|
120
|
+
}
|
|
121
|
+
.ml-countdown-time-num {
|
|
122
|
+
color: $ml-theme-primary-color;
|
|
123
|
+
padding: 0 8rpx;
|
|
124
|
+
font-size: 1.6em;
|
|
125
|
+
}
|
|
126
|
+
.ml-countdown-time-label {
|
|
127
|
+
padding: 0 8rpx;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
</style>
|