fix(kline): align intraday prefetch with rendering (live & effective days)

Rebase 到最新 main 后,按 review 提的两点把邻股预取与真实渲染路径对齐:

- 邻股预取当日最新分时补 live=true: 与 StockMultiDayIntradayChart 的 latest 同读
  实时源,盘中切股不回落分钟增量落盘的旧本地分区 (历史日期后端自行忽略 live)
- StockPanel 两处预取 days 改用 effectiveIntradayDays, 与多日图实际渲染周期一致,
  range 预取 queryKey 命中, 切换分时 tab 即时有数据
- 附带清理 rebase 冲突解析产生的残留右括号与冗余注释

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
richard
2026-09-02 13:25:06 +08:00
co-authored by Claude
parent 6964e1b5c9
commit 0a11bb870e
4 changed files with 7 additions and 8 deletions
@@ -131,7 +131,6 @@ export function StockDailyKChart({
const dateRange = externalDateRange ?? getDefaultRange()
// 查询配置统一来自 klineDailyQueryOptions, 与 StockPanel 信息条/邻近预取共享同一 cache key (只发一次请求)
// 上游新增的 refetchIntervalMs(个股对话框盘中实时刷新今日蜡烛) 补挂在工厂配置之上
const kline = useQuery({ ...klineDailyQueryOptions(symbol, dateRange, extColumns), enabled: !!symbol, refetchInterval: refetchIntervalMs })
const rows = useMemo(() => toOHLC(kline.data?.rows ?? []), [kline.data?.rows])
+3 -2
View File
@@ -135,7 +135,8 @@ export function StockPanel({
}
// 分时 tab 的多日分时 + 最新分时: 切股后分时图也免 loading (与日K并行预取)
qc.prefetchQuery({ ...klineMinuteRangeQueryOptions(s, intradayDays), staleTime: 30_000 })
qc.prefetchQuery({ ...klineMinuteQueryOptions(s), staleTime: 30_000 })
// latest 当日分时同样 live=true: 预取与渲染同读实时源 (历史日期后端忽略 live)
qc.prefetchQuery({ ...klineMinuteQueryOptions(s, undefined, true), staleTime: 30_000 })
// 日K用 fetchQuery (返回数据) 以便级联预取分时; 邻股预取失败静默, 不影响切股。
void qc.fetchQuery({ ...klineDailyQueryOptions(s, dateRange, extColumns), staleTime: 30_000 })
.then((res) => {
@@ -144,7 +145,7 @@ export function StockPanel({
const lastDate = res?.rows?.at(-1)?.date
if (lastDate) {
const d = String(lastDate).slice(0, 10)
// live=true: 若 d 为当日, 预取即命中实时源, 与实际渲染的 queryKey 同源 (历史日期后端忽略 live)
// 同上 live=true: 该日若为当日即命中实时源 (历史日期后端忽略 live)
qc.prefetchQuery({ ...klineMinuteQueryOptions(s, d, true), staleTime: 30_000 })
}
})
@@ -86,7 +86,6 @@ function loadIntradayDays(): number {
? saved
: DEFAULT_INTRADAY_DAYS
}
}
function boardTag(symbol: string): { label: string; color: string } | null {
if (/^(300|301)/.test(symbol)) return { label: '创', color: 'text-[#f97316] bg-[#f97316]/12 border-[#f97316]/25' }
@@ -614,7 +613,7 @@ export function StockPreviewDialog({ symbol, name, onClose, triggerInfo, navList
onPriceDoubleClick={openPriceAlert}
refetchIntervalMs={intradayRefetchMs}
prefetchSymbols={prefetchSymbols}
intradayDays={intradayDays}
intradayDays={effectiveIntradayDays}
dailyKlineFlex="flex-[1.4]"
/>
) : (
@@ -624,7 +623,7 @@ export function StockPreviewDialog({ symbol, name, onClose, triggerInfo, navList
dateRange={dateRange}
infoBarOnly
prefetchSymbols={prefetchSymbols}
intradayDays={intradayDays}
intradayDays={effectiveIntradayDays}
/>
<StockMultiDayIntradayChart
symbol={symbol}
+2 -2
View File
@@ -32,8 +32,8 @@ export function klineDailyQueryOptions(
/**
* 单日分时查询配置 — 与 klineDailyQueryOptions 同风格的单源 options (date 为空 = 最新日内)。
*
* live 透传上游语义: 当日盘中传 true 后端直接实时拉取最新K (不被分钟增量落盘的本地分区拖慢);
* 历史日期后端自行忽略 live, 所以预取/多日图恒传 true 也不会影响历史读取。
* live 仅当日盘中生效: 传 true 后端实时拉取最新K, 不被分钟增量落盘(≥60s 一轮)拖慢;
* 历史日期后端自行忽略 live, 故多日图与预取恒传 true 亦不影响历史读取。
*/
export function klineMinuteQueryOptions(symbol: string, date?: string, live?: boolean) {
return {