From 3bfeb81c90e34759ad7b00b2d2b0be707b0ddcfd Mon Sep 17 00:00:00 2001 From: Sakurasan <26715255+Sakurasan@users.noreply.github.com> Date: Mon, 13 Jul 2026 21:15:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9D=BF=E5=9D=97=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E6=95=B0=E6=8D=AE=E5=90=88=E5=B9=B6=EF=BC=9A=E7=A6=81?= =?UTF-8?q?=E6=AD=A2=20API=20=E5=93=8D=E5=BA=94=E7=BC=93=E5=AD=98=EF=BC=88?= =?UTF-8?q?=E5=8F=8D=E4=BB=A3=E6=8C=89=20path=20=E5=BF=BD=E7=95=A5=20query?= =?UTF-8?q?=20=E5=AF=BC=E8=87=B4=E4=B8=A4=E4=B8=AA=20tab=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9B=B8=E5=90=8C=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/routes/sectors.py | 20 +++++++++++++++++--- src/lib/stock-api.ts | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/backend/routes/sectors.py b/backend/routes/sectors.py index d5f112b..5e10e76 100644 --- a/backend/routes/sectors.py +++ b/backend/routes/sectors.py @@ -1,10 +1,15 @@ """板块数据路由:行业板块、概念板块""" from fastapi import APIRouter, Query, HTTPException +from fastapi.responses import JSONResponse from services import eastmoney, mootdx router = APIRouter() +# 行业/概念通过 query 参数区分,但上游反代/CDN 可能按 path 缓存而忽略 query, +# 导致两个 tab 返回相同数据。显式禁止缓存,保证按 query 区分。 +_NO_CACHE_HEADERS = {"Cache-Control": "no-store, no-cache, must-revalidate, max-age=0"} + @router.get("", summary="板块列表") async def sector_list( @@ -15,11 +20,20 @@ async def sector_list( data = await eastmoney.fetch_sector_list(type) if data: - return {"data": data, "count": len(data), "type": type} + return JSONResponse( + {"data": data, "count": len(data), "type": type}, + headers=_NO_CACHE_HEADERS, + ) # 降级:通达信 mootdx(不含实时资金流数据) md_data = await mootdx.fetch_sector_list(type) if md_data: - return {"data": md_data, "count": len(md_data), "type": type, "source": "mootdx"} + return JSONResponse( + {"data": md_data, "count": len(md_data), "type": type, "source": "mootdx"}, + headers=_NO_CACHE_HEADERS, + ) - return {"data": [], "count": 0, "type": type} + return JSONResponse( + {"data": [], "count": 0, "type": type}, + headers=_NO_CACHE_HEADERS, + ) diff --git a/src/lib/stock-api.ts b/src/lib/stock-api.ts index 52d124f..a334065 100755 --- a/src/lib/stock-api.ts +++ b/src/lib/stock-api.ts @@ -468,7 +468,7 @@ export async function fetchSectors(type: SectorType, signal?: AbortSignal): Prom const url = `${baseUrl}/api/sectors?type=${type}`; try { - const resp = await fetch(url, { method: "GET", signal }); + const resp = await fetch(url, { method: "GET", signal, cache: "no-store" }); if (!resp.ok) return []; const result: SectorResponse = await resp.json(); return result.data || [];