From 390b3ee876540632c268de171673a520ccb61e7f Mon Sep 17 00:00:00 2001 From: WrBug Date: Fri, 30 Jan 2026 23:58:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=E5=88=9B=E5=BB=BA=E8=B7=9F?= =?UTF-8?q?=E5=8D=95=E9=85=8D=E7=BD=AE=E6=97=B6=E6=98=BE=E7=A4=BALeader?= =?UTF-8?q?=E8=B5=84=E4=BA=A7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 选择Leader后自动获取并显示资产信息(总资产、可用余额、仓位资产) - 在AddModal和EditModal中都实现该功能 - 使用Card和Statistic组件美观展示 - 添加中英文多语言支持 - 使用formatUSDC格式化显示金额 --- frontend/src/locales/en/common.json | 8 +- frontend/src/locales/zh-CN/common.json | 8 +- frontend/src/locales/zh-TW/common.json | 12 ++- .../src/pages/CopyTradingOrders/AddModal.tsx | 86 ++++++++++++++++- .../src/pages/CopyTradingOrders/EditModal.tsx | 95 +++++++++++++++++-- 5 files changed, 197 insertions(+), 12 deletions(-) diff --git a/frontend/src/locales/en/common.json b/frontend/src/locales/en/common.json index 6ef6f1a..3dceb14 100644 --- a/frontend/src/locales/en/common.json +++ b/frontend/src/locales/en/common.json @@ -840,7 +840,13 @@ "noAccounts": "No accounts", "importAccount": "Import Account", "noLeaders": "No Leaders", - "addLeader": "Add Leader" + "addLeader": "Add Leader", + "leaderAssetInfo": "Leader Asset Info", + "loadingAssetInfo": "Loading asset info...", + "totalAsset": "Total Assets", + "availableBalance": "Available Balance", + "positionAsset": "Position Assets", + "fetchAssetInfoFailed": "Failed to fetch asset info" }, "copyTradingEdit": { "title": "Edit Copy Trading Config", diff --git a/frontend/src/locales/zh-CN/common.json b/frontend/src/locales/zh-CN/common.json index 9877483..30cf1f3 100644 --- a/frontend/src/locales/zh-CN/common.json +++ b/frontend/src/locales/zh-CN/common.json @@ -840,7 +840,13 @@ "noAccounts": "暂无账户", "importAccount": "导入账户", "noLeaders": "暂无 Leader", - "addLeader": "添加 Leader" + "addLeader": "添加 Leader", + "leaderAssetInfo": "Leader 资产信息", + "loadingAssetInfo": "加载资产信息中...", + "totalAsset": "总资产", + "availableBalance": "可用余额", + "positionAsset": "仓位资产", + "fetchAssetInfoFailed": "获取资产信息失败" }, "copyTradingEdit": { "title": "编辑跟单配置", diff --git a/frontend/src/locales/zh-TW/common.json b/frontend/src/locales/zh-TW/common.json index 94367d7..ced40b1 100644 --- a/frontend/src/locales/zh-TW/common.json +++ b/frontend/src/locales/zh-TW/common.json @@ -837,10 +837,16 @@ "fetchLeaderFailed": "獲取 Leader 列表失敗", "fetchTemplateFailed": "獲取模板列表失敗", "templateName": "模板名稱", - "noAccounts": "暫無賬戶", - "importAccount": "導入賬戶", + "noAccounts": "暫無帳戶", + "importAccount": "導入帳戶", "noLeaders": "暫無 Leader", - "addLeader": "添加 Leader" + "addLeader": "添加 Leader", + "leaderAssetInfo": "Leader 資產資訊", + "loadingAssetInfo": "加載資產資訊中...", + "totalAsset": "總資產", + "availableBalance": "可用餘額", + "positionAsset": "倉位資產", + "fetchAssetInfoFailed": "獲取資產資訊失敗" }, "copyTradingEdit": { "title": "編輯跟單配置", diff --git a/frontend/src/pages/CopyTradingOrders/AddModal.tsx b/frontend/src/pages/CopyTradingOrders/AddModal.tsx index 78453f9..be4af55 100644 --- a/frontend/src/pages/CopyTradingOrders/AddModal.tsx +++ b/frontend/src/pages/CopyTradingOrders/AddModal.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useState, useRef } from 'react' -import { Modal, Form, Button, Switch, message, Space, Radio, InputNumber, Table, Select, Divider, Input, Tag, InputRef } from 'antd' +import { Modal, Form, Button, Switch, message, Space, Radio, InputNumber, Table, Select, Divider, Input, Tag, InputRef, Card, Row, Col, Statistic } from 'antd' import { SaveOutlined, FileTextOutlined, PlusOutlined } from '@ant-design/icons' import { apiService } from '../../services/api' import { useAccountStore } from '../../store/accountStore' @@ -36,6 +36,8 @@ const AddModal: React.FC = ({ const keywordInputRef = useRef(null) const [maxMarketEndDateValue, setMaxMarketEndDateValue] = useState() const [maxMarketEndDateUnit, setMaxMarketEndDateUnit] = useState<'HOUR' | 'DAY'>('HOUR') + const [leaderAssetInfo, setLeaderAssetInfo] = useState<{ total: string; available: string; position: string } | null>(null) + const [loadingAssetInfo, setLoadingAssetInfo] = useState(false) // 导入账户modal相关状态 const [accountImportModalVisible, setAccountImportModalVisible] = useState(false) @@ -132,6 +134,32 @@ const AddModal: React.FC = ({ setCopyMode(mode) } + // 获取 Leader 资产信息 + const fetchLeaderAssetInfo = async (leaderId: number) => { + if (!leaderId) return + + setLoadingAssetInfo(true) + setLeaderAssetInfo(null) + try { + const response = await apiService.leaders.balance({ leaderId }) + if (response.data.code === 0 && response.data.data) { + const balance = response.data.data + setLeaderAssetInfo({ + total: balance.totalBalance || '0', + available: balance.availableBalance || '0', + position: balance.positionBalance || '0' + }) + } else { + message.error(response.data.msg || t('copyTradingAdd.fetchAssetInfoFailed') || '获取资产信息失败') + } + } catch (error: any) { + console.error('获取 Leader 资产失败:', error) + message.error(error.message || t('copyTradingAdd.fetchAssetInfoFailed') || '获取资产信息失败') + } finally { + setLoadingAssetInfo(false) + } + } + // 处理导入账户成功 const handleAccountImportSuccess = async (accountId: number) => { message.success(t('accountImport.importSuccess')) @@ -382,6 +410,7 @@ const AddModal: React.FC = ({ ) : null } + onChange={(value) => fetchLeaderAssetInfo(value)} > {leaders.map(leader => (