Spaces:
Sleeping
Sleeping
File size: 6,800 Bytes
a9df8b1 | 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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | import { useState } from 'react'
import { Layout, Menu, Switch, Badge, Tooltip, Avatar, Tag, Grid, Button } from 'antd'
import {
DashboardOutlined,
BookOutlined,
ApartmentOutlined,
PlayCircleOutlined,
SyncOutlined,
ExperimentOutlined,
CloudUploadOutlined,
BranchesOutlined,
BulbOutlined,
BulbFilled,
WifiOutlined,
RocketOutlined,
BarChartOutlined,
SafetyCertificateOutlined,
TranslationOutlined,
} from '@ant-design/icons'
import { useNavigate, useLocation } from 'react-router-dom'
import { motion } from 'framer-motion'
import { useAppStore } from '@/store/appStore'
import { useWebSocket } from '@/hooks/useWebSocket'
import { useT } from '@/i18n'
const { Header, Sider, Content } = Layout
const { useBreakpoint } = Grid
export default function AppLayout({ children }: { children: React.ReactNode }) {
const [collapsed, setCollapsed] = useState(false)
const screens = useBreakpoint()
const navigate = useNavigate()
const location = useLocation()
const { darkMode, toggleDark, wsEvents, lang, setLang } = useAppStore()
const t = useT(lang)
useWebSocket()
const isNarrow = screens.xs && !screens.md
const siderCollapsed = isNarrow ? true : collapsed
const unreadEvents = wsEvents.filter(e => e.type !== 'pong' && e.type !== 'connected').length
const menuItems = [
{
type: 'group' as const,
label: t.groupOverview,
children: [
{ key: '/', icon: <DashboardOutlined />, label: t.menuDashboard },
{ key: '/evaluation', icon: <BarChartOutlined />, label: t.menuEvaluation },
],
},
{
type: 'group' as const,
label: t.groupSkillMgmt,
children: [
{ key: '/ingest', icon: <CloudUploadOutlined />, label: t.menuIngest },
{ key: '/wiki', icon: <BookOutlined />, label: t.menuWiki },
{ key: '/graph', icon: <ApartmentOutlined />, label: t.menuGraph },
{ key: '/lifecycle', icon: <ExperimentOutlined />, label: t.menuLifecycle },
{ key: '/versions', icon: <BranchesOutlined />, label: t.menuVersions },
],
},
{
type: 'group' as const,
label: t.groupAgentEvolution,
children: [
{ key: '/harness', icon: <SafetyCertificateOutlined />, label: t.menuHarness },
{ key: '/execution', icon: <PlayCircleOutlined />, label: t.menuExecution },
{ key: '/evolution', icon: <SyncOutlined />, label: t.menuEvolution },
{
key: '/demo',
icon: <RocketOutlined />,
label: (
<span style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
{t.menuDemo}
<Tag color="red" style={{ fontSize: 10, padding: '0 4px', lineHeight: '16px', marginLeft: 2 }}>DEMO</Tag>
</span>
),
},
],
},
]
return (
<Layout style={{ minHeight: '100vh' }}>
<Sider
collapsible
collapsed={siderCollapsed}
onCollapse={setCollapsed}
collapsedWidth={isNarrow ? 64 : 80}
width={isNarrow ? 64 : 200}
theme={darkMode ? 'dark' : 'light'}
style={{
boxShadow: '2px 0 8px rgba(0,0,0,0.08)',
zIndex: 10,
}}
>
<motion.div
style={{
height: 64,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
padding: '0 16px',
borderBottom: '1px solid rgba(0,0,0,0.06)',
}}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
>
{!siderCollapsed ? (
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<Avatar
style={{ background: 'linear-gradient(135deg, #1677ff, #722ed1)', flexShrink: 0 }}
size={32}
>
S
</Avatar>
<span style={{ fontWeight: 800, fontSize: 16, color: darkMode ? '#fff' : '#1677ff', whiteSpace: 'nowrap' }}>
SkillWiki
</span>
</div>
) : (
<Avatar style={{ background: 'linear-gradient(135deg, #1677ff, #722ed1)' }} size={32}>S</Avatar>
)}
</motion.div>
<Menu
theme={darkMode ? 'dark' : 'light'}
mode="inline"
selectedKeys={[location.pathname]}
items={menuItems}
onClick={({ key }) => navigate(key)}
inlineCollapsed={siderCollapsed}
style={{ borderRight: 0, marginTop: 8 }}
/>
</Sider>
<Layout>
<Header
style={{
background: darkMode ? '#141414' : '#fff',
padding: isNarrow ? '0 12px' : '0 24px',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
gap: 12,
boxShadow: '0 1px 4px rgba(0,0,0,0.08)',
zIndex: 9,
}}
>
<div
style={{
fontWeight: 600,
color: darkMode ? '#fff' : '#333',
minWidth: 0,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}}
>
{isNarrow ? t.appTitleShort : t.appTitle}
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
<Tooltip title={`${unreadEvents} ${t.liveEvents}`}>
<Badge count={Math.min(unreadEvents, 99)} size="small">
<WifiOutlined style={{ fontSize: 18, color: '#52c41a', cursor: 'pointer' }} />
</Badge>
</Tooltip>
<Tooltip title={darkMode ? t.switchLight : t.switchDark}>
<Switch
checked={darkMode}
onChange={toggleDark}
checkedChildren={<BulbFilled />}
unCheckedChildren={<BulbOutlined />}
/>
</Tooltip>
<Tooltip title={t.langToggle}>
<Button
size="small"
icon={<TranslationOutlined />}
onClick={() => setLang(lang === 'en' ? 'zh' : 'en')}
style={{ fontWeight: 600, minWidth: 56 }}
>
{t.langToggle}
</Button>
</Tooltip>
</div>
</Header>
<Content
style={{
background: darkMode ? '#1f1f1f' : '#f5f7fa',
overflow: 'auto',
minHeight: 'calc(100vh - 64px)',
}}
>
<motion.div
key={location.pathname}
initial={{ opacity: 0, y: 8 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.2 }}
>
{children}
</motion.div>
</Content>
</Layout>
</Layout>
)
}
|