Merge pull request #24 from Im-Sue/main

fix: 修复AI学习数据加载失败问题-前端硬编码api
This commit is contained in:
tinkle-community
2025-10-30 02:15:10 +08:00
committed by GitHub
2 changed files with 13 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import useSWR from 'swr'; import useSWR from 'swr';
import { useLanguage } from '../contexts/LanguageContext'; import { useLanguage } from '../contexts/LanguageContext';
import { t } from '../i18n/translations'; import { t } from '../i18n/translations';
import { api } from '../lib/api';
interface TradeOutcome { interface TradeOutcome {
symbol: string; symbol: string;
@@ -44,13 +45,11 @@ interface AILearningProps {
traderId: string; traderId: string;
} }
const fetcher = (url: string) => fetch(url).then(res => res.json());
export default function AILearning({ traderId }: AILearningProps) { export default function AILearning({ traderId }: AILearningProps) {
const { language } = useLanguage(); const { language } = useLanguage();
const { data: performance, error } = useSWR<PerformanceAnalysis>( const { data: performance, error } = useSWR<PerformanceAnalysis>(
`http://localhost:8080/api/performance?trader_id=${traderId}`, traderId ? `performance-${traderId}` : 'performance',
fetcher, () => api.getPerformance(traderId),
{ refreshInterval: 10000 } { refreshInterval: 10000 }
); );

View File

@@ -100,4 +100,14 @@ export const api = {
if (!res.ok) throw new Error('获取历史数据失败'); if (!res.ok) throw new Error('获取历史数据失败');
return res.json(); return res.json();
}, },
// 获取AI学习表现分析支持trader_id
async getPerformance(traderId?: string): Promise<any> {
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();
},
}; };