import { useEffect, useState } from 'react' import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts' import { api } from '../../api/client.js' // 策略研究: 顶部 chip 行选策略, 下面显示 4 张图 (debt / gdp / debtToGdp / interestToGdp) + 表格 const SERIES = [ { key: 'debt', label: '政府债务 (万亿美元)', color: '#8884d8' }, { key: 'gdp', label: 'GDP (万亿美元)', color: '#3cb44b' }, { key: 'debtToGdp', label: '债务/GDP (%)', color: '#4363d8' }, { key: 'interestToGdp', label: '债务利息/GDP (%)', color: '#f58231' }, ] export default function StrategyView() { const [strategies, setStrategies] = useState([]) const [selected, setSelected] = useState(null) const [err, setErr] = useState('') const [loading, setLoading] = useState(true) useEffect(() => { let cancelled = false setLoading(true) api('/strategies') .then((data) => { if (cancelled) return setStrategies(data.strategies || []) if (data.strategies && data.strategies[0]) setSelected(data.strategies[0].name) }) .catch((e) => !cancelled && setErr(e.message)) .finally(() => !cancelled && setLoading(false)) return () => { cancelled = true } }, []) if (loading) return
加载中...
if (err) return
{err}
if (!strategies.length) return
暂无策略数据
const cur = strategies.find((s) => s.name === selected) const rows = cur ? cur.data.rows : [] return (
策略研究
{strategies.map((s) => ( ))}
{cur && (
{cur.description || cur.name}
数据 {rows.length} 条 · 来源 {cur.data.source || 'seed'}
{SERIES.map((s) => (
{s.label}
))}
{rows.map((r) => ( ))}
年份 债务 GDP 债务/GDP 利息/GDP
{r.year} {r.debt} {r.gdp} {r.debtToGdp} {r.interestToGdp}
)}
) }