提交 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() {
let that = this
this.$nextTick(function () {
//整个视图都渲染完毕
that.timeRecording()
})
},
props: ['startTime', 'tagFlag'],
computed: {
timeRecord() {
if (this.startTime !== '') {
//递归每秒调用countTime方法,显示动态时间效果
this.record = setTimeout(this.timeRecording, 1000)
}
return this.date + '天' + this.hour + '时' + this.minute + '分' + this.second + '秒'
}, },
mounted() { },
let that = this; methods: {
this.$nextTick(function () { // startRecord() {
//整个视图都渲染完毕 // // //获取当前时间,记录下当前时间保存到后台
that.timeRecording(); // // let date = new Date();
}); // // this.startTime = date.getTime();
// /*
// * 调用后台接口保存开始时间后,再重新获取开始时间
// * this.$emit("update:IframeFlag", false);
// */
// this.timeRecording()
// },
endRecord() {
let date = new Date()
this.endTime = date.getTime()
clearTimeout(this.record)
/*
* 调用后台接口保存结束时间
*/
}, },
props: ["startTime","tagFlag"], timeRecording() {
computed: { let curTime = new Date().getTime()
timeRecord() { let startTime = new Date(this.startTime).getTime()
if (this.startTime !== "") { //时间差
//递归每秒调用countTime方法,显示动态时间效果 let leftTime = curTime - startTime
this.record = setTimeout(this.timeRecording, 1000); if (leftTime >= 0) {
} this.date = this.checkedZero(Math.floor(leftTime / 1000 / 60 / 60 / 24))
return ( this.hour = this.checkedZero(Math.floor((leftTime / 1000 / 60 / 60) % 24))
this.date + this.minute = this.checkedZero(Math.floor((leftTime / 1000 / 60) % 60))
"天" + this.second = this.checkedZero(Math.floor((leftTime / 1000) % 60))
this.hour + }
"时" +
this.minute +
"分" +
this.second +
"秒"
);
},
}, },
methods: { checkedZero(number) {
// startRecord() { //补0
// // //获取当前时间,记录下当前时间保存到后台 if (number <= 9) {
// // let date = new Date(); // eslint-disable-next-line no-param-reassign
// // this.startTime = date.getTime(); number = `0${number}`
// /* }
// * 调用后台接口保存开始时间后,再重新获取开始时间 return number
// * this.$emit("update:IframeFlag", false);
// */
// this.timeRecording()
// },
endRecord() {
let date = new Date();
this.endTime = date.getTime();
clearTimeout(this.record);
/*
* 调用后台接口保存结束时间
*/
},
timeRecording() {
let curTime = new Date().getTime();
let startTime = new Date(this.startTime).getTime();
//时间差
let leftTime = curTime - startTime;
if (leftTime >= 0) {
this.date = this.checkedZero(
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.second = this.checkedZero(Math.floor((leftTime / 1000) % 60));
}
},
checkedZero(number) {
//补0
if (number <= 9) {
// eslint-disable-next-line no-param-reassign
number = `0${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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论