mirror of
https://ghfast.top/https://github.com/aeroxw/tick-stock-panel.git
synced 2026-09-12 19:04:15 +08:00
fix: 扩展数据拉取修复与连板梯队queryKey修复
This commit is contained in:
@@ -575,6 +575,13 @@ def configure_pull(request: Request, config_id: str, body: PullConfigReq):
|
|||||||
# 刷新调度器
|
# 刷新调度器
|
||||||
pull_scheduler.refresh(_data_dir(request))
|
pull_scheduler.refresh(_data_dir(request))
|
||||||
|
|
||||||
|
# 关闭定时拉取时清理残留的 next_run, 避免前端展示一个永不执行的"下次"
|
||||||
|
if not config.pull.enabled:
|
||||||
|
cleared = store.get(config_id)
|
||||||
|
if cleared and cleared.pull and cleared.pull.next_run:
|
||||||
|
cleared.pull.next_run = None
|
||||||
|
store.upsert(cleared)
|
||||||
|
|
||||||
return {"status": "ok", "pull": config.pull.to_dict()}
|
return {"status": "ok", "pull": config.pull.to_dict()}
|
||||||
|
|
||||||
|
|
||||||
@@ -630,8 +637,25 @@ async def run_pull(request: Request, config_id: str):
|
|||||||
try:
|
try:
|
||||||
n, d = await fetch_and_ingest(config, _data_dir(request))
|
n, d = await fetch_and_ingest(config, _data_dir(request))
|
||||||
_refresh_views(request)
|
_refresh_views(request)
|
||||||
|
# 写回执行状态, 让前端"上次执行"面板立即反映
|
||||||
|
updated = store.get(config_id)
|
||||||
|
if updated and updated.pull:
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
updated.pull.last_run = datetime.now(timezone.utc).isoformat()
|
||||||
|
updated.pull.last_status = "success"
|
||||||
|
updated.pull.last_message = f"{n} rows @ {d}"
|
||||||
|
updated.pull.last_rows = n
|
||||||
|
store.upsert(updated)
|
||||||
return {"status": "ok", "rows": n, "date": d}
|
return {"status": "ok", "rows": n, "date": d}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
# 失败也写回状态, 记录错误信息
|
||||||
|
failed = store.get(config_id)
|
||||||
|
if failed and failed.pull:
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
failed.pull.last_run = datetime.now(timezone.utc).isoformat()
|
||||||
|
failed.pull.last_status = "error"
|
||||||
|
failed.pull.last_message = str(e)[:200]
|
||||||
|
store.upsert(failed)
|
||||||
raise HTTPException(400, f"拉取失败: {e}") from e
|
raise HTTPException(400, f"拉取失败: {e}") from e
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class PullConfig:
|
|||||||
"url", "method", "headers", "body", "response_path",
|
"url", "method", "headers", "body", "response_path",
|
||||||
"field_map", "schedule_minutes", "enabled",
|
"field_map", "schedule_minutes", "enabled",
|
||||||
"last_run", "last_status", "last_message", "last_rows",
|
"last_run", "last_status", "last_message", "last_rows",
|
||||||
|
"next_run",
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -54,6 +55,7 @@ class PullConfig:
|
|||||||
last_status: str | None = None,
|
last_status: str | None = None,
|
||||||
last_message: str | None = None,
|
last_message: str | None = None,
|
||||||
last_rows: int | None = None,
|
last_rows: int | None = None,
|
||||||
|
next_run: str | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.url = url
|
self.url = url
|
||||||
self.method = method # GET | POST
|
self.method = method # GET | POST
|
||||||
@@ -67,6 +69,7 @@ class PullConfig:
|
|||||||
self.last_status = last_status # "success" | "error"
|
self.last_status = last_status # "success" | "error"
|
||||||
self.last_message = last_message
|
self.last_message = last_message
|
||||||
self.last_rows = last_rows
|
self.last_rows = last_rows
|
||||||
|
self.next_run = next_run # 下次预计运行 (ISO, 调度器写入)
|
||||||
|
|
||||||
def to_dict(self) -> dict:
|
def to_dict(self) -> dict:
|
||||||
return {
|
return {
|
||||||
@@ -82,6 +85,7 @@ class PullConfig:
|
|||||||
"last_status": self.last_status,
|
"last_status": self.last_status,
|
||||||
"last_message": self.last_message,
|
"last_message": self.last_message,
|
||||||
"last_rows": self.last_rows,
|
"last_rows": self.last_rows,
|
||||||
|
"next_run": self.next_run,
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -101,6 +105,7 @@ class PullConfig:
|
|||||||
last_status=d.get("last_status"),
|
last_status=d.get("last_status"),
|
||||||
last_message=d.get("last_message"),
|
last_message=d.get("last_message"),
|
||||||
last_rows=d.get("last_rows"),
|
last_rows=d.get("last_rows"),
|
||||||
|
next_run=d.get("next_run"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -407,8 +412,10 @@ def write_ext_parquet(
|
|||||||
existing = pl.read_parquet(out_path)
|
existing = pl.read_parquet(out_path)
|
||||||
key = "symbol" if "symbol" in df.columns else df.columns[0]
|
key = "symbol" if "symbol" in df.columns else df.columns[0]
|
||||||
df = pl.concat([existing, df]).unique(subset=[key], keep="last")
|
df = pl.concat([existing, df]).unique(subset=[key], keep="last")
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
# schema 不一致 (列不同) 时 concat 失败 → 直接用新 df 覆盖。
|
||||||
|
# 记日志而非静默吞掉, 便于排查"数据结构错乱"类问题。
|
||||||
|
logger.warning("扩展表 %s 合并去重失败, 将覆盖写入: %s", config.id, e)
|
||||||
else:
|
else:
|
||||||
# 时序: timeseries/ 下按日期分区
|
# 时序: timeseries/ 下按日期分区
|
||||||
out_dir = cfg_dir / "timeseries" / f"date={snap}"
|
out_dir = cfg_dir / "timeseries" / f"date={snap}"
|
||||||
@@ -421,8 +428,8 @@ def write_ext_parquet(
|
|||||||
existing = pl.read_parquet(out_path)
|
existing = pl.read_parquet(out_path)
|
||||||
key = "symbol" if "symbol" in df.columns else df.columns[0]
|
key = "symbol" if "symbol" in df.columns else df.columns[0]
|
||||||
df = pl.concat([existing, df]).unique(subset=[key], keep="last")
|
df = pl.concat([existing, df]).unique(subset=[key], keep="last")
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
logger.warning("扩展表 %s 合并去重失败, 将覆盖写入: %s", config.id, e)
|
||||||
|
|
||||||
df = cast_df_to_schema(df, config.fields)
|
df = cast_df_to_schema(df, config.fields)
|
||||||
df.write_parquet(out_path)
|
df.write_parquet(out_path)
|
||||||
|
|||||||
@@ -75,6 +75,19 @@ def _apply_field_map(rows: list[dict], field_map: dict[str, str]) -> list[dict]:
|
|||||||
# 拉取执行
|
# 拉取执行
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def _apply_preset_flatten(config_id: str, rows: list[dict]) -> list[dict]:
|
||||||
|
"""对内置预设 (概念/行业) 应用结构转换, 与 fetch_preset 保持一致。
|
||||||
|
|
||||||
|
延迟导入避免与 ext_presets 形成循环依赖。
|
||||||
|
非预设 id 原样返回。
|
||||||
|
"""
|
||||||
|
if config_id not in ("ext_gn_ths", "ext_hy_ths"):
|
||||||
|
return rows
|
||||||
|
from app.services.ext_presets import _flatten_concept_rows, _flatten_industry_rows
|
||||||
|
flatten = _flatten_concept_rows if config_id == "ext_gn_ths" else _flatten_industry_rows
|
||||||
|
return flatten(rows)
|
||||||
|
|
||||||
|
|
||||||
async def fetch_and_ingest(
|
async def fetch_and_ingest(
|
||||||
config: ExtConfig,
|
config: ExtConfig,
|
||||||
data_dir,
|
data_dir,
|
||||||
@@ -111,6 +124,12 @@ async def fetch_and_ingest(
|
|||||||
if not rows:
|
if not rows:
|
||||||
raise ValueError("提取到的行数为 0")
|
raise ValueError("提取到的行数为 0")
|
||||||
|
|
||||||
|
# 内置预设 (概念/行业): 应用结构转换, 让产出 schema 与分析页一致。
|
||||||
|
# 否则 raw 接口列 (concepts/industries 数组、name) 会直接覆盖正确的 part.parquet,
|
||||||
|
# 导致分析页因找不到维度字段 (所属概念/所属同花顺行业) 而"数据消失"。
|
||||||
|
# 见 ext_presets._flatten_* —— 手动拉取 / 定时拉取都必须走同一套转换。
|
||||||
|
rows = _apply_preset_flatten(config.id, rows)
|
||||||
|
|
||||||
# 字段映射
|
# 字段映射
|
||||||
rows = _apply_field_map(rows, pull.field_map)
|
rows = _apply_field_map(rows, pull.field_map)
|
||||||
|
|
||||||
@@ -129,21 +148,46 @@ async def fetch_and_ingest(
|
|||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
class PullScheduler:
|
class PullScheduler:
|
||||||
"""后台调度器:为每个启用了 pull 的 ExtConfig 维护定时任务。"""
|
"""后台调度器:为每个启用了 pull 的 ExtConfig 维护定时任务。
|
||||||
|
|
||||||
|
线程安全说明:
|
||||||
|
refresh()/stop() 可能从主事件循环 (lifespan startup) 或同步路由的
|
||||||
|
worker 线程 (configure_pull 是 def 而非 async def, FastAPI 丢进线程池)
|
||||||
|
调用。worker 线程里没有 running loop, 直接 asyncio.create_task 会抛
|
||||||
|
"no running event loop"。因此对 task 的增删一律通过
|
||||||
|
call_soon_threadsafe 提交到主循环执行 —— 同一套代码两种调用场景都安全。
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self._tasks: dict[str, asyncio.Task] = {}
|
self._tasks: dict[str, asyncio.Task] = {}
|
||||||
self._running = False
|
self._running = False
|
||||||
self._lock = threading.Lock()
|
self._loop: asyncio.AbstractEventLoop | None = None
|
||||||
|
|
||||||
def start(self, data_dir) -> None:
|
def start(self, data_dir) -> None:
|
||||||
"""启动调度(在 lifespan startup 调用)。"""
|
"""启动调度(在 lifespan startup 调用,主事件循环内)。"""
|
||||||
self._running = True
|
self._running = True
|
||||||
self._data_dir = data_dir
|
self._data_dir = data_dir
|
||||||
|
try:
|
||||||
|
self._loop = asyncio.get_running_loop()
|
||||||
|
except RuntimeError:
|
||||||
|
self._loop = None
|
||||||
logger.info("PullScheduler started")
|
logger.info("PullScheduler started")
|
||||||
|
|
||||||
|
def _submit(self, fn, *args) -> None:
|
||||||
|
"""把一个 callable 提交到主事件循环执行 (线程安全)。
|
||||||
|
|
||||||
|
startup 在主循环内调用时 fn 立即排队; worker 线程调用时跨线程排队。
|
||||||
|
两者都通过 call_soon_threadsafe, 保证 _tasks 字典的读写只在主循环里发生。
|
||||||
|
"""
|
||||||
|
loop = self._loop
|
||||||
|
if loop is None or loop.is_closed():
|
||||||
|
raise RuntimeError(
|
||||||
|
"PullScheduler: 事件循环不可用 (start() 未在事件循环中调用?)"
|
||||||
|
)
|
||||||
|
loop.call_soon_threadsafe(fn, *args)
|
||||||
|
|
||||||
def stop(self) -> None:
|
def stop(self) -> None:
|
||||||
"""停止所有任务。"""
|
"""停止所有任务 (从 shutdown 调用)。"""
|
||||||
self._running = False
|
self._running = False
|
||||||
for task in self._tasks.values():
|
for task in self._tasks.values():
|
||||||
task.cancel()
|
task.cancel()
|
||||||
@@ -151,47 +195,61 @@ class PullScheduler:
|
|||||||
logger.info("PullScheduler stopped")
|
logger.info("PullScheduler stopped")
|
||||||
|
|
||||||
def refresh(self, data_dir) -> None:
|
def refresh(self, data_dir) -> None:
|
||||||
"""重新加载配置,更新调度任务(增/删/改)。"""
|
"""重新加载配置,更新调度任务(增/删/改)。线程安全。"""
|
||||||
self._data_dir = data_dir
|
self._data_dir = data_dir
|
||||||
store = ExtConfigStore(data_dir)
|
store = ExtConfigStore(data_dir)
|
||||||
configs = store.load_all()
|
configs = store.load_all()
|
||||||
|
|
||||||
active_ids: set[str] = set()
|
active_ids: set[str] = set()
|
||||||
|
new_configs: list[ExtConfig] = []
|
||||||
|
|
||||||
for config in configs:
|
for config in configs:
|
||||||
if not config.pull or not config.pull.enabled or not config.pull.url:
|
if not config.pull or not config.pull.enabled or not config.pull.url:
|
||||||
continue
|
continue
|
||||||
active_ids.add(config.id)
|
active_ids.add(config.id)
|
||||||
if config.id not in self._tasks:
|
if config.id not in self._tasks:
|
||||||
# 新增调度
|
new_configs.append(config)
|
||||||
task = asyncio.create_task(self._run_loop(config))
|
|
||||||
self._tasks[config.id] = task
|
|
||||||
logger.info("PullScheduler: scheduled %s (every %d min)", config.id, config.pull.schedule_minutes)
|
|
||||||
|
|
||||||
# 移除不再活跃的
|
# 需要移除的 id (快照当前 task 字典的键, 避免遍历时改字典)
|
||||||
for cid in list(self._tasks):
|
remove_ids = [cid for cid in list(self._tasks) if cid not in active_ids]
|
||||||
if cid not in active_ids:
|
|
||||||
self._tasks[cid].cancel()
|
# 所有对 _tasks 的修改都提交到主循环里执行, 保证线程安全
|
||||||
del self._tasks[cid]
|
def _apply() -> None:
|
||||||
logger.info("PullScheduler: removed %s", cid)
|
for config in new_configs:
|
||||||
|
if config.id not in self._tasks: # 二次校验, 防重复
|
||||||
|
self._tasks[config.id] = self._loop.create_task(
|
||||||
|
self._run_loop(config)
|
||||||
|
)
|
||||||
|
logger.info(
|
||||||
|
"PullScheduler: scheduled %s (every %d min)",
|
||||||
|
config.id, config.pull.schedule_minutes,
|
||||||
|
)
|
||||||
|
for cid in remove_ids:
|
||||||
|
task = self._tasks.pop(cid, None)
|
||||||
|
if task is not None:
|
||||||
|
task.cancel()
|
||||||
|
logger.info("PullScheduler: removed %s", cid)
|
||||||
|
|
||||||
|
self._submit(_apply)
|
||||||
|
|
||||||
async def _run_loop(self, config: ExtConfig) -> None:
|
async def _run_loop(self, config: ExtConfig) -> None:
|
||||||
"""单个配置的定时拉取循环。"""
|
"""单个配置的定时拉取循环。
|
||||||
|
|
||||||
|
策略: 启用后立即执行一次, 之后按 interval 循环。
|
||||||
|
每次循环重读最新配置 (fresh), interval 取自 fresh.pull.schedule_minutes,
|
||||||
|
这样用户中途修改间隔也能立即生效 (无需重启)。
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
while self._running:
|
while self._running:
|
||||||
pull = config.pull
|
# 每轮重读最新配置 — 用户可能修改了 url / interval / enabled
|
||||||
if not pull:
|
store = ExtConfigStore(self._data_dir)
|
||||||
break
|
fresh = store.get(config.id)
|
||||||
interval = max(pull.schedule_minutes * 60, 60) # 至少 60s
|
if not fresh or not fresh.pull or not fresh.pull.enabled:
|
||||||
await asyncio.sleep(interval)
|
|
||||||
if not self._running:
|
|
||||||
break
|
break
|
||||||
|
pull = fresh.pull
|
||||||
|
|
||||||
|
# 先执行一次 (启用即拉取, 让用户立刻看到生效)
|
||||||
try:
|
try:
|
||||||
# 重新加载最新配置(用户可能中途修改)
|
|
||||||
store = ExtConfigStore(self._data_dir)
|
|
||||||
fresh = store.get(config.id)
|
|
||||||
if not fresh or not fresh.pull or not fresh.pull.enabled:
|
|
||||||
break
|
|
||||||
n, d = await fetch_and_ingest(fresh, self._data_dir)
|
n, d = await fetch_and_ingest(fresh, self._data_dir)
|
||||||
fresh.pull.last_run = datetime.now(timezone.utc).isoformat()
|
fresh.pull.last_run = datetime.now(timezone.utc).isoformat()
|
||||||
fresh.pull.last_status = "success"
|
fresh.pull.last_status = "success"
|
||||||
@@ -200,14 +258,79 @@ class PullScheduler:
|
|||||||
store.upsert(fresh)
|
store.upsert(fresh)
|
||||||
logger.info("PullScheduler: %s success, %d rows", config.id, n)
|
logger.info("PullScheduler: %s success, %d rows", config.id, n)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
store = ExtConfigStore(self._data_dir)
|
fresh2 = store.get(config.id)
|
||||||
fresh = store.get(config.id)
|
if fresh2 and fresh2.pull:
|
||||||
if fresh and fresh.pull:
|
fresh2.pull.last_run = datetime.now(timezone.utc).isoformat()
|
||||||
fresh.pull.last_run = datetime.now(timezone.utc).isoformat()
|
fresh2.pull.last_status = "error"
|
||||||
fresh.pull.last_status = "error"
|
fresh2.pull.last_message = str(e)[:200]
|
||||||
fresh.pull.last_message = str(e)[:200]
|
store.upsert(fresh2)
|
||||||
store.upsert(fresh)
|
|
||||||
logger.warning("PullScheduler: %s error: %s", config.id, e)
|
logger.warning("PullScheduler: %s error: %s", config.id, e)
|
||||||
|
|
||||||
|
# 间隔取自最新配置 (每次重新读取, 修复改间隔不生效)
|
||||||
|
interval = max(pull.schedule_minutes * 60, 60) # 至少 60s
|
||||||
|
# 预告下次运行时间, 供前端展示
|
||||||
|
next_dt = datetime.now(timezone.utc).timestamp() + interval
|
||||||
|
latest = store.get(config.id)
|
||||||
|
if latest and latest.pull:
|
||||||
|
latest.pull.next_run = datetime.fromtimestamp(
|
||||||
|
next_dt, tz=timezone.utc
|
||||||
|
).isoformat()
|
||||||
|
store.upsert(latest)
|
||||||
|
|
||||||
|
await asyncio.sleep(interval)
|
||||||
|
if not self._running:
|
||||||
|
break
|
||||||
|
except asyncio.CancelledError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def _run_loop(self, config: ExtConfig) -> None:
|
||||||
|
"""单个配置的定时拉取循环。
|
||||||
|
|
||||||
|
策略: 启用后立即执行一次, 之后按 interval 循环。
|
||||||
|
每次循环重读最新配置 (fresh), interval 取自 fresh.pull.schedule_minutes,
|
||||||
|
这样用户中途修改间隔也能立即生效 (无需重启)。
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
while self._running:
|
||||||
|
# 每轮重读最新配置 — 用户可能修改了 url / interval / enabled
|
||||||
|
store = ExtConfigStore(self._data_dir)
|
||||||
|
fresh = store.get(config.id)
|
||||||
|
if not fresh or not fresh.pull or not fresh.pull.enabled:
|
||||||
|
break
|
||||||
|
pull = fresh.pull
|
||||||
|
|
||||||
|
# 先执行一次 (启用即拉取, 让用户立刻看到生效)
|
||||||
|
try:
|
||||||
|
n, d = await fetch_and_ingest(fresh, self._data_dir)
|
||||||
|
fresh.pull.last_run = datetime.now(timezone.utc).isoformat()
|
||||||
|
fresh.pull.last_status = "success"
|
||||||
|
fresh.pull.last_message = f"{n} rows @ {d}"
|
||||||
|
fresh.pull.last_rows = n
|
||||||
|
store.upsert(fresh)
|
||||||
|
logger.info("PullScheduler: %s success, %d rows", config.id, n)
|
||||||
|
except Exception as e:
|
||||||
|
fresh2 = store.get(config.id)
|
||||||
|
if fresh2 and fresh2.pull:
|
||||||
|
fresh2.pull.last_run = datetime.now(timezone.utc).isoformat()
|
||||||
|
fresh2.pull.last_status = "error"
|
||||||
|
fresh2.pull.last_message = str(e)[:200]
|
||||||
|
store.upsert(fresh2)
|
||||||
|
logger.warning("PullScheduler: %s error: %s", config.id, e)
|
||||||
|
|
||||||
|
# 间隔取自最新配置 (每次重新读取, 修复改间隔不生效)
|
||||||
|
interval = max(pull.schedule_minutes * 60, 60) # 至少 60s
|
||||||
|
# 预告下次运行时间, 供前端展示
|
||||||
|
next_dt = datetime.now(timezone.utc).timestamp() + interval
|
||||||
|
latest = store.get(config.id)
|
||||||
|
if latest and latest.pull:
|
||||||
|
latest.pull.next_run = datetime.fromtimestamp(
|
||||||
|
next_dt, tz=timezone.utc
|
||||||
|
).isoformat()
|
||||||
|
store.upsert(latest)
|
||||||
|
|
||||||
|
await asyncio.sleep(interval)
|
||||||
|
if not self._running:
|
||||||
|
break
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { Loader2, Search, RefreshCw, Check } from 'lucide-react'
|
import { Loader2, Search, Check, Clock, Zap, Settings2, AlertCircle, CheckCircle2, Calendar } from 'lucide-react'
|
||||||
import { api, type ExtDataConfig } from '@/lib/api'
|
import { api, type ExtDataConfig } from '@/lib/api'
|
||||||
|
import { toast } from '@/components/Toast'
|
||||||
|
|
||||||
export function ExtDataPullPanel({ config, onSaved }: {
|
export function ExtDataPullPanel({ config, onSaved }: {
|
||||||
config: ExtDataConfig
|
config: ExtDataConfig
|
||||||
@@ -22,157 +23,284 @@ export function ExtDataPullPanel({ config, onSaved }: {
|
|||||||
const [saving, setSaving] = useState(false)
|
const [saving, setSaving] = useState(false)
|
||||||
const [testing, setTesting] = useState(false)
|
const [testing, setTesting] = useState(false)
|
||||||
const [running, setRunning] = useState(false)
|
const [running, setRunning] = useState(false)
|
||||||
|
const [runResult, setRunResult] = useState<{ rows: number; date: string } | null>(null)
|
||||||
const [testResult, setTestResult] = useState<{ total_rows: number; preview: Record<string, unknown>[]; has_symbol: boolean } | null>(null)
|
const [testResult, setTestResult] = useState<{ total_rows: number; preview: Record<string, unknown>[]; has_symbol: boolean } | null>(null)
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
|
|
||||||
const handleSave = () => {
|
// 解析 JSON 输入, 失败时设置 error 并返回 null
|
||||||
let headers: Record<string, string> | undefined
|
const parseJson = (str: string, label: string): Record<string, string> | undefined | null => {
|
||||||
if (headerStr.trim()) {
|
if (!str.trim()) return undefined
|
||||||
try { headers = JSON.parse(headerStr) }
|
try { return JSON.parse(str) }
|
||||||
catch { setError('Headers 不是有效 JSON'); return }
|
catch { setError(`${label} 不是有效 JSON`); return null }
|
||||||
}
|
}
|
||||||
let field_map: Record<string, string> | undefined
|
|
||||||
if (fieldMapStr.trim()) {
|
// 构建保存 payload (复用当前编辑态), enabledOverride 用于开关自动保存
|
||||||
try { field_map = JSON.parse(fieldMapStr) }
|
const buildPayload = (enabledOverride?: boolean) => {
|
||||||
catch { setError('字段映射不是有效 JSON'); return }
|
const headers = parseJson(headerStr, 'Headers')
|
||||||
}
|
if (headers === null) return null
|
||||||
setSaving(true); setError('')
|
const field_map = parseJson(fieldMapStr, '字段映射')
|
||||||
api.extDataPullConfig(config.id, {
|
if (field_map === null) return null
|
||||||
|
return {
|
||||||
url, method, headers, body: body || undefined,
|
url, method, headers, body: body || undefined,
|
||||||
response_path: responsePath, field_map,
|
response_path: responsePath, field_map,
|
||||||
schedule_minutes: schedule, enabled,
|
schedule_minutes: schedule, enabled: enabledOverride ?? enabled,
|
||||||
}).then(() => onSaved())
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSave = (silent = false) => {
|
||||||
|
const payload = buildPayload()
|
||||||
|
if (!payload) return
|
||||||
|
setSaving(true); setError('')
|
||||||
|
api.extDataPullConfig(config.id, payload)
|
||||||
|
.then(() => {
|
||||||
|
onSaved()
|
||||||
|
if (!silent) toast('配置已保存', 'success')
|
||||||
|
})
|
||||||
.catch(e => setError(e.message || '保存失败'))
|
.catch(e => setError(e.message || '保存失败'))
|
||||||
.finally(() => setSaving(false))
|
.finally(() => setSaving(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleTest = () => {
|
const handleTest = () => {
|
||||||
setTesting(true); setError(''); setTestResult(null)
|
setTesting(true); setError(''); setTestResult(null)
|
||||||
let headers: Record<string, string> | undefined
|
const payload = buildPayload()
|
||||||
if (headerStr.trim()) {
|
if (!payload) { setTesting(false); return }
|
||||||
try { headers = JSON.parse(headerStr) }
|
api.extDataPullConfig(config.id, payload)
|
||||||
catch { setError('Headers 不是有效 JSON'); setTesting(false); return }
|
.then(() => api.extDataPullTest(config.id))
|
||||||
}
|
|
||||||
let field_map: Record<string, string> | undefined
|
|
||||||
if (fieldMapStr.trim()) {
|
|
||||||
try { field_map = JSON.parse(fieldMapStr) }
|
|
||||||
catch { setError('字段映射不是有效 JSON'); setTesting(false); return }
|
|
||||||
}
|
|
||||||
api.extDataPullConfig(config.id, {
|
|
||||||
url, method, headers, body: body || undefined,
|
|
||||||
response_path: responsePath, field_map,
|
|
||||||
schedule_minutes: schedule, enabled,
|
|
||||||
}).then(() => api.extDataPullTest(config.id))
|
|
||||||
.then(r => { setTestResult(r); onSaved() })
|
.then(r => { setTestResult(r); onSaved() })
|
||||||
.catch(e => setError(e.message || '测试失败'))
|
.catch(e => setError(e.message || '测试失败'))
|
||||||
.finally(() => setTesting(false))
|
.finally(() => setTesting(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleRun = () => {
|
const handleRun = () => {
|
||||||
setRunning(true); setError('')
|
setRunning(true); setError(''); setRunResult(null)
|
||||||
api.extDataPullRun(config.id)
|
api.extDataPullRun(config.id)
|
||||||
.then(() => onSaved())
|
.then(r => {
|
||||||
|
setRunResult({ rows: r.rows, date: r.date })
|
||||||
|
onSaved()
|
||||||
|
toast(`拉取成功 · ${r.rows} 行`, 'success')
|
||||||
|
})
|
||||||
.catch(e => setError(e.message || '执行失败'))
|
.catch(e => setError(e.message || '执行失败'))
|
||||||
.finally(() => setRunning(false))
|
.finally(() => setRunning(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 开关 toggle: 自动保存全量配置 (切换 enabled), 后端 refresh 后立即首次拉取
|
||||||
|
const [toggling, setToggling] = useState(false)
|
||||||
|
const handleToggle = (next: boolean) => {
|
||||||
|
if (toggling) return
|
||||||
|
if (next && !url.trim()) {
|
||||||
|
toast('请先填写拉取 URL', 'error')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const payload = buildPayload(next)
|
||||||
|
if (!payload) return
|
||||||
|
setToggling(true); setError(''); setEnabled(next)
|
||||||
|
api.extDataPullConfig(config.id, payload)
|
||||||
|
.then(() => {
|
||||||
|
onSaved()
|
||||||
|
toast(next ? '定时拉取已启用 · 立即执行首次拉取' : '定时拉取已关闭', 'success')
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
setEnabled(!next) // 回滚
|
||||||
|
setError(e.message || '切换失败')
|
||||||
|
})
|
||||||
|
.finally(() => setToggling(false))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化时间显示
|
||||||
|
const fmtTime = (iso: string | null | undefined) => {
|
||||||
|
if (!iso) return null
|
||||||
|
const d = new Date(iso)
|
||||||
|
if (isNaN(d.getTime())) return null
|
||||||
|
const mm = String(d.getMonth() + 1).padStart(2, '0')
|
||||||
|
const dd = String(d.getDate()).padStart(2, '0')
|
||||||
|
const hh = String(d.getHours()).padStart(2, '0')
|
||||||
|
const mi = String(d.getMinutes()).padStart(2, '0')
|
||||||
|
return `${mm}-${dd} ${hh}:${mi}`
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2.5">
|
<div className="space-y-3">
|
||||||
<div className="flex gap-1.5">
|
{/* ===== 分区 ①: 请求配置 ===== */}
|
||||||
<select
|
<div className="space-y-2">
|
||||||
value={method} onChange={e => setMethod(e.target.value)}
|
<div className="flex items-center gap-1.5 text-[11px] font-medium text-secondary">
|
||||||
className="shrink-0 rounded-md border border-border bg-elevated px-2 py-1.5 text-[11px] text-foreground"
|
<Settings2 className="h-3 w-3 text-muted" />
|
||||||
>
|
<span>请求配置</span>
|
||||||
<option value="GET">GET</option>
|
</div>
|
||||||
<option value="POST">POST</option>
|
|
||||||
</select>
|
|
||||||
<input
|
|
||||||
value={url} onChange={e => setUrl(e.target.value)}
|
|
||||||
placeholder="https://api.example.com/data"
|
|
||||||
className="flex-1 min-w-0 rounded-md border border-border bg-elevated px-2.5 py-1.5 text-[11px] font-mono text-foreground placeholder:text-muted/50"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
<div className="flex gap-1.5">
|
||||||
<div className="text-[10px] text-muted mb-0.5">Headers (JSON,可选)</div>
|
<select
|
||||||
<textarea
|
value={method} onChange={e => setMethod(e.target.value)}
|
||||||
value={headerStr} onChange={e => setHeaderStr(e.target.value)}
|
className="shrink-0 rounded-btn border border-border bg-elevated px-2 py-1.5 text-[11px] text-foreground"
|
||||||
placeholder='{"Authorization": "Bearer xxx"}'
|
>
|
||||||
rows={2}
|
<option value="GET">GET</option>
|
||||||
className="w-full rounded-md border border-border bg-elevated px-2.5 py-1.5 text-[10px] font-mono text-foreground placeholder:text-muted/40 resize-none"
|
<option value="POST">POST</option>
|
||||||
/>
|
</select>
|
||||||
</div>
|
<input
|
||||||
|
value={url} onChange={e => setUrl(e.target.value)}
|
||||||
|
placeholder="https://api.example.com/data"
|
||||||
|
className="flex-1 min-w-0 rounded-btn border border-border bg-elevated px-2.5 py-1.5 text-[11px] font-mono text-foreground placeholder:text-muted/50"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{method === 'POST' && (
|
|
||||||
<div>
|
<div>
|
||||||
<div className="text-[10px] text-muted mb-0.5">请求体 (JSON,可选)</div>
|
<div className="text-[10px] text-muted mb-1">Headers (JSON,可选)</div>
|
||||||
<textarea
|
<textarea
|
||||||
value={body} onChange={e => setBody(e.target.value)}
|
value={headerStr} onChange={e => setHeaderStr(e.target.value)}
|
||||||
placeholder='{"page": 1}'
|
placeholder='{"Authorization": "Bearer xxx"}'
|
||||||
rows={2}
|
rows={2}
|
||||||
className="w-full rounded-md border border-border bg-elevated px-2.5 py-1.5 text-[10px] font-mono text-foreground placeholder:text-muted/40 resize-none"
|
className="w-full rounded-btn border border-border bg-elevated px-2.5 py-1.5 text-[10px] font-mono text-foreground placeholder:text-muted/40 resize-none"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="grid grid-cols-2 gap-2">
|
{method === 'POST' && (
|
||||||
<div>
|
<div>
|
||||||
<div className="text-[10px] text-muted mb-0.5">响应数据路径</div>
|
<div className="text-[10px] text-muted mb-1">请求体 (JSON,可选)</div>
|
||||||
<input
|
<textarea
|
||||||
value={responsePath} onChange={e => setResponsePath(e.target.value)}
|
value={body} onChange={e => setBody(e.target.value)}
|
||||||
placeholder="data.list"
|
placeholder='{"page": 1}'
|
||||||
className="w-full rounded-md border border-border bg-elevated px-2 py-1.5 text-[10px] font-mono text-foreground placeholder:text-muted/40"
|
rows={2}
|
||||||
/>
|
className="w-full rounded-btn border border-border bg-elevated px-2.5 py-1.5 text-[10px] font-mono text-foreground placeholder:text-muted/40 resize-none"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-2">
|
||||||
|
<div>
|
||||||
|
<div className="text-[10px] text-muted mb-1">响应数据路径</div>
|
||||||
|
<input
|
||||||
|
value={responsePath} onChange={e => setResponsePath(e.target.value)}
|
||||||
|
placeholder="data.list"
|
||||||
|
className="w-full rounded-btn border border-border bg-elevated px-2 py-1.5 text-[10px] font-mono text-foreground placeholder:text-muted/40"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className="text-[10px] text-muted mb-1">调度间隔 (分钟)</div>
|
||||||
|
<input
|
||||||
|
type="number" min={1} value={schedule} onChange={e => setSchedule(Number(e.target.value))}
|
||||||
|
className="w-full rounded-btn border border-border bg-elevated px-2 py-1.5 text-[10px] font-mono text-foreground"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div className="text-[10px] text-muted mb-0.5">调度间隔 (分钟)</div>
|
<div className="text-[10px] text-muted mb-1">字段映射 (外部名 → 内部名,JSON,可选)</div>
|
||||||
<input
|
<textarea
|
||||||
type="number" min={1} value={schedule} onChange={e => setSchedule(Number(e.target.value))}
|
value={fieldMapStr} onChange={e => setFieldMapStr(e.target.value)}
|
||||||
className="w-full rounded-md border border-border bg-elevated px-2 py-1.5 text-[10px] font-mono text-foreground"
|
placeholder='{"code": "symbol", "val": "score"}'
|
||||||
|
rows={2}
|
||||||
|
className="w-full rounded-btn border border-border bg-elevated px-2.5 py-1.5 text-[10px] font-mono text-foreground placeholder:text-muted/40 resize-none"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
{/* ===== 分区 ②: 定时拉取状态 ===== */}
|
||||||
<div className="text-[10px] text-muted mb-0.5">字段映射 (外部名 → 内部名,JSON,可选)</div>
|
<div className="rounded-card border border-border/60 bg-elevated/30 p-2.5 space-y-2">
|
||||||
<textarea
|
<div className="flex items-center justify-between">
|
||||||
value={fieldMapStr} onChange={e => setFieldMapStr(e.target.value)}
|
<div className="flex items-center gap-1.5 text-[11px] font-medium text-secondary">
|
||||||
placeholder='{"code": "symbol", "val": "score"}'
|
<Clock className="h-3 w-3 text-muted" />
|
||||||
rows={2}
|
<span>定时拉取</span>
|
||||||
className="w-full rounded-md border border-border bg-elevated px-2.5 py-1.5 text-[10px] font-mono text-foreground placeholder:text-muted/40 resize-none"
|
</div>
|
||||||
/>
|
{/* 自定义 Toggle 开关 */}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
role="switch"
|
||||||
|
aria-checked={enabled}
|
||||||
|
disabled={toggling}
|
||||||
|
onClick={() => handleToggle(!enabled)}
|
||||||
|
className={`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors duration-200 disabled:opacity-50 ${
|
||||||
|
enabled ? 'bg-accent' : 'bg-border'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className={`inline-block h-3 w-3 transform rounded-full bg-white shadow transition-transform duration-200 ${
|
||||||
|
enabled ? 'translate-x-3.5' : 'translate-x-0.5'
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 状态文案 */}
|
||||||
|
<div className="text-[10px] leading-relaxed">
|
||||||
|
{enabled ? (
|
||||||
|
<div className="space-y-0.5">
|
||||||
|
<div className="flex items-center gap-1 text-accent">
|
||||||
|
<span className="h-1 w-1 rounded-full bg-accent animate-pulse" />
|
||||||
|
<span>已启用 · 每 {schedule} 分钟</span>
|
||||||
|
</div>
|
||||||
|
{pull?.next_run && fmtTime(pull.next_run) && (
|
||||||
|
<div className="flex items-center gap-1 text-muted">
|
||||||
|
<Calendar className="h-2.5 w-2.5" />
|
||||||
|
<span>下次:{fmtTime(pull.next_run)}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="text-muted">未启用 · 仅手动执行</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 上次执行结果 */}
|
||||||
|
{pull?.last_run && (
|
||||||
|
<div className="flex items-start gap-1.5 pt-1.5 border-t border-border/40">
|
||||||
|
{pull.last_status === 'success' ? (
|
||||||
|
<CheckCircle2 className="h-3 w-3 text-emerald-500 shrink-0 mt-px" />
|
||||||
|
) : (
|
||||||
|
<AlertCircle className="h-3 w-3 text-danger shrink-0 mt-px" />
|
||||||
|
)}
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<div className={`text-[10px] font-medium ${pull.last_status === 'success' ? 'text-emerald-500' : 'text-danger'}`}>
|
||||||
|
{pull.last_message || (pull.last_status === 'success' ? '成功' : '失败')}
|
||||||
|
</div>
|
||||||
|
{fmtTime(pull.last_run) && (
|
||||||
|
<div className="text-[9px] text-muted">{fmtTime(pull.last_run)}</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center justify-between">
|
{/* ===== 分区 ③: 操作按钮 ===== */}
|
||||||
<label className="inline-flex items-center gap-1.5 cursor-pointer">
|
<div className="space-y-2">
|
||||||
<input
|
<div className="grid grid-cols-2 gap-2">
|
||||||
type="checkbox" checked={enabled} onChange={e => setEnabled(e.target.checked)}
|
|
||||||
className="rounded border-border accent-accent"
|
|
||||||
/>
|
|
||||||
<span className="text-[10px] text-secondary">启用定时拉取</span>
|
|
||||||
</label>
|
|
||||||
<div className="flex items-center gap-1.5">
|
|
||||||
<button
|
<button
|
||||||
onClick={handleTest}
|
onClick={handleTest}
|
||||||
disabled={testing || !url}
|
disabled={testing || !url}
|
||||||
className="inline-flex items-center gap-1 px-2 py-1 rounded-btn border border-border bg-elevated text-[10px] text-foreground hover:bg-border/30 disabled:opacity-40 transition-colors"
|
className="inline-flex items-center justify-center gap-1 px-2 py-2 rounded-btn border border-border bg-elevated text-xs text-foreground hover:bg-border/30 disabled:opacity-40 transition-colors"
|
||||||
>
|
>
|
||||||
{testing ? <Loader2 className="h-3 w-3 animate-spin" /> : <Search className="h-3 w-3" />}
|
{testing ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <Search className="h-3.5 w-3.5" />}
|
||||||
测试
|
测试
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={handleRun}
|
onClick={handleRun}
|
||||||
disabled={running || !url}
|
disabled={running || !url}
|
||||||
className="inline-flex items-center gap-1 px-2 py-1 rounded-btn bg-accent/90 text-base text-[10px] font-medium hover:bg-accent disabled:opacity-40 transition-colors"
|
className="inline-flex items-center justify-center gap-1 px-2 py-2 rounded-btn bg-accent/90 text-base text-xs font-medium hover:bg-accent disabled:opacity-40 transition-colors"
|
||||||
>
|
>
|
||||||
{running ? <Loader2 className="h-3 w-3 animate-spin" /> : <RefreshCw className="h-3 w-3" />}
|
{running ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <Zap className="h-3.5 w-3.5" />}
|
||||||
立即执行
|
立即执行
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={() => handleSave(false)}
|
||||||
|
disabled={saving || !url}
|
||||||
|
className="w-full inline-flex items-center justify-center gap-1 py-2 rounded-btn bg-accent/90 text-base text-xs font-medium hover:bg-accent disabled:opacity-40 transition-colors"
|
||||||
|
>
|
||||||
|
{saving ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <Check className="h-3.5 w-3.5" />}
|
||||||
|
保存配置
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* ===== 结果展示 ===== */}
|
||||||
|
{runResult && (
|
||||||
|
<div className="rounded-card border border-emerald-500/30 bg-emerald-500/[0.06] p-2.5 flex items-center justify-between text-[10px]">
|
||||||
|
<span className="text-emerald-500 font-medium flex items-center gap-1">
|
||||||
|
<CheckCircle2 className="h-3 w-3" />拉取成功
|
||||||
|
</span>
|
||||||
|
<span className="text-secondary">{runResult.rows} 行 · {runResult.date}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{testResult && (
|
{testResult && (
|
||||||
<div className="rounded-md border border-accent/30 bg-accent/[0.04] p-2.5 space-y-1.5">
|
<div className="rounded-card border border-accent/30 bg-accent/[0.04] p-2.5 space-y-1.5">
|
||||||
<div className="flex items-center justify-between text-[10px]">
|
<div className="flex items-center justify-between text-[10px]">
|
||||||
<span className="text-accent font-medium">测试成功</span>
|
<span className="text-accent font-medium">测试成功</span>
|
||||||
<span className="text-secondary">{testResult.total_rows} 行</span>
|
<span className="text-secondary">{testResult.total_rows} 行</span>
|
||||||
@@ -188,25 +316,11 @@ export function ExtDataPullPanel({ config, onSaved }: {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{pull?.last_run && (
|
{error && (
|
||||||
<div className="flex items-center justify-between text-[10px] border-t border-border/50 pt-2">
|
<div className="text-[10px] text-danger text-center bg-danger/[0.06] rounded-btn py-1.5">
|
||||||
<span className="text-muted">上次执行</span>
|
{error}
|
||||||
<span className={pull.last_status === 'success' ? 'text-green-500' : 'text-danger'}>
|
|
||||||
{pull.last_message}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<button
|
|
||||||
onClick={handleSave}
|
|
||||||
disabled={saving || !url}
|
|
||||||
className="w-full inline-flex items-center justify-center gap-1 py-1.5 rounded-btn bg-accent/90 text-base text-xs font-medium hover:bg-accent disabled:opacity-40 transition-colors"
|
|
||||||
>
|
|
||||||
{saving ? <Loader2 className="h-3 w-3 animate-spin" /> : <Check className="h-3 w-3" />}
|
|
||||||
保存配置
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{error && <div className="text-[10px] text-danger text-center">{error}</div>}
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1800,6 +1800,7 @@ export interface PullConfig {
|
|||||||
last_status?: string | null
|
last_status?: string | null
|
||||||
last_message?: string | null
|
last_message?: string | null
|
||||||
last_rows?: number | null
|
last_rows?: number | null
|
||||||
|
next_run?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ExtDataConfig {
|
export interface ExtDataConfig {
|
||||||
|
|||||||
@@ -1153,7 +1153,11 @@ export function LimitUpLadder() {
|
|||||||
const extColumnsParam = useMemo(() => buildExtColumnsParam(extFields), [extFields])
|
const extColumnsParam = useMemo(() => buildExtColumnsParam(extFields), [extFields])
|
||||||
|
|
||||||
const { data, isLoading, refetch, isFetching } = useQuery({
|
const { data, isLoading, refetch, isFetching } = useQuery({
|
||||||
queryKey: [QK.limitLadder(asOf || undefined), extColumnsParam, direction],
|
// key 必须扁平: ['limit-ladder', asOf, extColumns, direction]。
|
||||||
|
// QK.limitLadder() 返回数组, 不能整块塞进 key —— 那样第 0 元素会变成嵌套数组
|
||||||
|
// ['limit-ladder', asOf], 与四处 invalidate 用的字符串前缀 ['limit-ladder'] 类型
|
||||||
|
// 不匹配(partialMatchKey 因 typeof 不同而失配), 导致修正/SSE 推送后页面不刷新。
|
||||||
|
queryKey: [...QK.limitLadder(asOf || undefined), extColumnsParam, direction],
|
||||||
queryFn: () => api.limitLadder(asOf || undefined, extColumnsParam, direction),
|
queryFn: () => api.limitLadder(asOf || undefined, extColumnsParam, direction),
|
||||||
staleTime: 5 * 60_000,
|
staleTime: 5 * 60_000,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user