Spaces:
Sleeping
Sleeping
Download frontend/src/components/Layout.tsx from shaun07/grid-backtest: direct link, hf CLI and curl.
- Browser
- Download file 5.67 kB
-
https://huggingface.co/spaces/shaun07/grid-backtest/resolve/main/frontend/src/components/Layout.tsx
- Command line
-
hf download hf://spaces/shaun07/grid-backtest/frontend/src/components/Layout.tsx
-
curl -L -o Layout.tsx https://huggingface.co/spaces/shaun07/grid-backtest/resolve/main/frontend/src/components/Layout.tsx
5.67 kB
| 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> | |
| ) | |
| } | |