import { createFileRoute, Link } from "@tanstack/react-router"; import { useQuery } from "@tanstack/react-query"; import { Fragment, useState } from "react"; import { fetchActiveCoreStocks } from "@/lib/core-stock-api"; import { ArrowLeft, RefreshCw, Flame } from "lucide-react"; import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; export const Route = createFileRoute("/core-stocks")({ component: CoreStocksPage, }); /** 格式化涨幅,红涨绿跌 */ function formatGain(v: number | null | undefined): string { if (v == null) return "·"; const s = v >= 0 ? `+${v.toFixed(2)}%` : `${v.toFixed(2)}%`; return s; } function CoreStocksPage() { const [days, setDays] = useState(10); const { data, isLoading, isFetching, refetch } = useQuery({ queryKey: ["core-stocks", "active", days], queryFn: () => fetchActiveCoreStocks(days), staleTime: 60_000, retry: false, }); const dates = data?.dates ?? []; const stocks = data?.stocks ?? []; return (
{/* 顶栏 */}

热点股追踪

活跃热点股(最近 {days} 个交易日内上榜)· 按上榜次数排序 · 共 {stocks.length} 只

setDays(Number(v))}> 近3日 近5日 近10日
{isLoading ? (
) : dates.length === 0 || stocks.length === 0 ? (
暂无数据,数据将在每日收盘后自动采集
) : (
{dates.map((d) => ( ))} {stocks.map((s) => ( {dates.map((d) => { const g = s.dailyGains[d]; const cls = g == null ? "text-muted-foreground/40" : g >= 0 ? "text-red-500" : "text-green-500"; return ( ); })} ))}
股票 {d.slice(5)} 题材数 最近上榜 上榜
{s.stockName} {s.stockCode} {formatGain(g)} {s.coverCount ?? "·"} {s.lastAppear ? s.lastAppear.slice(5) : "·"} {s.appearCount}
所属题材
{s.themes && s.themes.length > 0 ? (
{s.themes.map((t) => ( {t.theme_name} ))}
) : ( 暂无题材数据 )}
)}
); }