"use client" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Loader2, Database, CheckCircle2, AlertCircle } from "lucide-react" import { Progress } from "@/components/ui/progress" import type { DataCheckResponse, DataUpdateResponse, SearchResult } from "@/lib/types" import { formatTimestamp } from "@/lib/formatters" interface DataStatusDisplayProps { company: SearchResult dataSource: string status: DataCheckResponse | null updateStatus: DataUpdateResponse | null loading: boolean fetching: boolean error: string } export function DataStatusDisplay({ company, dataSource, status, updateStatus, loading, fetching, error }: DataStatusDisplayProps) { if (loading) { return ( ) } // Determine if we should show fetching state const isUpdating = fetching && updateStatus; const progress = updateStatus?.progress_percentage || 0; const message = updateStatus?.progress_message || (updateStatus?.status === "in_progress" ? "正在获取数据..." : "准备中..."); return ( 数据状态 {error && ( {error} )} {/* 正在更新状态 */} {isUpdating && ( {message} {Math.round(progress)}% {updateStatus?.fetched_tables && updateStatus.fetched_tables.length > 0 && ( 已完成: {updateStatus.fetched_tables.map(t => t.replace('tushare_', '').replace('cn_', '')).join(", ")} )} )} {/* 静态数据状态 (非更新时显示) */} {!isUpdating && status?.has_data && status.last_update && ( 数据已就绪 最后更新 {formatTimestamp(status.last_update.date)} {status.last_update.data_start_date && status.last_update.data_end_date && ( 数据范围 {status.last_update.data_start_date} 至 {status.last_update.data_end_date} )} {status.last_update.table_counts && ( {Object.entries(status.last_update.table_counts).map(([table, count]) => ( {table.replace('tushare_', '').replace('cn_', '')}: {count} ))} )} )} {/* 无数据状态 */} {!isUpdating && !status?.has_data && !error && ( 暂无该数据源的数据 请点击右上角的"获取数据"按钮开始同步 )} ) }
暂无该数据源的数据
请点击右上角的"获取数据"按钮开始同步