From d24ce55a591ce7537083ab786202e1aa110e6020 Mon Sep 17 00:00:00 2001 From: kkfluous Date: Thu, 30 Apr 2026 15:08:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(energy):=20=E9=A1=B6=E9=83=A8=E5=8F=8C=20st?= =?UTF-8?q?icky=20=E9=97=B4=E9=9A=99=E6=B3=84=E9=9C=B2=20+=20=E5=8A=A0?= =?UTF-8?q?=E6=B0=A2=E7=AB=99=E5=90=8D=E5=8D=95=E4=BB=B7=E5=AE=8C=E6=95=B4?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题 1:原本「氢能/电能/ETC」与「每日/总览」是两个独立的 sticky 元素,分别 top:0 / top:[58px],中间 gap-3 +位置不精确导致滚动时 图表内容从 14px 缝隙里穿过。 修复: - 把 HydrogenView 内部的 sub-tab 状态提到 EnergyModule - top tab + 子 tab 合并到「同一张白色 rounded-2xl 卡片」里,无内部间隙 - 外层 sticky 容器 frosted glass:bg-[#F8F9FB]/85 + backdrop-blur-md -mx -mt 扩到页面边,消除左右上的微缝 - HydrogenView 改为受控组件(接收 sub prop) 问题 2:站点行 mobile 上 name + ' · 价格' 共用一格还 truncate, 导致长名称(广州新锋交通联新…/上海浦江加氢站…)截断、单价不可见。 修复: - 行改为「站名换行 + 下方单价 chip」纵向排列 - 单价用 amber 小徽章「单价 X 元/Kg」,不再 inline 跟着名字 - name 用 break-words 允许折行,items-start 顶部对齐 - 单价为 0(免费/赠送)时不显示徽章,desktop 列里显示「—」 Co-Authored-By: Claude Opus 4.7 (1M context) --- src/modules/energy/EnergyModule.tsx | 76 ++++++++++++++++++++-------- src/modules/energy/HydrogenDaily.tsx | 18 ++++--- src/modules/energy/HydrogenView.tsx | 39 +++----------- 3 files changed, 74 insertions(+), 59 deletions(-) diff --git a/src/modules/energy/EnergyModule.tsx b/src/modules/energy/EnergyModule.tsx index 07664a3..46ad883 100644 --- a/src/modules/energy/EnergyModule.tsx +++ b/src/modules/energy/EnergyModule.tsx @@ -1,7 +1,7 @@ import { useState } from 'react'; -import { Fuel, BatteryCharging, Receipt } from 'lucide-react'; +import { Fuel, BatteryCharging, Receipt, LayoutDashboard, CalendarDays } from 'lucide-react'; import { motion } from 'motion/react'; -import HydrogenView from './HydrogenView'; +import HydrogenView, { type HydrogenSubTab } from './HydrogenView'; import ElectricView from './ElectricView'; import ETCView from './ETCView'; @@ -13,31 +13,65 @@ const TABS: { key: TopTab; label: string; icon: typeof Fuel }[] = [ { key: 'etc', label: 'ETC', icon: Receipt }, ]; +const HYDROGEN_SUB_TABS: { id: HydrogenSubTab; label: string; icon: typeof LayoutDashboard }[] = [ + { id: 'daily', label: '每日', icon: CalendarDays }, + { id: 'overview', label: '总览', icon: LayoutDashboard }, +]; + export default function EnergyModule() { const [activeTab, setActiveTab] = useState('hydrogen'); + const [hydroSub, setHydroSub] = useState('daily'); return (
-
- {TABS.map(tab => { - const Icon = tab.icon; - const active = activeTab === tab.key; - return ( - - ); - })} + + {/* 统一 sticky 头部:top tab + (氢能时) 子 tab;同一张卡片,无间隙 */} +
+
+ {/* 顶部 tab:氢能 / 电能 / ETC */} +
+ {TABS.map(tab => { + const Icon = tab.icon; + const active = activeTab === tab.key; + return ( + + ); + })} +
+ {/* 子 tab:仅氢能时显示 */} + {activeTab === 'hydrogen' && ( +
+ {HYDROGEN_SUB_TABS.map(({ id, label, icon: Icon }) => { + const active = hydroSub === id; + return ( + + ); + })} +
+ )} +
- {activeTab === 'hydrogen' && } + + {activeTab === 'hydrogen' && } {activeTab === 'electric' && } {activeTab === 'etc' && }
diff --git a/src/modules/energy/HydrogenDaily.tsx b/src/modules/energy/HydrogenDaily.tsx index 76cf2fc..74aa8e5 100644 --- a/src/modules/energy/HydrogenDaily.tsx +++ b/src/modules/energy/HydrogenDaily.tsx @@ -191,13 +191,19 @@ export default function HydrogenDaily() { {r.stations.map(s => (
- - {s.name} - · {s.pricePerKg} - - {s.pricePerKg} +
+
+ {s.name} +
+ {s.pricePerKg > 0 && ( +
+ 单价 {s.pricePerKg} 元/Kg +
+ )} +
+ {s.pricePerKg > 0 ? s.pricePerKg : '—'} {s.kg.toLocaleString('zh-CN', { maximumFractionDigits: 2 })} diff --git a/src/modules/energy/HydrogenView.tsx b/src/modules/energy/HydrogenView.tsx index 07c1a92..c5a24af 100644 --- a/src/modules/energy/HydrogenView.tsx +++ b/src/modules/energy/HydrogenView.tsx @@ -1,37 +1,12 @@ -import { useState } from 'react'; -import { LayoutDashboard, CalendarDays } from 'lucide-react'; import HydrogenOverview from './HydrogenOverview'; import HydrogenDaily from './HydrogenDaily'; -type SubTab = 'daily' | 'overview'; +export type HydrogenSubTab = 'daily' | 'overview'; -const SUB_TABS: Array<{ id: SubTab; label: string; icon: typeof LayoutDashboard }> = [ - { id: 'daily', label: '每日', icon: CalendarDays }, - { id: 'overview', label: '总览', icon: LayoutDashboard }, -]; - -export default function HydrogenView() { - const [sub, setSub] = useState('daily'); - return ( - <> -
- {SUB_TABS.map(({ id, label, icon: Icon }) => { - const active = sub === id; - return ( - - ); - })} -
- {sub === 'overview' ? : } - - ); +interface Props { + sub: HydrogenSubTab; +} + +export default function HydrogenView({ sub }: Props) { + return sub === 'overview' ? : ; }