修复总市值显示错误 & 板块切换数据合并问题

1. 后端: 修正腾讯API字段索引偏移 (total_market_cap [43]→[45],
   pb [45]→[46]),并处理市值单位转换(亿→元)
2. 前端: 板块切换时同步清空旧数据 + 显示加载态,避免新旧
   数据合并闪现

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Sakurasan
2026-07-13 20:07:21 +08:00
co-authored by Claude
parent aaa618b15d
commit 20b2afb0fc
2 changed files with 13 additions and 6 deletions
+6 -5
View File
@@ -142,11 +142,11 @@ async def fetch_quote(code: str) -> Optional[dict]:
return None
text = resp.content.decode("gbk", errors="replace")
parts = parse_tencent_data(text)
if not parts or len(parts) < 46:
if not parts or len(parts) < 47:
return None
# 字段索引:1=名称, 3=当前价, 4=昨收, 5=今开, 6=成交量(手)
# 7=外盘, 8=内盘, 31=涨跌额, 32=涨跌幅%, 33=最高, 34=最低, 37=成交额(万)
# 38=换手率%, 39=市盈率, 43=总市值, 44=流通市值, 45=市净率
# 38=换手率%, 39=市盈率, 43=振幅%, 44=流通市值(亿), 45=总市值(亿), 46=市净率
name = parts[1] or ""
current_price = float(parts[3]) if parts[3] else 0
yesterday_close = float(parts[4]) if parts[4] else 0
@@ -161,9 +161,10 @@ async def fetch_quote(code: str) -> Optional[dict]:
inner_disk = float(parts[8]) if parts[8] else 0
turnover_rate = float(parts[38]) if parts[38] else 0 # 换手率%
pe = float(parts[39]) if parts[39] else 0 # 市盈率
total_market_cap = float(parts[43]) if parts[43] else 0 # 总市值
circulating_market_cap = float(parts[44]) if parts[44] else 0 # 流通市值
pb = float(parts[45]) if parts[45] else 0 # 市净率
# 腾讯API返回的市值单位是亿, formatMoney期望元, 需×1e8
total_market_cap = float(parts[45]) * 1e8 if parts[45] else 0 # 总市值(亿→元)
circulating_market_cap = float(parts[44]) * 1e8 if parts[44] else 0 # 流通市值(亿→元)
pb = float(parts[46]) if parts[46] else 0 # 市净率
if not name or current_price == 0:
return None
+7 -1
View File
@@ -75,7 +75,13 @@ function SectorsPage() {
{TABS.map((t) => (
<button
key={t.key}
onClick={() => setTab(t.key)}
onClick={() => {
if (t.key !== tab) {
setData([]);
setLoading(true);
setTab(t.key);
}
}}
className={`flex-1 py-1.5 text-sm font-medium rounded-md transition-colors ${
tab === t.key
? "bg-background text-foreground shadow-sm"