提交 21c85fc1 authored 作者: FC's avatar FC

合并分支 'fc' 到 'master'

fc 查看合并请求 !1
<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 {
export default {
data() {
return {
// startTime:'',
endTime: "",
date: "00",
hour: "00",
minute: "00",
second: "00",
endTime: '',
date: '00',
hour: '00',
minute: '00',
second: '00',
record: {},
};
}
},
mounted() {
let that = this;
let that = this
this.$nextTick(function () {
//整个视图都渲染完毕
that.timeRecording();
});
that.timeRecording()
})
},
props: ["startTime","tagFlag"],
props: ['startTime', 'tagFlag'],
computed: {
timeRecord() {
if (this.startTime !== "") {
if (this.startTime !== '') {
//递归每秒调用countTime方法,显示动态时间效果
this.record = setTimeout(this.timeRecording, 1000);
this.record = setTimeout(this.timeRecording, 1000)
}
return (
this.date +
"天" +
this.hour +
"时" +
this.minute +
"分" +
this.second +
"秒"
);
return this.date + '天' + this.hour + '时' + this.minute + '分' + this.second + '秒'
},
},
methods: {
......@@ -54,42 +48,38 @@
// this.timeRecording()
// },
endRecord() {
let date = new Date();
this.endTime = date.getTime();
clearTimeout(this.record);
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 curTime = new Date().getTime()
let startTime = new Date(this.startTime).getTime()
//时间差
let leftTime = curTime - startTime;
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));
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}`;
number = `0${number}`
}
return number;
return number
},
},
};
}
</script>
<style scoped lang="less">
.count_wrap {
.count_wrap {
height: 100%;
}
}
</style>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论