Spaces:
Sleeping
Sleeping
File size: 5,671 Bytes
61ca2b1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | import { Link, useLocation } from 'react-router-dom'
import { cn } from '../lib/utils'
import {
Database,
TrendingUp,
History,
Home,
ClipboardList,
BarChart3,
PieChart,
} from 'lucide-react'
import { useEffect, useState } from 'react'
// 导航配置 - 精简版
const navItems = [
{ name: '仪表盘', href: '/', icon: Home },
{ name: '网格回测', href: '/grid', icon: BarChart3 },
{ name: '技术指标', href: '/indicators', icon: TrendingUp },
{ name: '交易记录', href: '/trades', icon: ClipboardList },
{ name: '回测历史', href: '/history', icon: History },
{ name: '数据中心', href: '/data', icon: Database },
{ name: '行情列表', href: '/market-lists', icon: PieChart },
]
// 世界时钟
const worldClocks = [
{ city: '东京', timezone: 'Asia/Tokyo', flag: '🇯🇵' },
{ city: '伦敦', timezone: 'Europe/London', flag: '🇬🇧' },
{ city: '纽约', timezone: 'America/New_York', flag: '🇺🇸' },
]
export default function Layout({ children }: { children: React.ReactNode }) {
const location = useLocation()
const [currentTime, setCurrentTime] = useState(new Date())
const [greeting, setGreeting] = useState('')
useEffect(() => {
const timer = setInterval(() => {
setCurrentTime(new Date())
}, 1000)
return () => clearInterval(timer)
}, [])
useEffect(() => {
const hour = currentTime.getHours()
if (hour < 12) setGreeting('上午好')
else if (hour < 18) setGreeting('下午好')
else setGreeting('晚上好')
}, [currentTime])
const formatTime = (timezone: string) => {
return new Intl.DateTimeFormat('zh-CN', {
hour: '2-digit',
minute: '2-digit',
timeZone: timezone,
hour12: false,
}).format(currentTime)
}
const isMarketOpen = (timezone: string) => {
const hour = parseInt(formatTime(timezone).split(':')[0])
return hour >= 9 && hour < 15
}
const isActive = (href: string) => {
if (href === '/') return location.pathname === '/'
return location.pathname.startsWith(href)
}
return (
<div className="min-h-screen flex flex-col bg-slate-50">
{/* 顶部导航栏 */}
<header className="sticky top-0 z-50 bg-white border-b border-slate-200">
<div className="flex items-center justify-between h-14 px-6">
{/* Logo */}
<Link to="/" className="flex items-center gap-2 hover:opacity-80 transition-opacity">
<div className="w-8 h-8 rounded-lg bg-gradient-to-br from-violet-500 to-purple-600 flex items-center justify-center text-white font-bold text-sm">
WG
</div>
<span className="text-lg font-bold text-slate-900">网格交易</span>
</Link>
{/* 导航链接 */}
<nav className="flex items-center gap-1">
{navItems.map((item) => {
const Icon = item.icon
const active = isActive(item.href)
return (
<Link
key={item.href}
to={item.href}
className={cn(
"flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-medium transition-all",
active
? "bg-violet-100 text-violet-700"
: "text-slate-600 hover:bg-slate-100 hover:text-slate-900"
)}
>
<Icon className="h-4 w-4" />
<span>{item.name}</span>
</Link>
)
})}
</nav>
{/* 右侧时间 */}
<div className="text-sm text-slate-500">
{currentTime.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })}
</div>
</div>
</header>
{/* 欢迎区(仅首页) */}
{location.pathname === '/' && (
<div className="bg-white border-b border-slate-200">
<div className="px-6 py-5">
<div className="flex items-start justify-between">
<div>
<h1 className="text-xl font-bold text-slate-900">
{greeting},交易员!
</h1>
<p className="text-slate-500 text-sm mt-1">
{currentTime.toLocaleDateString('zh-CN', { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long' })}
</p>
</div>
{/* 世界时钟 */}
<div className="flex items-center gap-3">
{worldClocks.map((clock) => (
<div
key={clock.city}
className="flex items-center gap-2 px-3 py-1.5 bg-slate-50 rounded-lg"
>
<span className="text-lg">{clock.flag}</span>
<div>
<div className="text-xs text-slate-400">{clock.city}</div>
<div className="text-sm font-semibold text-slate-900">
{formatTime(clock.timezone)}
</div>
</div>
</div>
))}
</div>
</div>
</div>
</div>
)}
{/* 主内容 */}
<main className="flex-1 p-6 overflow-x-auto">
{children}
</main>
{/* 页脚 */}
<footer className="bg-white border-t border-slate-200 py-3 px-6">
<div className="flex items-center justify-between text-xs text-slate-400">
<p>© {new Date().getFullYear()} 网格交易和定投交易回测工具</p>
<p>投资有风险,入市需谨慎</p>
</div>
</footer>
</div>
)
}
|