import { fetchAuthenticated } from '../../../auth/api-client'; import type { HistoryMode, HistoryTrend, HistoryPoint, HistoryDetails, HistoryCategory } from '../../../shared/assets/history'; async function get(path: string, params: Record, signal: AbortSignal): Promise { const query = new URLSearchParams(); for (const [key, value] of Object.entries(params)) if (value != null && value !== '') query.set(key, String(value)); const response = await fetchAuthenticated(`/api/asset-history/${path}?${query}`, { signal }); const body = await response.json(); if (!response.ok) throw new Error(body.error || '历史趋势加载失败,请重试'); return body as T; } export function fetchHistoryTrend(mode: HistoryMode, year: number, subject: string | null, signal: AbortSignal) { return get('trend', { mode, year, subject }, signal); } export function fetchHistoryLive(mode: HistoryMode, subject: string | null, signal: AbortSignal) { return get('live', { mode, subject }, signal); } export function fetchHistoryDetails(month: string, batchId: string | null, subject: string | null, category: HistoryCategory, search: string, page: number, signal: AbortSignal) { return get('details', { month, batchId, subject, category, search, page, pageSize: 30 }, signal); }