fix: change_pct 统一按小数存储并前端乘以100展示

This commit is contained in:
2026-07-04 11:06:41 +08:00
parent 5bf4949999
commit 2d967f21ec
2 changed files with 6 additions and 5 deletions
+3 -2
View File
@@ -38,13 +38,14 @@ type Quote struct {
} `json:"ext"` } `json:"ext"`
} }
// ChangePct 优先使用 ext.change_pct,否则根据 close/prev_close 计算。 // ChangePct 优先使用 ext.change_pcttickflow 返回小数,如 0.30 = 30%),
// 否则根据 close/prev_close 计算并统一返回小数形式。
func (q *Quote) ChangePct() float64 { func (q *Quote) ChangePct() float64 {
if q.Ext.ChangePct != 0 { if q.Ext.ChangePct != 0 {
return q.Ext.ChangePct return q.Ext.ChangePct
} }
if q.PrevClose != 0 { if q.PrevClose != 0 {
return (q.Close - q.PrevClose) / q.PrevClose * 100 return (q.Close - q.PrevClose) / q.PrevClose
} }
return 0 return 0
} }
+3 -3
View File
@@ -133,7 +133,7 @@ export function StockOverview({ role }: StockOverviewProps) {
<KpiCard <KpiCard
icon={<Activity className="h-4 w-4 text-accent" />} icon={<Activity className="h-4 w-4 text-accent" />}
label="平均涨跌" label="平均涨跌"
value={`${avg_change_pct >= 0 ? '+' : ''}${avg_change_pct.toFixed(2)}%`} value={`${avg_change_pct >= 0 ? '+' : ''}${(avg_change_pct * 100).toFixed(2)}%`}
valueClass={avg_change_pct >= 0 ? 'text-bull' : 'text-bear'} valueClass={avg_change_pct >= 0 ? 'text-bull' : 'text-bear'}
/> />
</div> </div>
@@ -186,7 +186,7 @@ function IndexCard({ item }: { item: StockRow }) {
{item.close.toFixed(2)} {item.close.toFixed(2)}
</div> </div>
<div className={cn('text-xs font-medium', positive ? 'text-bull' : 'text-bear')}> <div className={cn('text-xs font-medium', positive ? 'text-bull' : 'text-bear')}>
{positive ? '+' : ''}{item.change_pct.toFixed(2)}% {positive ? '+' : ''}{(item.change_pct * 100).toFixed(2)}%
</div> </div>
</div> </div>
) )
@@ -209,7 +209,7 @@ function StockList({
<div className="text-xs text-muted py-2"></div> <div className="text-xs text-muted py-2"></div>
) : ( ) : (
rows.map((item, idx) => { rows.map((item, idx) => {
const val = valueKey === 'amount' ? (item.amount ?? 0) / 1e8 : item.change_pct const val = valueKey === 'amount' ? (item.amount ?? 0) / 1e8 : item.change_pct * 100
const isPositive = valueKey === 'amount' ? true : item.change_pct >= 0 const isPositive = valueKey === 'amount' ? true : item.change_pct >= 0
return ( return (
<div key={item.symbol} className="flex items-center justify-between text-sm py-1"> <div key={item.symbol} className="flex items-center justify-between text-sm py-1">