- 将时间转化成时分秒
for (var s = 0; s < this.count_down_list.length; s++) {
if (this.count_down_list[s].time !== 0) {
this.live_day = Math.floor(
this.count_down_list[s].time / 86400
);
this.hour = Math.floor(
(this.count_down_list[s].time / 3600) % 24
);
this.minute = Math.floor(
(this.count_down_list[s].time / 60) % 60
);
this.second = Math.floor(this.count_down_list[s].time % 60);
this.hour_video_id = this.count_down_list[s].video;
const count_down_dict = {
live_day: this.live_day,
hour: this.hour,
minute: this.minute,
second: this.second,
video: this.hour_video_id,
};
this.hour_minute_second_list.push(count_down_dict);
}
}
- 调用倒计时函数
this.countDowm()
3.倒计时函数
countDowm() {
clearInterval(this.promiseTimer);
this.promiseTimer = setInterval(()=> {
this.hour_minute_second_list.forEach((self, index)=>{
if (self.live_day === 0) {
if (self.hour === 0 && self.minute === 0 && self.second === 0) {
self.second = 0;
self.$emit("countDowmEnd", true);
clearInterval(self.promiseTimer);
} else if (self.hour == 0 && self.minute !== 0 && self.second === 0) {
self.second = 59;
self.minute -= 1;
} else if (
self.hour !== 0 &&
self.minute === 0 &&
self.second === 0
) {
self.hour -= 1;
self.minute = 59;
self.second = 59;
} else if (
self.hour !== 0 &&
self.minute !== 0 &&
self.second === 0
) {
self.second = 59;
self.minute -= 1;
} else {
self.second -= 1;
}
} else {
if (self.hour == 0 && self.minute == 0 && self.second === 0) {
self.live_day -= 1;
self.hour = 23;
self.minute = 59;
self.second = 59;
} else if (
self.hour !== 0 &&
self.minute === 0 &&
self.second === 0
) {
self.hour -= 1;
self.minute = 59;
self.second = 59;
} else if (self.hour == 0 && self.minute !== 0 && self.second === 0) {
self.second = 59;
self.minute -= 1;
} else if (
self.hour !== 0 &&
self.minute !== 0 &&
self.second === 0
) {
self.second = 59;
self.minute -= 1;
} else {
self.second -= 1;
}
}
});
}, 1000)
},