From 0d7325e0821a70dd8117916f673595c79e05dfaa Mon Sep 17 00:00:00 2001 From: sue <177699783@qq.com> Date: Thu, 30 Oct 2025 01:36:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DAI=E5=AD=A6=E4=B9=A0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8A=A0=E8=BD=BD=E5=A4=B1=E8=B4=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题描述: - 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: tinkle-community --- web/src/components/AILearning.tsx | 7 +++---- web/src/lib/api.ts | 10 ++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) 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(); + }, };