import React, { useState, useEffect } from 'react' import { Outlet, useNavigate, useLocation } from 'react-router-dom' import { Layout, Menu, Button, Avatar, Dropdown, Typography, Space, Badge, Drawer, Modal, theme } from 'antd' import { DashboardOutlined, ProjectOutlined, DollarOutlined, FileTextOutlined, BarChartOutlined, UserOutlined, LogoutOutlined, SettingOutlined, BellOutlined, MenuFoldOutlined, MenuUnfoldOutlined, CalculatorOutlined, ToolOutlined, WalletOutlined, MoneyCollectOutlined, AuditOutlined, FileSearchOutlined, ShoppingCartOutlined, TeamOutlined, ShopOutlined, SolutionOutlined, HomeOutlined, SafetyOutlined, FileDoneOutlined, AppstoreOutlined, CheckCircleOutlined } from '@ant-design/icons' import { useAuthStore } from '../../store/authStore' import { useLanguageStore } from '../../store/languageStore' import CompanyLogo from '../common/CompanyLogo' import LanguageSelector from '../common/LanguageSelector' const { Header, Sider, Content } = Layout const { Text } = Typography const MainLayout: React.FC = () => { const navigate = useNavigate() const location = useLocation() const [collapsed, setCollapsed] = useState(false) const [isMobile, setIsMobile] = useState(false) const [mobileMenuVisible, setMobileMenuVisible] = useState(false) const [settingsVisible, setSettingsVisible] = useState(false) const { user, logout } = useAuthStore() const { t } = useLanguageStore() const { token: { colorBgContainer, borderRadiusLG }, } = theme.useToken() // 检测屏幕尺寸 useEffect(() => { const checkMobile = () => { const mobile = window.innerWidth <= 768 setIsMobile(mobile) if (mobile) { setCollapsed(true) } } checkMobile() window.addEventListener('resize', checkMobile) return () => window.removeEventListener('resize', checkMobile) }, []) // 完整菜单项 const menuItems = [ { key: '/dashboard', icon: , label: '工作台' }, { key: '/projects', icon: , label: '项目管理' }, { key: '/budget-projects', icon: , label: '预算报价' }, { key: '/construction', icon: , label: '施工管理' }, { key: 'approval', icon: , label: '审批管理', children: [ { key: '/approval', icon: , label: '待审批' }, { key: '/execution', icon: , label: '待执行' } ] }, { key: 'finance-docs', icon: , label: '财务申请', children: [ { key: '/advances', icon: , label: '预支申请' }, { key: '/reimbursements', icon: , label: '报销申请' }, { key: '/payment-requests', icon: , label: '付款申请' }, { key: '/verification', icon: , label: '核销申请' } ] }, { key: 'finance-group', icon: , label: '财务管理', children: [ { key: '/finance', label: '财务概览' }, { key: '/exchange-rates', icon: , label: '汇率管理' } ] }, { key: '/reports', icon: , label: '报表分析' }, { key: 'procurement', icon: , label: '采购管理', children: [ { key: '/products', icon: , label: '商品管理' } ] }, { key: 'partners', icon: , label: '合作伙伴', children: [ { key: '/suppliers', icon: , label: '供应商管理' }, { key: '/subcontractors', icon: , label: '分包商管理' }, { key: '/customers', icon: , label: '客户管理' } ] } ] // 用户下拉菜单 const userMenuItems = [ { key: 'profile', icon: , label: '个人信息' }, { key: 'settings', icon: , label: '系统设置' }, { type: 'divider' as const }, { key: 'logout', icon: , label: '退出登录' } ] // 处理菜单点击 const handleMenuClick = ({ key }: { key: string }) => { if (key === 'logout') { logout() navigate('/login') } else if (key === 'settings') { setSettingsVisible(true) } else if (key.startsWith('/')) { navigate(key) if (isMobile) { setMobileMenuVisible(false) } } } // 获取当前选中的菜单项 const getSelectedKey = () => { return location.pathname } // 获取当前展开的菜单项 const getOpenKeys = () => { const path = location.pathname if (path.startsWith('/suppliers') || path.startsWith('/subcontractors') || path.startsWith('/customers')) { return ['partners'] } if (path.startsWith('/advances') || path.startsWith('/reimbursements') || path.startsWith('/payment-requests') || path.startsWith('/verification')) { return ['finance-docs'] } if (path.startsWith('/approval') || path.startsWith('/execution')) { return ['approval'] } if (path.startsWith('/products')) { return ['procurement'] } return [] } return ( {/* 桌面端侧边栏 */} {!isMobile && ( {/* Logo */}
{/* 菜单 */} {/* 折叠按钮 */}
)} {/* 移动端抽屉菜单 */} {isMobile && ( setMobileMenuVisible(false)} open={mobileMenuVisible} width={280} styles={{ body: { padding: 0 } }} >
)} {/* 顶部导航 */}
{/* 移动端菜单按钮 */} {isMobile && (
{/* 内容区域 */}
{/* 设置弹窗 */} setSettingsVisible(false)} footer={null} >

系统设置功能开发中...

) } export default MainLayout