fix: dailyGains 类型精度 + 补 try/catch 与 theme-api 对齐
This commit is contained in:
@@ -4,7 +4,7 @@ import { getApiBaseUrl } from "@/lib/api-client";
|
||||
export interface ActiveCoreStock {
|
||||
stockCode: string;
|
||||
stockName: string;
|
||||
dailyGains: Record<string, number>; // 日期 -> 当日涨幅
|
||||
dailyGains: Record<string, number | null>; // 日期 -> 当日涨幅(可空)
|
||||
appearCount: number;
|
||||
lastAppear: string | null;
|
||||
}
|
||||
@@ -33,15 +33,25 @@ export interface CoreStockHistoryResponse {
|
||||
/** 获取活跃核心股 + 最近10日涨幅矩阵 */
|
||||
export async function fetchActiveCoreStocks(): Promise<ActiveCoreStocksResponse> {
|
||||
const baseUrl = getApiBaseUrl();
|
||||
const resp = await fetch(`${baseUrl}/api/core-stocks/active`, { method: "GET", cache: "no-store" });
|
||||
if (!resp.ok) return { dates: [], stocks: [] };
|
||||
return resp.json();
|
||||
try {
|
||||
const resp = await fetch(`${baseUrl}/api/core-stocks/active`, { method: "GET", cache: "no-store" });
|
||||
if (!resp.ok) return { dates: [], stocks: [] };
|
||||
return resp.json();
|
||||
} catch (err) {
|
||||
console.error("[core-stock-api] 获取活跃核心股失败:", err);
|
||||
return { dates: [], stocks: [] };
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取指定交易日核心股(含所属题材) */
|
||||
export async function fetchCoreStockHistory(date: string): Promise<CoreStockHistoryResponse | null> {
|
||||
const baseUrl = getApiBaseUrl();
|
||||
const resp = await fetch(`${baseUrl}/api/core-stocks/history?date=${date}`, { method: "GET", cache: "no-store" });
|
||||
if (!resp.ok) return null;
|
||||
return resp.json();
|
||||
try {
|
||||
const resp = await fetch(`${baseUrl}/api/core-stocks/history?date=${date}`, { method: "GET", cache: "no-store" });
|
||||
if (!resp.ok) return null;
|
||||
return resp.json();
|
||||
} catch (err) {
|
||||
console.error("[core-stock-api] 获取核心股历史失败:", err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user