From 587363ace43e10203bb95727835bb315b46dad6c Mon Sep 17 00:00:00 2001 From: BTMuli Date: Sun, 12 Apr 2026 20:30:26 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E6=A0=91?= =?UTF-8?q?=E8=84=82=E8=AE=A1=E7=AE=97=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pageHome/ph-daily-note-resin.vue | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/components/pageHome/ph-daily-note-resin.vue b/src/components/pageHome/ph-daily-note-resin.vue index 6eca9d55..7a2b8403 100644 --- a/src/components/pageHome/ph-daily-note-resin.vue +++ b/src/components/pageHome/ph-daily-note-resin.vue @@ -28,12 +28,21 @@ type PhDailyNoteResinProps = { const props = defineProps(); -const current = ref(0); const remainedTime = ref(0); -const formattedTime = ref(""); const initialRecoveryTime = ref(0); +const initialCurrent = ref(0); + const max = computed(() => props.maxResin ?? 200); +const current = computed(() => { + const totalSecondsPassed = initialRecoveryTime.value - remainedTime.value; + const resinToRecover = Math.floor(totalSecondsPassed / 540); + return Math.min(initialCurrent.value + resinToRecover, max.value); +}); const full = computed(() => current.value === max.value); +const formattedTime = computed(() => { + if (remainedTime.value <= 0) return "已恢复满"; + return stamp2LastTime(remainedTime.value * 1000); +}); let timer: ReturnType | null = null; @@ -56,27 +65,16 @@ watch( ); function initTime(): void { - current.value = props.currentResin || 0; + initialCurrent.value = props.currentResin || 0; const time = props.recoveryTime; remainedTime.value = typeof time === "string" ? parseInt(time) : time || 0; initialRecoveryTime.value = remainedTime.value; - updateFormattedTime(); } function startTimer(): void { if (remainedTime.value <= 0) return; - timer = setInterval(() => { - if (remainedTime.value > 0) { - remainedTime.value -= 1; - updateFormattedTime(); - const totalSecondsPassed = initialRecoveryTime.value - remainedTime.value; - const resinToRecover = Math.floor(totalSecondsPassed / 540); - const newCurrent = Math.min(current.value + resinToRecover, max.value); - if (newCurrent !== current.value) { - current.value = newCurrent; - } - } + if (remainedTime.value > 0) remainedTime.value -= 1; }, 1000); } @@ -86,15 +84,6 @@ function stopTimer(): void { timer = null; } } - -function updateFormattedTime(): void { - if (remainedTime.value <= 0) { - formattedTime.value = "已恢复满"; - return; - } - - formattedTime.value = stamp2LastTime(remainedTime.value * 1000); -}