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

fc

上级 d2b18ae0
<template>
<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>
</template>
<script>
export default {
data() {
return {
// startTime:'',
endTime: "",
date: "00",
hour: "00",
minute: "00",
second: "00",
record: {},
};
export default {
data() {
return {
// startTime:'',
endTime: '',
date: '00',
hour: '00',
minute: '00',
second: '00',
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;
this.$nextTick(function () {
//整个视图都渲染完毕
that.timeRecording();
});
},
methods: {
// startRecord() {
// // //获取当前时间,记录下当前时间保存到后台
// // 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"],
computed: {
timeRecord() {
if (this.startTime !== "") {
//递归每秒调用countTime方法,显示动态时间效果
this.record = setTimeout(this.timeRecording, 1000);
}
return (
this.date +
"天" +
this.hour +
"时" +
this.minute +
"分" +
this.second +
"秒"
);
},
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))
}
},
methods: {
// startRecord() {
// // //获取当前时间,记录下当前时间保存到后台
// // 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);
/*
* 调用后台接口保存结束时间
*/
},
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;
},
checkedZero(number) {
//补0
if (number <= 9) {
// eslint-disable-next-line no-param-reassign
number = `0${number}`
}
return number
},
};
},
}
</script>
<style scoped lang="less">
.count_wrap {
height: 100%;
}
.count_wrap {
height: 100%;
}
</style>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论