uni-countdown 倒计时 - DCloud 插件市场 倒计时
<uni-count-down
:day="currentTime.d"
:hour="currentTime.h"
:minute="currentTime.i"
:second="currentTime.s"
color="#FA5B14"
splitorColor="#FF4644"
/>
data(){
return{
Countdown: '',
currentTime: '',
noStartTime: '',
timestamp: '',
xxx: '',
}
},
countDown(seconds) {
let [day, hour, minute, second] = [0, 0, 0, 0]
if (seconds > 0) {
day = Math.floor(seconds / (60 * 60 * 24))
hour = Math.floor(seconds / (60 * 60)) - (day * 24)
minute = Math.floor(seconds / 60) - (day * 24 * 60) - (hour * 60)
second = Math.floor(seconds) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60)
}
if (day < 10) {
day = '0' + day
}
if (hour < 10) {
hour = '0' + hour
}
if (minute < 10) {
minute = '0' + minute
}
if (second < 10) {
second = '0' + second
}
return {
d: day,
h: hour,
i: minute,
s: second
};
},
daojishi(end_time, start_time, timestamp) {
let res = this.$util.countDown(end_time - start_time);
if (res.d <= 0 && res.h <= 0 && res.i <= 0 && res.s <= 0) {
return
}
this.currentTime = this.countDown(end_time - timestamp);
this.noStartTime = this.countDown(start_time - timestamp);
this.Countdown = res.d + "天" + res.h + "小时" + res.i + "分钟" + res.s + "秒";
},
this.$api.sendRequest({
url: 'url ',
data: {},
success: res => {
if (res.code >= 0) {
this.xxxx = res.data;
this.daojishi(res.data.end_time, res.data.start_time, res.timestamp);
}
}
})