diff --git a/web/src/components/AILearning.tsx b/web/src/components/AILearning.tsx index e3806b36..b7757e32 100644 --- a/web/src/components/AILearning.tsx +++ b/web/src/components/AILearning.tsx @@ -1,6 +1,7 @@ import useSWR from 'swr'; import { useLanguage } from '../contexts/LanguageContext'; import { t } from '../i18n/translations'; +import { api } from '../lib/api'; interface TradeOutcome { symbol: string; @@ -44,13 +45,11 @@ interface AILearningProps { traderId: string; } -const fetcher = (url: string) => fetch(url).then(res => res.json()); - export default function AILearning({ traderId }: AILearningProps) { const { language } = useLanguage(); const { data: performance, error } = useSWR( - `http://localhost:8080/api/performance?trader_id=${traderId}`, - fetcher, + traderId ? `performance-${traderId}` : 'performance', + () => api.getPerformance(traderId), { refreshInterval: 10000 } ); diff --git a/web/src/lib/api.ts b/web/src/lib/api.ts index 22d1b82d..d00ae2ab 100644 --- a/web/src/lib/api.ts +++ b/web/src/lib/api.ts @@ -100,4 +100,14 @@ export const api = { if (!res.ok) throw new Error('获取历史数据失败'); return res.json(); }, + + // 获取AI学习表现分析(支持trader_id) + async getPerformance(traderId?: string): Promise { + const url = traderId + ? `${API_BASE}/performance?trader_id=${traderId}` + : `${API_BASE}/performance`; + const res = await fetch(url); + if (!res.ok) throw new Error('获取AI学习数据失败'); + return res.json(); + }, };