|
|
@ -14,11 +14,7 @@ const remaining = ref(0) |
|
|
|
let timer: number | null = null |
|
|
|
|
|
|
|
const calculateRemaining = () => { |
|
|
|
// const now = new Date() |
|
|
|
// // 计算时间差(考虑网络延迟) |
|
|
|
// const timeDiff = now.getTime() - props.current |
|
|
|
// 计算结束时间 |
|
|
|
console.log(props) |
|
|
|
const endTime = props.startTime + props.duration * 1000 |
|
|
|
// 剩余时间 = 结束时间 - 当前时间 - 网络延迟 |
|
|
|
remaining.value = Math.max(0, endTime - new Date(systemStore.currentTime).getTime()) |
|
|
@ -43,7 +39,6 @@ const startTimer = () => { |
|
|
|
|
|
|
|
const stopTimer = () => { |
|
|
|
if (timer) { |
|
|
|
console.log(111) |
|
|
|
clearInterval(timer) |
|
|
|
timer = null |
|
|
|
} |
|
|
@ -63,11 +58,14 @@ const hours = ref('00') |
|
|
|
const minutes = ref('00') |
|
|
|
const seconds = ref('00') |
|
|
|
|
|
|
|
const visible = ref(true) |
|
|
|
|
|
|
|
// 监听剩余时间变化 |
|
|
|
watch( |
|
|
|
() => remaining.value, |
|
|
|
(newVal) => { |
|
|
|
if (newVal <= 0 || !newVal) { |
|
|
|
visible.value = false |
|
|
|
days.value = 0 |
|
|
|
hours.value = '00' |
|
|
|
minutes.value = '00' |
|
|
@ -90,7 +88,7 @@ watch( |
|
|
|
</script> |
|
|
|
|
|
|
|
<template> |
|
|
|
<div class="countdown"> |
|
|
|
<div v-if="visible" class="countdown"> |
|
|
|
<span v-if="days">{{ days }}天</span> |
|
|
|
{{ hours }}:{{ minutes }}:{{ seconds }} |
|
|
|
</div> |
|
|
|