2026-09-19 23:40:46 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 数据单位格式化工具
|
|
|
|
|
|
*
|
2026-09-20 04:42:51 +08:00
|
|
|
|
* 按 docs/tech/API.md 数据单位规范:
|
2026-09-19 23:40:46 +08:00
|
|
|
|
* - soc: ‰(千分比)→ 百分比,÷10
|
|
|
|
|
|
* - voltage: mV → V,÷1000
|
|
|
|
|
|
* - current: mA → A,÷1000
|
|
|
|
|
|
* - energy: Wh → kWh,÷1000
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
export const fmtSoc = (v: number | null | undefined) =>
|
|
|
|
|
|
v != null ? (v / 10).toFixed(1) + '%' : '-'
|
|
|
|
|
|
|
|
|
|
|
|
export const fmtVoltage = (v: number | null | undefined) =>
|
|
|
|
|
|
v != null ? (v / 1000).toFixed(1) + ' V' : '-'
|
|
|
|
|
|
|
|
|
|
|
|
export const fmtCurrent = (v: number | null | undefined) =>
|
|
|
|
|
|
v != null ? (v / 1000).toFixed(1) + ' A' : '-'
|
|
|
|
|
|
|
|
|
|
|
|
export const fmtEnergy = (v: number | null | undefined) =>
|
|
|
|
|
|
v != null ? (v / 1000).toFixed(2) + ' kWh' : '-'
|
|
|
|
|
|
|
|
|
|
|
|
export const fmtEnergyKwh = (v: number | null | undefined) =>
|
|
|
|
|
|
v != null ? (v / 1000).toFixed(3) + ' kWh' : '-'
|