mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-05 20:11:13 +08:00
fix: 修复AI学习数据加载失败问题
问题描述: - AILearning组件直接使用硬编码的localhost:8080地址 - 绕过了Vite代理配置,导致加载失败 - 在生产环境无法正常工作 修复内容: 1. api.ts: 添加统一的getPerformance()方法 2. AILearning.tsx: 移除硬编码URL,使用统一API 3. 删除多余的fetcher函数 技术改进: - 使用Vite代理配置,避免CORS问题 - 统一API管理,提高可维护性 - 支持开发和生产环境 影响范围: - web/src/lib/api.ts: +11行 (新增getPerformance方法) - web/src/components/AILearning.tsx: -4行, +2行 (重构API调用) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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<PerformanceAnalysis>(
|
||||
`http://localhost:8080/api/performance?trader_id=${traderId}`,
|
||||
fetcher,
|
||||
traderId ? `performance-${traderId}` : 'performance',
|
||||
() => api.getPerformance(traderId),
|
||||
{ refreshInterval: 10000 }
|
||||
);
|
||||
|
||||
|
||||
@@ -100,4 +100,14 @@ export const api = {
|
||||
if (!res.ok) throw new Error('获取历史数据失败');
|
||||
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();
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user