From bdd039a2c4404c32589391622cc49d97f85e4dd1 Mon Sep 17 00:00:00 2001 From: kkfluous Date: Tue, 28 Apr 2026 12:01:13 +0800 Subject: [PATCH] refactor(energy): visual polish + KPI/table self-consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - mock: derive ELECTRIC_KPI month/today from APR_DAYS so card and table totals always agree (previously ¥8,437 vs ¥9,151 mismatch) - overview: Top5 bar chart now shows rank badges (1-5) and inline value labels at bar ends — readable without hover - overview: donut "年合计 362.43T" moves into the chart center (previously below as a separate line, defeating the donut hole) - daily: rows with |chainPct| ≥ 30% get a tinted background (green for spikes, red for drops) for at-a-glance abnormal-day spotting Co-Authored-By: Claude Opus 4.7 (1M context) --- src/modules/energy/HydrogenDaily.tsx | 8 ++- src/modules/energy/HydrogenOverview.tsx | 80 ++++++++++++++++++------- src/modules/energy/mock.ts | 26 ++++---- 3 files changed, 79 insertions(+), 35 deletions(-) diff --git a/src/modules/energy/HydrogenDaily.tsx b/src/modules/energy/HydrogenDaily.tsx index 1794b81..b58fbb6 100644 --- a/src/modules/energy/HydrogenDaily.tsx +++ b/src/modules/energy/HydrogenDaily.tsx @@ -120,11 +120,15 @@ export default function HydrogenDaily() {
暂无数据
) : rows.map(r => { const open = expanded.has(r.date); + const isAbnormal = Math.abs(r.chainPct) >= 0.3; + const abnormalBg = isAbnormal + ? r.chainPct > 0 ? 'bg-emerald-50/40' : 'bg-red-50/40' + : ''; return ( -
+
- - + + } tickLine={false} axisLine={false} /> @@ -103,6 +124,14 @@ export default function HydrogenOverview() { {HYDROGEN_STATIONS_TOP5.map((_, i) => ( ))} + `${Number(v ?? 0).toLocaleString('zh-CN', { maximumFractionDigits: 0 })}`} + fill="#475569" + fontSize={11} + fontWeight={700} + /> @@ -117,23 +146,29 @@ export default function HydrogenOverview() {
各区域加氢占比
- - - - {HYDROGEN_REGION_SHARE.map((_, i) => ( - - ))} - - `${(Number(v ?? 0) / 1000).toFixed(2)}T`} contentStyle={{ borderRadius: 12, fontSize: 12 }} /> - - +
+ + + + {HYDROGEN_REGION_SHARE.map((_, i) => ( + + ))} + + `${(Number(v ?? 0) / 1000).toFixed(2)}T`} contentStyle={{ borderRadius: 12, fontSize: 12 }} /> + + +
+
年合计
+
{(HYDROGEN_KPI.yearKg / 1000).toFixed(2)}T
+
+
{HYDROGEN_REGION_SHARE.map((r, i) => (
@@ -144,7 +179,6 @@ export default function HydrogenOverview() { ))}
-
年合计 {(HYDROGEN_KPI.yearKg / 1000).toFixed(2)}T
diff --git a/src/modules/energy/mock.ts b/src/modules/energy/mock.ts index f848879..018e969 100644 --- a/src/modules/energy/mock.ts +++ b/src/modules/energy/mock.ts @@ -72,16 +72,6 @@ export const HYDROGEN_DAILY: HydrogenDailyRow[] = Array.from({ length: 30 }, (_, }; }); -export const ELECTRIC_KPI: ElectricKpi = { - totalKwh: 817_632.24, - totalFee: 151_542.92, - monthKwh: 42_318.56, - monthFee: 8_437.12, - todayKwh: 510.91, - todayFee: 184.82, - todayChainPct: -0.821, -}; - const APR_DAYS: Array<[string, number, number]> = [ ['2026-04-26', 510.91, 184.82], ['2026-04-25', 2859.61, 314.20], @@ -113,6 +103,22 @@ function buildElectricRows(days: Array<[string, number, number]>) { }); } +const APR_KWH_SUM = APR_DAYS.reduce((a, [, k]) => a + k, 0); +const APR_FEE_SUM = APR_DAYS.reduce((a, [, , f]) => a + f, 0); +const [TODAY_DATE, TODAY_KWH, TODAY_FEE] = APR_DAYS[0]; +const [, PREV_KWH] = APR_DAYS[1]; +void TODAY_DATE; + +export const ELECTRIC_KPI: ElectricKpi = { + totalKwh: 817_632.24, + totalFee: 151_542.92, + monthKwh: APR_KWH_SUM, + monthFee: APR_FEE_SUM, + todayKwh: TODAY_KWH, + todayFee: TODAY_FEE, + todayChainPct: (TODAY_KWH - PREV_KWH) / PREV_KWH, +}; + export const ELECTRIC_MONTHLY: ElectricMonthGroup[] = [ { month: '2026-04',