import type { Artist } from "@/types/artist"; import { cn } from "@/lib/cn"; interface RankCardProps { artist: Artist; /** 全榜单(用于计算与上下名的差距) */ allArtists: Artist[]; className?: string; } export default function RankCard({ artist, allArtists, className }: RankCardProps) { // 按当前票数排序后定位艺人 const sorted = [...allArtists].sort((a, b) => b.votes - a.votes); const idx = sorted.findIndex((a) => a.id === artist.id); const prev = idx > 0 ? sorted[idx - 1] : undefined; const next = idx < sorted.length - 1 ? sorted[idx + 1] : undefined; const leadOver = next ? artist.votes - next.votes : null; const trailBehind = prev ? prev.votes - artist.votes : null; const isFirst = artist.rank === 1; const inTop12 = artist.rank <= 12; return (
{/* 当前排名 */}
当前排名
#{artist.rank} {(artist.votes / 10000).toFixed(1)}w 票
{inTop12 && ( ✦ 出道位 )}
{/* 差距信息 */}
{isFirst && leadOver != null ? ( <>
领先第二名
+{leadOver.toLocaleString()}
) : trailBehind != null ? ( <>
距上一名
−{trailBehind.toLocaleString()}
) : null}
); }