import { AnimatePresence, motion } from 'framer-motion' import { useQuery } from '@tanstack/react-query' import { api, type EnrichedField } from '@/lib/api' import { QK } from '@/lib/queryKeys' const TABLE_TITLES: Record = { instruments: '个股维表', daily: '日 K', adj_factor: '除权因子', enriched: 'Enriched', minute: '分钟 K', index_instruments: '指数维表', index_daily: '指数日 K', index_enriched: '指数 Enriched', etf_instruments: 'ETF 维表', etf_daily: 'ETF 日 K', etf_enriched: 'ETF Enriched', } function categorize(name: string): string { if (['symbol', 'date'].includes(name)) return '基础' if (['open', 'high', 'low', 'close', 'volume', 'amount'].includes(name)) return '行情' if (name.startsWith('raw_') || name.startsWith('ex_') || name === 'close_pre_adj') return '复权' if (name.startsWith('ma')) return '均线 MA' if (name.startsWith('ema')) return '指数均线 EMA' if (name.startsWith('macd')) return 'MACD' if (name.startsWith('boll')) return '布林带' if (name.startsWith('kdj')) return 'KDJ' if (name.startsWith('rsi')) return 'RSI' if (name.startsWith('signal_') || name.startsWith('consecutive_')) return '信号' if (['atr_14', 'vol_ratio_5d', 'vol_ma5', 'vol_ma10', 'momentum_5d', 'momentum_10d', 'momentum_20d', 'momentum_30d', 'momentum_60d', 'annual_vol_20d', 'change_pct', 'change_amount', 'amplitude', 'turnover_rate'].includes(name)) return '波动/动量' if (['high_60d', 'low_60d'].includes(name)) return '极值' return '其他' } export function EnrichedSchemaModal({ table, onClose }: { table: string | null; onClose: () => void }) { const open = !!table const schema = useQuery({ queryKey: QK.tableSchema(table!), queryFn: () => api.enrichedSchema(table!), enabled: open, staleTime: Infinity, }) const fields = schema.data ?? [] const groups: Record = {} for (const f of fields) { const cat = categorize(f.name) if (!groups[cat]) groups[cat] = [] groups[cat].push(f) } const title = table ? (TABLE_TITLES[table] ?? table) : '' return ( {open && (

{title} 字段说明

{fields.length} 个字段
{schema.isLoading ? (
加载中…
) : (
{Object.entries(groups).map(([cat, items]) => (
{cat}
{items.map((f) => (
{f.name} {f.desc} {f.type}
))}
))}
)}
)} ) }