import React, { useState, Suspense, lazy } from 'react'; import { Layout, Menu, theme, Button, Dropdown, Avatar, message, Space, Divider, ConfigProvider as AntdConfigProvider } from 'antd'; import { BarChartOutlined, DatabaseOutlined, CloudServerOutlined, MenuUnfoldOutlined, MenuFoldOutlined, EyeOutlined, BuildOutlined, HomeOutlined, ShoppingCartOutlined, InboxOutlined, ImportOutlined, FileTextOutlined, UserOutlined, LogoutOutlined, HistoryOutlined, AuditOutlined, ToolOutlined, ScheduleOutlined, SettingOutlined, ApiOutlined, PartitionOutlined, CodepenOutlined } from '@ant-design/icons'; import { BrowserRouter as Router, Routes, Route, Link, Navigate, useLocation, useNavigate } from 'react-router-dom'; import { useAuth } from './context/AuthContext'; import { ConfigProvider, useConfig } from './context/ConfigContext'; import { Spin } from 'antd'; const Dashboard = lazy(() => import('./pages/Dashboard')); const DeviceManagement = lazy(() => import('./pages/DeviceManagement')); const RackManagement = lazy(() => import('./pages/RackManagement')); const RoomManagement = lazy(() => import('./pages/RoomManagement')); const DeviceFieldManagement = lazy(() => import('./pages/DeviceFieldManagement')); const Rack3DVisualization = lazy(() => import('./pages/Rack3DVisualization')); const ConsumableManagement = lazy(() => import('./pages/ConsumableManagement')); const ConsumableStatistics = lazy(() => import('./pages/ConsumableStatistics')); const ConsumableLogs = lazy(() => import('./pages/ConsumableLogs')); const CategoryManagement = lazy(() => import('./pages/CategoryManagement')); const UserManagement = lazy(() => import('./pages/UserManagement')); const Login = lazy(() => import('./pages/Login')); const TicketManagement = lazy(() => import('./pages/TicketManagement')); const TicketCategoryManagement = lazy(() => import('./pages/TicketCategoryManagement')); const TicketStatistics = lazy(() => import('./pages/TicketStatistics')); const TicketFieldManagement = lazy(() => import('./pages/TicketFieldManagement')); const SystemSettings = lazy(() => import('./pages/SystemSettings')); const CableManagement = lazy(() => import('./pages/CableManagement')); const PortManagement = lazy(() => import('./pages/PortManagement')); const { Header, Content, Sider } = Layout; const PageLoading = () => (
正在加载页面...
); const AuthLoading = () => (
正在加载认证状态...
); const designTokens = { colors: { primary: { main: '#667eea', gradient: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', light: '#8b9ff0' }, success: { main: '#10b981' }, warning: { main: '#f59e0b' }, error: { main: '#ef4444' }, text: { primary: '#1e293b', secondary: '#64748b', inverse: '#ffffff' }, background: { primary: '#ffffff', secondary: '#f8fafc', dark: '#1e293b' }, border: { light: '#e2e8f0' }, sidebar: { bg: '#ffffff', bgHover: 'rgba(102, 126, 234, 0.08)', bgActive: 'rgba(102, 126, 234, 0.15)', text: '#475569', textHover: '#667eea', textActive: '#667eea', border: '#e2e8f0' } }, shadows: { small: '0 1px 2px 0 rgba(0, 0, 0, 0.05)', medium: '0 4px 6px -1px rgba(0, 0, 0, 0.1)', large: '0 10px 15px -3px rgba(0, 0, 0, 0.1)' }, borderRadius: { small: '6px', medium: '10px' }, spacing: { sm: '8px', md: '16px', lg: '24px' } }; const PrivateRoute = ({ children }) => { const { token, initialized, loading } = useAuth(); const location = useLocation(); if (!initialized) { return ; } if (!token) { return ; } return {children}; }; const ProtectedRoute = ({ component: Component }) => ( ); const AppLayout = ({ children }) => { const [collapsed, setCollapsed] = useState(false); const [activeKey, setActiveKey] = useState('dashboard'); const { user, logout } = useAuth(); const navigate = useNavigate(); const location = useLocation(); const { config } = useConfig(); const handleLogout = () => { logout(); message.success('已退出登录'); navigate('/login'); }; const getSelectedKey = () => { const path = location.pathname; if (path === '/') return 'dashboard'; if (path.startsWith('/visualization-3d')) return 'visualization-3d'; if (path.startsWith('/rooms') || path.startsWith('/racks')) return 'room-management'; if (path.startsWith('/devices') || path.startsWith('/fields') || path.startsWith('/cables') || path.startsWith('/ports')) return 'asset-management'; if (path.startsWith('/consumables')) return 'consumables-management'; if (path.startsWith('/users') || path.startsWith('/login-history') || path.startsWith('/operation-logs') || path.startsWith('/settings')) return 'system-management'; if (path.startsWith('/tickets')) return 'ticket-management'; return 'dashboard'; }; // 动态设计令牌 const designTokens = { colors: { primary: { main: config.primary_color || '#667eea', gradient: `linear-gradient(135deg, ${config.primary_color || '#667eea'} 0%, ${config.secondary_color || '#764ba2'} 100%)`, light: '#8b9ff0' }, success: { main: '#10b981' }, warning: { main: '#f59e0b' }, error: { main: '#ef4444' }, text: { primary: '#1e293b', secondary: '#64748b', inverse: '#ffffff' }, background: { primary: '#ffffff', secondary: '#f8fafc', dark: '#1e293b' }, border: { light: '#e2e8f0' }, sidebar: { bg: '#ffffff', bgHover: 'rgba(102, 126, 234, 0.08)', bgActive: 'rgba(102, 126, 234, 0.15)', text: '#475569', textHover: config.primary_color || '#667eea', textActive: config.primary_color || '#667eea', border: '#e2e8f0' } }, shadows: { small: '0 1px 2px 0 rgba(0, 0, 0, 0.05)', medium: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)', large: '0 10px 15px -3px rgba(0, 0, 0, 0.1)' }, borderRadius: { small: '6px', medium: '10px' }, spacing: { sm: '8px', md: '16px', lg: '24px' } }; const menuItems = [ { key: 'dashboard', icon: , label: 仪表盘, }, { key: 'room-management', icon: , label: '机房管理', children: [ { key: 'rooms', icon: , label: 机房管理, }, { key: 'racks', icon: , label: 机柜管理, }, { key: 'visualization-3d', icon: , label: 3D机柜可视化, }, ], }, { key: 'asset-management', icon: , label: '资产管理', children: [ { key: 'devices', icon: , label: 设备管理, }, { key: 'fields', icon: , label: 字段管理, }, { key: 'cables', icon: , label: 接线管理, }, { key: 'ports', icon: , label: 端口管理, }, ], }, { key: 'consumables-management', icon: , label: '耗材管理', children: [ { key: 'consumables-stats', icon: , label: 耗材统计, }, { key: 'consumables', icon: , label: 耗材列表, }, { key: 'consumables-categories', icon: , label: 分类管理, }, { key: 'consumables-logs', icon: , label: 操作日志, }, ], }, { key: 'ticket-management', icon: , label: '工单管理', children: [ { key: 'tickets', icon: , label: 工单列表, }, { key: 'ticket-categories', icon: , label: 故障分类, }, { key: 'ticket-statistics', icon: , label: 统计报表, }, { key: 'ticket-fields', icon: , label: 字段管理, }, ], }, { key: 'system-management', icon: , label: '系统管理', children: [ { key: 'users', icon: , label: 用户管理, }, { key: 'system-settings', icon: , label: 系统设置, }, ], }, ]; return (
{!collapsed && (
{config.site_name || 'IDC管理'}
数据中心管理平台
)}
{user && (
} /> {user.username}
)}
{children}
); }; const ThemeConfig = () => { const { config } = useConfig(); // 动态设计令牌 const designTokens = { colors: { primary: { main: config.primary_color || '#667eea', gradient: `linear-gradient(135deg, ${config.primary_color || '#667eea'} 0%, ${config.secondary_color || '#764ba2'} 100%)`, light: '#8b9ff0' }, success: { main: '#10b981' }, warning: { main: '#f59e0b' }, error: { main: '#ef4444' }, text: { primary: '#1e293b', secondary: '#64748b', inverse: '#ffffff' }, background: { primary: '#ffffff', secondary: '#f8fafc', dark: '#1e293b' }, border: { light: '#e2e8f0' }, sidebar: { bg: '#ffffff', bgHover: 'rgba(102, 126, 234, 0.08)', bgActive: 'rgba(102, 126, 234, 0.15)', text: '#475569', textHover: config.primary_color || '#667eea', textActive: config.primary_color || '#667eea', border: '#e2e8f0' } }, shadows: { small: '0 1px 2px 0 rgba(0, 0, 0, 0.05)', medium: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)', large: '0 10px 15px -3px rgba(0, 0, 0, 0.1)' }, borderRadius: { small: '6px', medium: '10px' }, spacing: { sm: '8px', md: '16px', lg: '24px' } }; return ( }> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> ); }; function App() { return ( ); } export default App;