修改数据获取方式

This commit is contained in:
cheney
2026-08-06 14:00:11 +08:00
parent 4da9489662
commit b10b1c44db
11 changed files with 615 additions and 31 deletions
+12 -5
View File
@@ -7,6 +7,11 @@ import TrendBadge, { calcTrend, lastPoint } from '../../components/TrendBadge.js
// 经济数据
// 列表态 (默认): 列出所有指标, 每行显示最新值 + 趋势徽标, 点击进入详情
// 详情态: 顶部 NavBar (返回) + 折线图 + 数据表
// 统一数据行的时间字段: 兼容 {month}/{year}/{period} 三种存储形状
function periodOf(r) {
return (r && (r.period || r.month || r.year)) || ''
}
export default function DataView() {
const [indicators, setIndicators] = useState([])
const [err, setErr] = useState('')
@@ -51,7 +56,7 @@ export default function DataView() {
<List.Item
key={i.name}
title={labelOf(i)}
description={lp ? <><b>{lp.value}{unit}</b> · {lp.month}</> : '暂无数据'}
description={lp ? <><b>{lp.value}{unit}</b> · {periodOf(lp)}</> : '暂无数据'}
extra={
<div className="row-meta">
{lp && Math.abs(change) >= 1 && (
@@ -77,6 +82,8 @@ export default function DataView() {
function DataDetail({ indicator, onBack }) {
const i = indicator
const rows = (i.data && i.data.rows) || []
// 图表 X 轴统一用 period 字段
const chartRows = rows.map((r) => ({ ...r, period: periodOf(r) }))
const lp = lastPoint(i.data)
const { trend } = calcTrend(rows)
const title = (i.data && i.data.title) || i.name
@@ -86,14 +93,14 @@ function DataDetail({ indicator, onBack }) {
<Card className="detail-card">
<div className="detail-meta">
单位 {i.data.unit || '-'} · 来源 {i.data.source || 'seed'} ·
{lp && <> 最新 <b style={{ color: 'var(--color-text)' }}>{lp.value}{i.data.unit || ''}</b> ({lp.month}) </>}
{lp && <> 最新 <b style={{ color: 'var(--color-text)' }}>{lp.value}{i.data.unit || ''}</b> ({periodOf(lp)}) </>}
<TrendBadge trend={trend} />
</div>
<div className="chart-wrap">
<ResponsiveContainer width="100%" height={260}>
<LineChart data={rows} margin={{ top: 10, right: 16, left: 0, bottom: 0 }}>
<LineChart data={chartRows} margin={{ top: 10, right: 16, left: 0, bottom: 0 }}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="month" tick={{ fontSize: 11 }} />
<XAxis dataKey="period" tick={{ fontSize: 11 }} />
<YAxis tick={{ fontSize: 11 }} />
<Tooltip />
<Legend />
@@ -108,7 +115,7 @@ function DataDetail({ indicator, onBack }) {
</thead>
<tbody>
{rows.map((r) => (
<tr key={r.month}><td>{r.month}</td><td style={{ textAlign: 'right' }}>{r.value}</td></tr>
<tr key={periodOf(r)}><td>{periodOf(r)}</td><td style={{ textAlign: 'right' }}>{r.value}</td></tr>
))}
</tbody>
</table>