4 changed files with 154 additions and 150 deletions
@ -1,99 +1,104 @@ |
|||||||
<template> |
<template> |
||||||
<view class="time"> |
<view class="time"> |
||||||
<text v-if="rtipText">{{ rtipText }}</text> |
{{ tipText }} |
||||||
<text class="styleAll" v-if="risDay === true">{{ rday }}</text> |
<text class="styleAll" v-if="isDay === true">{{ day }}</text> |
||||||
<text class="timeTxt" v-if="rdayText">{{ rdayText }}</text> |
<text class="timeTxt">{{ dayText }}</text> |
||||||
<text class="styleAll">{{ hour }}</text> |
<text class="styleAll">{{ hour }}</text> |
||||||
<text class="timeTxt" v-if="rhourText">{{ rhourText }}</text> |
<text class="timeTxt">{{ hourText }}</text> |
||||||
<text class="styleAll">{{ minute }}</text> |
<text class="styleAll">{{ minute }}</text> |
||||||
<text class="timeTxt" v-if="rminuteText">{{ rminuteText }}</text> |
<text class="timeTxt">{{ minuteText }}</text> |
||||||
<text class="styleAll">{{ second }}</text> |
<text class="styleAll">{{ second }}</text> |
||||||
<text class="timeTxt" v-if="rsecondText">{{ rsecondText }}</text> |
<text class="timeTxt">{{ secondText }}</text> |
||||||
</view> |
</view> |
||||||
</template> |
</template> |
||||||
<script> |
<script> |
||||||
export default { |
export default { |
||||||
name: "CountDown", |
name: "CountDown", |
||||||
props: [ |
props: { |
||||||
//距离开始提示文字 |
//距离开始提示文字 |
||||||
'tipText', |
tipText: { |
||||||
'dayText', |
type: String, |
||||||
'hourText', |
default: "倒计时" |
||||||
'minuteText', |
}, |
||||||
'secondText', |
dayText: { |
||||||
'datatime', |
type: String, |
||||||
'isDay' |
default: "天" |
||||||
], |
}, |
||||||
data: function() { |
hourText: { |
||||||
return { |
type: String, |
||||||
day: "00", |
default: "时" |
||||||
hour: "00", |
}, |
||||||
minute: "00", |
minuteText: { |
||||||
second: "00", |
type: String, |
||||||
rtipText: "倒计时", |
default: "分" |
||||||
rdayText: "天", |
}, |
||||||
rhourText: "时", |
secondText: { |
||||||
rminuteText: "分", |
type: String, |
||||||
rsecondText: "秒", |
default: "秒" |
||||||
rdatatime: 0, |
}, |
||||||
risDay: true |
datatime: { |
||||||
}; |
type: Number, |
||||||
}, |
default: 0 |
||||||
created: function() { |
}, |
||||||
// this.show_time(); |
isDay: { |
||||||
}, |
type: Boolean, |
||||||
mounted: function() { |
default: true |
||||||
this.rtipText = this.$props.tipText; |
} |
||||||
this.rdayText = this.$props.dayText; |
}, |
||||||
this.rhourText = this.$props.hourText; |
data: function () { |
||||||
this.rminuteText = this.$props.minuteText; |
return { |
||||||
this.rsecondText = this.$props.secondText; |
day: "00", |
||||||
this.rdatatime = this.$props.datatime; |
hour: "00", |
||||||
this.risDay = this.$props.isDay; |
minute: "00", |
||||||
this.show_time(); |
second: "00" |
||||||
}, |
}; |
||||||
methods: { |
}, |
||||||
show_time: function() { |
created: function () { |
||||||
let that = this; |
this.show_time(); |
||||||
this.runTime(); |
|
||||||
setInterval(this.runTime, 1000); |
|
||||||
}, |
}, |
||||||
runTime() { |
mounted: function () {}, |
||||||
let that = this; |
methods: { |
||||||
//时间函数 |
show_time: function () { |
||||||
let intDiff = that.datatime - Date.parse(new Date()) / 1000; //获取数据中的时间戳的时间差; |
let that = this; |
||||||
let day = 0, |
|
||||||
hour = 0, |
function runTime() { |
||||||
minute = 0, |
//时间函数 |
||||||
second = 0; |
let intDiff = that.datatime - Date.parse(new Date()) / 1000; //获取数据中的时间戳的时间差; |
||||||
if (intDiff > 0) { |
let day = 0, |
||||||
//转换时间 |
hour = 0, |
||||||
if (that.isDay === true) { |
minute = 0, |
||||||
day = Math.floor(intDiff / (60 * 60 * 24)); |
second = 0; |
||||||
} else { |
if (intDiff > 0) { |
||||||
day = 0; |
//转换时间 |
||||||
|
if (that.isDay === true) { |
||||||
|
day = Math.floor(intDiff / (60 * 60 * 24)); |
||||||
|
} else { |
||||||
|
day = 0; |
||||||
|
} |
||||||
|
hour = Math.floor(intDiff / (60 * 60)) - day * 24; |
||||||
|
minute = Math.floor(intDiff / 60) - day * 24 * 60 - hour * 60; |
||||||
|
second = |
||||||
|
Math.floor(intDiff) - |
||||||
|
day * 24 * 60 * 60 - |
||||||
|
hour * 60 * 60 - |
||||||
|
minute * 60; |
||||||
|
if (hour <= 9) hour = "0" + hour; |
||||||
|
if (minute <= 9) minute = "0" + minute; |
||||||
|
if (second <= 9) second = "0" + second; |
||||||
|
that.day = day; |
||||||
|
that.hour = hour; |
||||||
|
that.minute = minute; |
||||||
|
that.second = second; |
||||||
|
} else { |
||||||
|
that.day = "00"; |
||||||
|
that.hour = "00"; |
||||||
|
that.minute = "00"; |
||||||
|
that.second = "00"; |
||||||
|
} |
||||||
} |
} |
||||||
hour = Math.floor(intDiff / (60 * 60)) - day * 24; |
runTime(); |
||||||
minute = Math.floor(intDiff / 60) - day * 24 * 60 - hour * 60; |
setInterval(runTime, 1000); |
||||||
second = |
|
||||||
Math.floor(intDiff) - |
|
||||||
day * 24 * 60 * 60 - |
|
||||||
hour * 60 * 60 - |
|
||||||
minute * 60; |
|
||||||
if (hour <= 9) hour = "0" + hour; |
|
||||||
if (minute <= 9) minute = "0" + minute; |
|
||||||
if (second <= 9) second = "0" + second; |
|
||||||
that.day = day; |
|
||||||
that.hour = hour; |
|
||||||
that.minute = minute; |
|
||||||
that.second = second; |
|
||||||
} else { |
|
||||||
that.day = "00"; |
|
||||||
that.hour = "00"; |
|
||||||
that.minute = "00"; |
|
||||||
that.second = "00"; |
|
||||||
} |
} |
||||||
} |
} |
||||||
} |
}; |
||||||
}; |
|
||||||
</script> |
</script> |
||||||
|
Loading…
Reference in new issue