Files
PolyHermes/frontend/src/components/Layout.tsx
T
WrBug fd10a31780 feat: 完善跟单模板管理功能
- 更新需求文档:移除每日最大亏损限制、跟单延迟、轮询和WebSocket配置
- 跟单比例改为百分比格式(10%-1000%),只允许整数
- 所有USDC字段支持最多4位小数
- 固定金额和最小金额校验(必须>=1)
- 模板名称支持编辑
- 复制模板改为Modal形式,可编辑后创建
- 模板列表按创建时间降序排序,显示创建时间
- 移动端适配:使用卡片式布局
- 合并跟单比例和固定金额列为跟单配置
- 支持卖出改为跟单卖出
- 菜单结构调整:跟单管理作为父菜单,包含跟单模板和跟单配置子菜单
2025-12-01 23:03:17 +08:00

214 lines
5.3 KiB
TypeScript

import { useState, useEffect } from 'react'
import { useNavigate, useLocation } from 'react-router-dom'
import { Layout as AntLayout, Menu, Drawer, Button } from 'antd'
import { useMediaQuery } from 'react-responsive'
import {
WalletOutlined,
UserOutlined,
UnorderedListOutlined,
BarChartOutlined,
MenuOutlined,
FileTextOutlined,
LinkOutlined,
AppstoreOutlined
} from '@ant-design/icons'
import type { MenuProps } from 'antd'
import type { ReactNode } from 'react'
const { Header, Content, Sider } = AntLayout
interface LayoutProps {
children: ReactNode
}
const Layout: React.FC<LayoutProps> = ({ children }) => {
const navigate = useNavigate()
const location = useLocation()
const isMobile = useMediaQuery({ maxWidth: 768 })
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
// 获取当前选中的菜单项
const getSelectedKeys = (): string[] => {
return [location.pathname]
}
// 获取当前应该打开的父菜单
const getInitialOpenKeys = (): string[] => {
const path = location.pathname
if (path.startsWith('/templates') || path.startsWith('/copy-trading')) {
return ['/copy-trading-management']
}
return []
}
const [openKeys, setOpenKeys] = useState<string[]>(getInitialOpenKeys())
// 当路径变化时,自动打开对应的父菜单
useEffect(() => {
const path = location.pathname
if (path.startsWith('/templates') || path.startsWith('/copy-trading')) {
setOpenKeys(['/copy-trading-management'])
}
}, [location.pathname])
const menuItems: MenuProps['items'] = [
{
key: '/accounts',
icon: <WalletOutlined />,
label: '账户管理'
},
{
key: '/leaders',
icon: <UserOutlined />,
label: 'Leader 管理'
},
{
key: '/copy-trading-management',
icon: <AppstoreOutlined />,
label: '跟单管理',
children: [
{
key: '/templates',
icon: <FileTextOutlined />,
label: '跟单模板'
},
{
key: '/copy-trading',
icon: <LinkOutlined />,
label: '跟单配置'
}
]
},
{
key: '/positions',
icon: <UnorderedListOutlined />,
label: '仓位管理'
},
{
key: '/statistics',
icon: <BarChartOutlined />,
label: '统计信息'
}
]
const handleMenuClick = ({ key }: { key: string }) => {
// 如果是父菜单,不导航
if (key === '/copy-trading-management') {
return
}
navigate(key)
if (isMobile) {
setMobileMenuOpen(false)
}
}
const handleOpenChange = (keys: string[]) => {
setOpenKeys(keys)
}
if (isMobile) {
// 移动端布局
return (
<AntLayout style={{ minHeight: '100vh' }}>
<Header style={{
background: '#001529',
padding: '0 16px',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between'
}}>
<div style={{ color: '#fff', fontSize: '18px', fontWeight: 'bold' }}>
Polymarket 跟单
</div>
<Button
type="text"
icon={<MenuOutlined />}
style={{ color: '#fff' }}
onClick={() => setMobileMenuOpen(true)}
/>
</Header>
<Content style={{
padding: '12px 8px',
background: '#f0f2f5',
minHeight: 'calc(100vh - 64px)'
}}>
{children}
</Content>
<Drawer
title="导航菜单"
placement="left"
onClose={() => setMobileMenuOpen(false)}
open={mobileMenuOpen}
bodyStyle={{ padding: 0 }}
>
<Menu
mode="inline"
selectedKeys={getSelectedKeys()}
openKeys={openKeys}
onOpenChange={handleOpenChange}
items={menuItems}
onClick={handleMenuClick}
style={{ border: 'none' }}
/>
</Drawer>
</AntLayout>
)
}
// 桌面端布局
return (
<AntLayout style={{ height: '100vh', overflow: 'hidden' }}>
<Sider
width={200}
style={{
background: '#001529',
height: '100vh',
position: 'fixed',
left: 0,
top: 0,
overflow: 'hidden'
}}
>
<div style={{
height: '64px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
color: '#fff',
fontSize: '18px',
fontWeight: 'bold',
flexShrink: 0
}}>
Polymarket 跟单
</div>
<Menu
mode="inline"
selectedKeys={getSelectedKeys()}
openKeys={openKeys}
onOpenChange={handleOpenChange}
items={menuItems}
onClick={handleMenuClick}
style={{
height: 'calc(100vh - 64px)',
borderRight: 0,
overflowY: 'auto'
}}
/>
</Sider>
<AntLayout style={{ marginLeft: 200, height: '100vh' }}>
<Content style={{
padding: '24px',
background: '#f0f2f5',
height: '100vh',
overflowY: 'auto'
}}>
{children}
</Content>
</AntLayout>
</AntLayout>
)
}
export default Layout