import { useState } from 'react' import { Loader2, Search, FileText, Database, Lightbulb, ExternalLink, X } from 'lucide-react' import { PageHeader } from '@/components/PageHeader' import { EmptyState } from '@/components/EmptyState' import { useFinancialStatus } from '@/lib/useFinancials' import { StockFinancialSearch } from '@/components/financials/StockFinancialSearch' import { StockFinancialDetail } from '@/components/financials/StockFinancialDetail' import { ReportHistoryPanel } from '@/components/financials/ReportHistoryPanel' import { LastStockChip } from '@/components/LastStockChip' import { useLastStock } from '@/lib/useLastStock' import { fmtBigNum } from '@/lib/format' const TABLE_LABELS: Record = { metrics: '核心指标', income: '利润表', balance_sheet: '资产负债表', cash_flow: '现金流量表', } const TABLE_ICON: Record = { metrics: Database, income: FileText, balance_sheet: FileText, cash_flow: FileText, } export function Financials() { const { data: status, isLoading } = useFinancialStatus() const { last: lastStock, remember: rememberStock } = useLastStock('financials') const [selected, setSelected] = useState<{ symbol: string; name: string } | null>(null) const pick = (symbol: string, name: string) => { setSelected({ symbol, name }) rememberStock(symbol, name) } // 等待 status 加载完, 判断是否有从 local 同步来的数据 if (isLoading) { return ( <>
) } if (!status?.available) { // 无同步数据 return ( <>
关于数据源

当前财务数据源需付费,后续会接入免费数据源。如你常用某个免费财务数据源,欢迎在 Issues 中多多推荐哈 ~

前往 Issues 推荐
) } // 有同步数据, 继续展示 const tables = status?.tables ?? {} const available = status?.available ?? false return ( <> } />
{/* 同步状态卡片 —— 始终显示,反映本地财务数据概况 */} {!isLoading && available && (
{Object.entries(TABLE_LABELS).map(([key, label]) => { const info = tables[key] const TIcon = TABLE_ICON[key] ?? Database const hasData = (info?.rows ?? 0) > 0 // 本次同步三态: 完成 / 同步中 / 等待 (仅全量同步时未轮到的表才"等待") return (
{label}
{fmtBigNum(info?.rows ?? 0)}
{fmtBigNum(info?.symbols ?? 0)} 只标的
) })}
)} {isLoading ? (
) : !available ? (
暂无财务数据
点击右上角"全部同步"从 TickFlow 拉取
) : ( <> {/* 个股搜索区 */}
{selected ? ( // 已选股:紧凑搜索条 + 清除按钮(便于换股)
) : ( // 未选股:醒目居中引导
搜索个股查看详细财务数据
支持股票代码或名称模糊匹配,如 600000 / 浦发
)}
{/* 个股详情 / 空引导 */}
{selected ? ( ) : ( )}
{/* AI 历史分析报告 */} {available && } )}
) }