提交 5b83d759 authored 作者: FC's avatar FC

fc

上级 d2b18ae0
<template> <template>
<div class="count_wrap"> <div class="count_wrap">
<div class="time_record"><span v-if="tagFlag">计时</span> {{ timeRecord }}</div> <div class="time_record">
<span v-if="tagFlag">计时</span>
{{ timeRecord }}
</div>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
data() { data() {
return { return {
// startTime:'', // startTime:'',
endTime: "", endTime: '',
date: "00", date: '00',
hour: "00", hour: '00',
minute: "00", minute: '00',
second: "00", second: '00',
record: {}, record: {},
}; }
}, },
mounted() { mounted() {
let that = this; let that = this
this.$nextTick(function () { this.$nextTick(function () {
//整个视图都渲染完毕 //整个视图都渲染完毕
that.timeRecording(); that.timeRecording()
}); })
}, },
props: ["startTime","tagFlag"], props: ['startTime', 'tagFlag'],
computed: { computed: {
timeRecord() { timeRecord() {
if (this.startTime !== "") { if (this.startTime !== '') {
//递归每秒调用countTime方法,显示动态时间效果 //递归每秒调用countTime方法,显示动态时间效果
this.record = setTimeout(this.timeRecording, 1000); this.record = setTimeout(this.timeRecording, 1000)
} }
return ( return this.date + '天' + this.hour + '时' + this.minute + '分' + this.second + '秒'
this.date +
"天" +
this.hour +
"时" +
this.minute +
"分" +
this.second +
"秒"
);
}, },
}, },
methods: { methods: {
...@@ -54,42 +48,38 @@ ...@@ -54,42 +48,38 @@
// this.timeRecording() // this.timeRecording()
// }, // },
endRecord() { endRecord() {
let date = new Date(); let date = new Date()
this.endTime = date.getTime(); this.endTime = date.getTime()
clearTimeout(this.record); clearTimeout(this.record)
/* /*
* 调用后台接口保存结束时间 * 调用后台接口保存结束时间
*/ */
}, },
timeRecording() { timeRecording() {
let curTime = new Date().getTime(); let curTime = new Date().getTime()
let startTime = new Date(this.startTime).getTime(); let startTime = new Date(this.startTime).getTime()
//时间差 //时间差
let leftTime = curTime - startTime; let leftTime = curTime - startTime
if (leftTime >= 0) { if (leftTime >= 0) {
this.date = this.checkedZero( this.date = this.checkedZero(Math.floor(leftTime / 1000 / 60 / 60 / 24))
Math.floor(leftTime / 1000 / 60 / 60 / 24) this.hour = this.checkedZero(Math.floor((leftTime / 1000 / 60 / 60) % 24))
); this.minute = this.checkedZero(Math.floor((leftTime / 1000 / 60) % 60))
this.hour = this.checkedZero( this.second = this.checkedZero(Math.floor((leftTime / 1000) % 60))
Math.floor((leftTime / 1000 / 60 / 60) % 24)
);
this.minute = this.checkedZero(Math.floor((leftTime / 1000 / 60) % 60));
this.second = this.checkedZero(Math.floor((leftTime / 1000) % 60));
} }
}, },
checkedZero(number) { checkedZero(number) {
//补0 //补0
if (number <= 9) { if (number <= 9) {
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign
number = `0${number}`; number = `0${number}`
} }
return number; return number
}, },
}, },
}; }
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
.count_wrap { .count_wrap {
height: 100%; height: 100%;
} }
</style> </style>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论