Spaces:
Runtime error
Runtime error
File size: 4,691 Bytes
ccab613 c1b740a ccab613 c1b740a ccab613 c1b740a ccab613 c1b740a ccab613 c1b740a ccab613 c1b740a ccab613 c1b740a ccab613 c1b740a ccab613 c1b740a ccab613 c1b740a ccab613 c1b740a ccab613 | 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 | import { useState } from 'react';
import { Outlet, useNavigate, useLocation } from 'react-router-dom';
import { Layout, Menu, Button, Typography, Avatar, Dropdown } from 'antd';
import {
MessageOutlined,
ToolOutlined,
HistoryOutlined,
SettingOutlined,
LogoutOutlined,
UserOutlined,
MenuFoldOutlined,
MenuUnfoldOutlined,
} from '@ant-design/icons';
import { useAuthStore } from '../../stores/authStore';
import Sidebar from './Sidebar';
const { Header, Sider, Content } = Layout;
export default function AppLayout() {
const [collapsed, setCollapsed] = useState(false);
const navigate = useNavigate();
const location = useLocation();
const { user, logout } = useAuthStore();
const isChatRoute = location.pathname.startsWith('/chat');
const menuItems = [
{ key: '/chat', icon: <MessageOutlined />, label: 'Chat' },
{ key: '/tools', icon: <ToolOutlined />, label: 'Tools' },
{ key: '/history', icon: <HistoryOutlined />, label: 'History' },
{ key: '/settings', icon: <SettingOutlined />, label: 'Settings' },
];
const userMenuItems = [
{
key: 'logout',
icon: <LogoutOutlined />,
label: 'Logout',
onClick: () => { logout(); navigate('/login'); },
},
];
return (
<Layout style={{ minHeight: '100vh' }}>
<Header
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
padding: '0 24px',
boxShadow: '0 2px 8px rgba(0, 0, 0, 0.15)',
position: 'sticky',
top: 0,
zIndex: 100,
}}
>
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
<div
style={{
width: 36,
height: 36,
borderRadius: 10,
background: 'rgba(255, 255, 255, 0.2)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<span style={{ fontSize: 20 }}>⚗️</span>
</div>
<Typography.Text strong style={{ color: '#fff', fontSize: 18, letterSpacing: 0.5 }}>
EchemAgent
</Typography.Text>
</div>
<Menu
mode="horizontal"
selectedKeys={[isChatRoute ? '/chat' : location.pathname]}
items={menuItems}
onClick={({ key }) => navigate(key)}
style={{
flex: 1,
justifyContent: 'center',
background: 'transparent',
borderBottom: 'none',
color: 'rgba(255, 255, 255, 0.85)',
}}
theme="dark"
/>
<Dropdown menu={{ items: userMenuItems }} placement="bottomRight">
<div
style={{
display: 'flex',
alignItems: 'center',
gap: 10,
cursor: 'pointer',
padding: '6px 12px',
borderRadius: 20,
background: 'rgba(255, 255, 255, 0.1)',
transition: 'all 0.3s',
}}
>
<Avatar
size={28}
icon={<UserOutlined />}
style={{ background: 'rgba(255, 255, 255, 0.3)' }}
/>
<Typography.Text style={{ color: '#fff', fontSize: 14 }}>
{user?.username}
</Typography.Text>
</div>
</Dropdown>
</Header>
<Layout>
{isChatRoute && (
<Sider
width={280}
collapsedWidth={0}
collapsible
collapsed={collapsed}
onCollapse={setCollapsed}
trigger={null}
style={{
background: '#fff',
borderRight: '1px solid #f0f0f0',
overflow: 'hidden',
}}
>
<div
style={{
padding: '12px',
borderBottom: '1px solid #f0f0f0',
display: 'flex',
justifyContent: 'flex-end',
}}
>
<Button
type="text"
icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
onClick={() => setCollapsed(!collapsed)}
size="small"
/>
</div>
<Sidebar collapsed={collapsed} />
</Sider>
)}
<Content
style={{
background: isChatRoute ? '#fafbfc' : '#fff',
minHeight: 'calc(100vh - 64px)',
}}
>
<Outlet />
</Content>
</Layout>
</Layout>
);
}
|