From 02201856efde1f4e1107509fa638d52316cca78a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Sun, 6 Jul 2025 14:12:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=BD=93=E5=89=8D=E6=B6=88=E6=AF=92?= =?UTF-8?q?=E6=B6=B2=E4=BD=99=E9=87=8F=E7=99=BE=E5=88=86=E6=AF=94=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E6=96=B9=E5=BC=8F=E8=B0=83=E6=95=B4=EF=BC=88=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E4=B8=8D=E8=B6=85=E8=BF=87100=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/home/index.vue | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/views/home/index.vue b/src/views/home/index.vue index 50236bc..5409e31 100644 --- a/src/views/home/index.vue +++ b/src/views/home/index.vue @@ -44,12 +44,17 @@ onMounted(() => { }) }) -// 当前消毒液余量百分比 +// 当前消毒液余量百分比(最大不超过100) const nowLiquidProgress = computed(() => { - if (!liquidInfo.value.nowLiquid) { + const now = Number(liquidInfo.value.nowLiquid) + const total = Number(liquidTotal.value) + if (!now || total <= 0) { return 0 } - return roundNumber(Number((liquidInfo.value.nowLiquid / liquidTotal.value) * 100), 0) + // 先算出百分比并四舍五入 + const rawPercent = roundNumber((now / total) * 100, 0) + // 如果大于100,就返回100;否则返回原值 + return rawPercent > 100 ? 100 : rawPercent }) // 当前消毒液余量