22301014 | bc4616f | 2025-06-03 16:59:44 +0800 | [diff] [blame] | 1 | import { Outlet, useLocation, useNavigate } from 'react-router'; |
| 2 | import { Layout, Menu } from 'antd'; |
| 3 | import { HomeOutlined, AppstoreOutlined } from '@ant-design/icons'; |
| 4 | |
| 5 | const { Header } = Layout; |
| 6 | |
| 7 | const AppLayout = () => { |
| 8 | const location = useLocation(); |
| 9 | const navigate = useNavigate(); |
| 10 | // 导航项配置 |
| 11 | const menuItems = [ |
| 12 | { |
| 13 | key: 'home', |
| 14 | label: '主页', |
| 15 | icon: <HomeOutlined />, |
| 16 | path: '/', |
| 17 | }, |
| 18 | { |
| 19 | key: 'tasks', |
| 20 | label: '任务清单', |
| 21 | icon: <AppstoreOutlined />, |
| 22 | path: '/tasks', |
| 23 | }, |
| 24 | ]; |
| 25 | |
| 26 | return ( |
| 27 | <Layout style={{ minHeight: '100vh', width: '100%' }}> |
| 28 | <Header className="header" style={{ display: 'flex', alignItems: 'center' }}> |
| 29 | <div className="logo" color='white'>创驿</div> |
| 30 | <Menu |
| 31 | mode="horizontal" |
| 32 | theme='dark' |
| 33 | selectedKeys={[location.pathname === '/' ? 'home' : location.pathname.slice(1)]} |
| 34 | items={menuItems.map(item => ({ |
| 35 | ...item, |
| 36 | onClick: () => navigate(item.path), |
| 37 | }))} |
| 38 | /> |
| 39 | </Header> |
| 40 | <Layout.Content style={{ padding: '24px' }}> |
| 41 | <Outlet /> |
| 42 | </Layout.Content> |
| 43 | <Layout.Footer> |
| 44 | © 2025 创驿 - 创作路上的同行者 |
| 45 | </Layout.Footer> |
| 46 | </Layout> |
| 47 | ); |
| 48 | }; |
| 49 | |
| 50 | export default AppLayout; |