fix: show placeholder for zero battery
This commit is contained in:
@@ -41,6 +41,14 @@ function getSignalLabel(value?: number | null): string {
|
|||||||
return '弱'
|
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 {
|
function formatSleepRange(status: DeviceStatus | null): string {
|
||||||
const start = status?.disable_time_start?.trim()
|
const start = status?.disable_time_start?.trim()
|
||||||
const end = status?.disable_time_end?.trim()
|
const end = status?.disable_time_end?.trim()
|
||||||
@@ -284,7 +292,7 @@ export default function Device() {
|
|||||||
const childName = child.child_name || '未设置'
|
const childName = child.child_name || '未设置'
|
||||||
const pageTitle = `${childName} 的伴伴`
|
const pageTitle = `${childName} 的伴伴`
|
||||||
const batteryValue = deviceStatus?.power ?? deviceStatus?.battery_pct ?? null
|
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 signalLabel = getSignalLabel(deviceStatus?.signal)
|
||||||
const versionLabel = deviceStatus?.version || '--'
|
const versionLabel = deviceStatus?.version || '--'
|
||||||
const coordinateLabel = formatCoordinates(deviceStatus)
|
const coordinateLabel = formatCoordinates(deviceStatus)
|
||||||
@@ -307,8 +315,8 @@ export default function Device() {
|
|||||||
</View>
|
</View>
|
||||||
<View className='battery-section'>
|
<View className='battery-section'>
|
||||||
<Text className='battery-percent'>
|
<Text className='battery-percent'>
|
||||||
{batteryDisplay}
|
{batteryDisplay.text}
|
||||||
{batteryDisplay !== '--' && <Text className='percent'>%</Text>}
|
{batteryDisplay.showPercent && <Text className='percent'>%</Text>}
|
||||||
</Text>
|
</Text>
|
||||||
<Text className='battery-label'>当前电量</Text>
|
<Text className='battery-label'>当前电量</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
Reference in New Issue
Block a user