yfs/components/xw-CountDown2/index.vue
2025-03-14 11:01:58 +08:00

108 lines
2.0 KiB
Vue

<template>
<view class="time" :style="justifyLeft">
<!-- <text class="red" v-if="tipText">{{ tipText }}</text>
<text class="styleAll" v-if="isDay === true">{{ day }}</text>
<text class="timeTxt red" v-if="dayText">{{ dayText }}</text>
<text class="styleAll" v-if="ishour === true">{{ hour }}</text>
<text class="timeTxt red" v-if="hourText">{{ hourText }}</text>
<text class="styleAll">{{ minute }}</text>
<text class="timeTxt red" v-if="minuteText">{{ minuteText }}</text> -->
<text class="styleAll">{{ second }}</text>
<!-- <text class="timeTxt red" v-if="secondText">{{ secondText }}</text> -->
</view>
</template>
<script>
export default {
name: "countDown",
props: {
justifyLeft: {
type: String,
default: ""
},
//距离开始提示文字
tipText: {
type: String,
default: "倒计时"
},
dayText: {
type: String,
default: "天"
},
hourText: {
type: String,
default: "时"
},
minuteText: {
type: String,
default: "分"
},
secondText: {
type: String,
default: "秒"
},
datatime: {
type: Number,
default: 0
},
isDay: {
type: Boolean,
default: true
},
ishour: {
type: Boolean,
default: true
}
},
data: function() {
return {
day: "00",
hour: "00",
minute: "00",
second: "00"
};
},
created: function() {
this.show_time();
},
mounted: function() {},
methods: {
show_time: function() {
let that = this;
function runTime() {
//时间函数
// console.log(that.datatime)
that.second = that.datatime - Date.parse(new Date()) / 1000; //获取数据中的时间戳的时间差;
if (that.second <= 0) {
//转换时间
that.$emit('change', {
's': that.second
})
clearInterval()
return
}
}
runTime();
setInterval(runTime, 1000);
}
}
};
</script>
<style>
.time {
display: flex;
justify-content: center;
/* font-size: 24rpx; */
color: #fff;
}
.red {
/* color: #fc4141; */
margin: 0 4rpx;
}
</style>