Browse Source

fix: 时间

master
guoapeng 2 months ago
parent
commit
1c294a7f93
  1. 10
      src/components/common/Countdown.vue
  2. 2
      src/hooks/useServerTime.ts

10
src/components/common/Countdown.vue

@ -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>

2
src/hooks/useServerTime.ts

@ -15,7 +15,7 @@ export function useServerTime() {
clientFetchTime.value = Date.now()
let num = 0
interval = window.setInterval(async () => {
if (num > 10) {
if (num > 60) {
serverTime.value = await getTime()
clientFetchTime.value = Date.now()
num = 0

Loading…
Cancel
Save