From aea7a3fe42de949dead679c8c27077ecf6193f2b Mon Sep 17 00:00:00 2001 From: stu2not Date: Tue, 2 Jun 2026 14:40:44 +0800 Subject: [PATCH] fix: show placeholder for zero battery --- banban-mini/src/pages/device/index.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/banban-mini/src/pages/device/index.tsx b/banban-mini/src/pages/device/index.tsx index a8919f0..60ab715 100644 --- a/banban-mini/src/pages/device/index.tsx +++ b/banban-mini/src/pages/device/index.tsx @@ -41,6 +41,14 @@ function getSignalLabel(value?: number | null): string { return '弱' } +function formatBatteryDisplay(value?: number | null): { text: string; showPercent: boolean } { + if (value === null || value === undefined) return { text: '--', showPercent: false } + const normalized = Number(value) + if (!Number.isFinite(normalized)) return { text: '--', showPercent: false } + if (normalized === 0) return { text: '*', showPercent: false } + return { text: String(normalized), showPercent: true } +} + function formatSleepRange(status: DeviceStatus | null): string { const start = status?.disable_time_start?.trim() const end = status?.disable_time_end?.trim() @@ -284,7 +292,7 @@ export default function Device() { const childName = child.child_name || '未设置' const pageTitle = `${childName} 的伴伴` const batteryValue = deviceStatus?.power ?? deviceStatus?.battery_pct ?? null - const batteryDisplay = batteryValue === null || batteryValue === undefined ? '--' : String(batteryValue) + const batteryDisplay = formatBatteryDisplay(batteryValue) const signalLabel = getSignalLabel(deviceStatus?.signal) const versionLabel = deviceStatus?.version || '--' const coordinateLabel = formatCoordinates(deviceStatus) @@ -307,8 +315,8 @@ export default function Device() { - {batteryDisplay} - {batteryDisplay !== '--' && %} + {batteryDisplay.text} + {batteryDisplay.showPercent && %} 当前电量