feat: 完善Leader管理功能

- 修复LeaderList:移除不存在的字段(enabled, copyRatio),添加跟单关系数量和创建时间显示
- 修复LeaderAdd:移除不需要的字段(accountId, enabled),只保留leaderAddress, leaderName, category
- 新增LeaderEdit页面:支持编辑Leader名称和分类
- 添加移动端适配:LeaderList支持卡片式布局
- 统一地址验证:前后端使用相同的正则表达式验证钱包地址格式
- 更新路由配置:添加/leaders/edit路由
- 改进用户体验:删除前提示跟单关系数量
This commit is contained in:
WrBug
2025-12-01 23:36:23 +08:00
parent 4d322424c1
commit 844cd686eb
5 changed files with 318 additions and 67 deletions
+147 -27
View File
@@ -1,9 +1,8 @@
import { useEffect } from 'react'
import { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { Card, Table, Button, Space, Tag, Popconfirm, message } from 'antd'
import { Card, Table, Button, Space, Tag, Popconfirm, message, List, Empty, Spin, Divider } from 'antd'
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons'
import { apiService } from '../services/api'
import { useState } from 'react'
import type { Leader } from '../types'
import { useMediaQuery } from 'react-responsive'
@@ -59,7 +58,9 @@ const LeaderList: React.FC = () => {
dataIndex: 'leaderAddress',
key: 'leaderAddress',
render: (address: string) => (
<span style={{ fontFamily: 'monospace' }}>{address}</span>
<span style={{ fontFamily: 'monospace', fontSize: isMobile ? '12px' : '14px' }}>
{isMobile ? `${address.slice(0, 6)}...${address.slice(-4)}` : address}
</span>
)
},
{
@@ -71,24 +72,30 @@ const LeaderList: React.FC = () => {
) : <Tag></Tag>
},
{
title: '状态',
dataIndex: 'enabled',
key: 'enabled',
render: (enabled: boolean) => (
<Tag color={enabled ? 'success' : 'default'}>
{enabled ? '启用' : '禁用'}
</Tag>
)
title: '跟单关系数',
dataIndex: 'copyTradingCount',
key: 'copyTradingCount',
render: (count: number) => <Tag>{count}</Tag>
},
{
title: '跟单比例',
dataIndex: 'copyRatio',
key: 'copyRatio',
render: (ratio: string) => `${ratio}x`
title: '创建时间',
dataIndex: 'createdAt',
key: 'createdAt',
render: (timestamp: number) => {
const date = new Date(timestamp)
return date.toLocaleString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
})
}
},
{
title: '操作',
key: 'action',
width: isMobile ? 120 : 150,
render: (_: any, record: Leader) => (
<Space size="small">
<Button
@@ -101,6 +108,7 @@ const LeaderList: React.FC = () => {
</Button>
<Popconfirm
title="确定要删除这个 Leader 吗?"
description={record.copyTradingCount > 0 ? `该 Leader 还有 ${record.copyTradingCount} 个跟单关系,请先删除跟单关系` : undefined}
onConfirm={() => handleDelete(record.id)}
okText="确定"
cancelText="取消"
@@ -124,7 +132,7 @@ const LeaderList: React.FC = () => {
flexWrap: 'wrap',
gap: '12px'
}}>
<h2>Leader </h2>
<h2 style={{ margin: 0 }}>Leader </h2>
<Button
type="primary"
icon={<PlusOutlined />}
@@ -136,16 +144,128 @@ const LeaderList: React.FC = () => {
</div>
<Card>
<Table
dataSource={leaders}
columns={columns}
rowKey="id"
loading={loading}
pagination={{
pageSize: isMobile ? 10 : 20,
showSizeChanger: !isMobile
}}
/>
{isMobile ? (
// 移动端卡片布局
<div>
{loading ? (
<div style={{ textAlign: 'center', padding: '40px' }}>
<Spin size="large" />
</div>
) : leaders.length === 0 ? (
<Empty description="暂无 Leader 数据" />
) : (
<List
dataSource={leaders}
renderItem={(leader) => {
const date = new Date(leader.createdAt)
const formattedDate = date.toLocaleString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
})
return (
<Card
key={leader.id}
style={{
marginBottom: '12px',
borderRadius: '12px',
boxShadow: '0 2px 8px rgba(0,0,0,0.08)',
border: '1px solid #e8e8e8'
}}
bodyStyle={{ padding: '16px' }}
>
{/* Leader 名称和地址 */}
<div style={{ marginBottom: '12px' }}>
<div style={{
fontSize: '16px',
fontWeight: 'bold',
marginBottom: '8px',
color: '#1890ff'
}}>
{leader.leaderName || `Leader ${leader.id}`}
</div>
<div style={{
fontSize: '12px',
color: '#666',
fontFamily: 'monospace',
wordBreak: 'break-all'
}}>
{leader.leaderAddress}
</div>
</div>
<Divider style={{ margin: '12px 0' }} />
{/* 分类和跟单关系数 */}
<div style={{ marginBottom: '12px' }}>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '6px', alignItems: 'center' }}>
{leader.category ? (
<Tag color={leader.category === 'sports' ? 'blue' : 'green'}>
{leader.category}
</Tag>
) : (
<Tag></Tag>
)}
<Tag>{leader.copyTradingCount} </Tag>
</div>
</div>
{/* 创建时间 */}
<div style={{ marginBottom: '12px', fontSize: '12px', color: '#999' }}>
: {formattedDate}
</div>
{/* 操作按钮 */}
<div style={{ display: 'flex', gap: '8px' }}>
<Button
type="link"
size="small"
icon={<EditOutlined />}
onClick={() => navigate(`/leaders/edit?id=${leader.id}`)}
style={{ flex: 1 }}
>
</Button>
<Popconfirm
title="确定要删除这个 Leader 吗?"
description={leader.copyTradingCount > 0 ? `该 Leader 还有 ${leader.copyTradingCount} 个跟单关系,请先删除跟单关系` : undefined}
onConfirm={() => handleDelete(leader.id)}
okText="确定"
cancelText="取消"
>
<Button
type="link"
size="small"
danger
icon={<DeleteOutlined />}
style={{ flex: 1 }}
>
</Button>
</Popconfirm>
</div>
</Card>
)
}}
/>
)}
</div>
) : (
// 桌面端表格布局
<Table
dataSource={leaders}
columns={columns}
rowKey="id"
loading={loading}
pagination={{
pageSize: 20,
showSizeChanger: true
}}
/>
)}
</Card>
</div>
)