'use client'; import { useGameStore } from '@/store/gameStore'; interface StockHeaderProps { cursorData?: any; } export default function StockHeader({ cursorData }: StockHeaderProps) { const { isRevealed, realCode, realName, allKlines, currentIndex } = useGameStore(); const currentKLine = allKlines[currentIndex]; if (!currentKLine) return
; // 优先使用光标数据,否则使用当前进度数据 const data = cursorData || currentKLine; const { open, high, low, close, volume, pct_chg, date, volume_ratio, turnover_rate } = data; // 如果是光标数据,可能没有 pct_chg,需要计算(相对于前一根K线,或者简化处理) // 这里简化处理:如果是光标数据,pct_chg 可能不准确,除非我们传入了完整对象 // 为了展示一致性,我们假设 data 包含了必要字段 // 注意:Chart 传回来的 cursorData 可能只包含 OHLCV,没有 pct_chg // 如果没有 pct_chg,我们可以根据 open/close 计算一个近似值,或者不显示涨跌幅 const isUp = close >= open; // 简化判断:阳线为红,阴线为绿 const colorClass = isUp ? 'text-[#FD1050]' : 'text-[#00F0F0]'; const change = close - open; // 这是一个近似值,实际上应该是 close - prevClose const changePercent = (change / open) * 100; // 近似涨跌幅 // 如果是真实数据(非光标),使用精确值 const displayChange = cursorData ? change : (close - (close / (1 + (pct_chg || 0) / 100))); const displayPercent = cursorData ? changePercent : pct_chg; // 日期显示 const displayDate = date || (cursorData?.time ? cursorData.time.toString() : '--'); // 日期显示格式化: 2026-02-23 -> 2026/02/23 const formattedDate = (displayDate && displayDate !== '--') ? displayDate.replace(/-/g, '/') : '--'; return (