From 6ea1ead2639912c4db5d568135946655e753c764 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=20=E9=97=AE=E9=A2=98=E6=8F=8F=E8=BF=B0=EF=BC=9A=20-?= =?UTF-8?q?=20AILearning=E7=BB=84=E4=BB=B6=E7=9B=B4=E6=8E=A5=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=A1=AC=E7=BC=96=E7=A0=81=E7=9A=84localhost:8080?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=20-=20=E7=BB=95=E8=BF=87=E4=BA=86Vite?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=A4=B1=E8=B4=A5=20-=20=E5=9C=A8=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E7=8E=AF=E5=A2=83=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=20=E4=BF=AE=E5=A4=8D=E5=86=85=E5=AE=B9?= =?UTF-8?q?=EF=BC=9A=201.=20api.ts:=20=E6=B7=BB=E5=8A=A0=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E7=9A=84getPerformance()=E6=96=B9=E6=B3=95=202.=20AILearning.t?= =?UTF-8?q?sx:=20=E7=A7=BB=E9=99=A4=E7=A1=AC=E7=BC=96=E7=A0=81URL=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=BB=9F=E4=B8=80API=203.=20=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=A4=9A=E4=BD=99=E7=9A=84fetcher=E5=87=BD=E6=95=B0?= =?UTF-8?q?=20=E6=8A=80=E6=9C=AF=E6=94=B9=E8=BF=9B=EF=BC=9A=20-=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8Vite=E4=BB=A3=E7=90=86=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8DCORS=E9=97=AE=E9=A2=98=20-=20?= =?UTF-8?q?=E7=BB=9F=E4=B8=80API=E7=AE=A1=E7=90=86=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E9=AB=98=E5=8F=AF=E7=BB=B4=E6=8A=A4=E6=80=A7=20-=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=BC=80=E5=8F=91=E5=92=8C=E7=94=9F=E4=BA=A7=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=20=E5=BD=B1=E5=93=8D=E8=8C=83=E5=9B=B4=EF=BC=9A=20-?= =?UTF-8?q?=20web/src/lib/api.ts:=20+11=E8=A1=8C=20(=E6=96=B0=E5=A2=9EgetP?= =?UTF-8?q?erformance=E6=96=B9=E6=B3=95)=20-=20web/src/components/AILearni?= =?UTF-8?q?ng.tsx:=20-4=E8=A1=8C,=20+2=E8=A1=8C=20(=E9=87=8D=E6=9E=84API?= =?UTF-8?q?=E8=B0=83=E7=94=A8)=20Co-Authored-By:=20tinkle-community=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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(); + }, };