import { Suspense, useState } from 'react'
import { Outlet, Navigate, useLocation, useNavigate } from 'react-router-dom'
import { Spin, Layout, Menu, Avatar, Dropdown, Badge } from 'antd'
import {
DashboardOutlined,
CodeOutlined,
TeamOutlined,
SettingOutlined,
UserOutlined,
LogoutOutlined,
SwapOutlined,
MenuFoldOutlined,
MenuUnfoldOutlined,
BellOutlined,
BookOutlined,
FileTextOutlined,
ExperimentOutlined,
} from '@ant-design/icons'
import type { MenuProps } from 'antd'
import { useAuth } from '../auth'
import ErrorBoundary from '../modules/ErrorBoundary'
const { Header, Sider, Content } = Layout
// 运营管理端主色:翠绿
const PRIMARY_COLOR = '#10b981'
/**
* 运营管理端布局(方案A:全浅色)
*
* @description
* - 白色侧边栏 + 翠绿强调色
* - 浅灰内容区,信息清晰
* - 权限检查:SUPER_ADMIN / PROMPT_ENGINEER
*/
const AdminLayout = () => {
const { isAuthenticated, isLoading, user, logout } = useAuth()
const location = useLocation()
const navigate = useNavigate()
const [collapsed, setCollapsed] = useState(false)
// 加载中
if (isLoading) {
return (
)
}
// 未登录
if (!isAuthenticated) {
return
}
// 权限检查:只有 SUPER_ADMIN 和 PROMPT_ENGINEER 可访问
const allowedRoles = ['SUPER_ADMIN', 'PROMPT_ENGINEER']
if (!allowedRoles.includes(user?.role || '')) {
return (
🚫
无权访问运营管理端
需要 SUPER_ADMIN 或 PROMPT_ENGINEER 权限
)
}
// 侧边栏菜单
const menuItems: MenuProps['items'] = [
{
key: '/admin/dashboard',
icon: ,
label: '运营概览',
},
{
key: '/admin/prompts',
icon: ,
label: 'Prompt管理',
},
{
key: '/admin/system-kb',
icon: ,
label: '系统知识库',
},
{
key: '/admin/iit-projects',
icon: ,
label: 'IIT 项目管理',
},
{
key: '/admin/tenants',
icon: ,
label: '租户管理',
},
{
key: '/admin/activity-logs',
icon: ,
label: '运营日志',
},
{
key: '/admin/users',
icon: ,
label: '用户管理',
},
{
key: '/admin/system',
icon: ,
label: '系统配置',
},
]
// 用户下拉菜单
const userMenuItems: MenuProps['items'] = [
{
key: 'switch-app',
icon: ,
label: '切换到业务端',
},
{ type: 'divider' },
{
key: 'logout',
icon: ,
label: '退出登录',
danger: true,
},
]
const handleUserMenuClick = ({ key }: { key: string }) => {
if (key === 'logout') {
logout()
navigate('/login')
} else if (key === 'switch-app') {
navigate('/')
}
}
const handleMenuClick = ({ key }: { key: string }) => {
navigate(key)
}
// 获取当前选中的菜单项
const selectedKey = menuItems.find(item =>
location.pathname.startsWith(item?.key as string)
)?.key as string || '/admin/dashboard'
return (
{/* 侧边栏 - 白色 */}
{/* Logo */}
navigate('/admin/dashboard')}
>
⚙️
{!collapsed && (
运营管理中心
)}
{/* 菜单 */}
{/* 顶部栏 - 白色 */}
{/* 折叠按钮 */}
{/* 右侧工具栏 */}
{/* 通知 */}
{/* 用户 */}
}
style={{ background: PRIMARY_COLOR }}
/>
{user?.name || '管理员'}
{user?.role}
{/* 主内容区 - 浅灰 */}
}
>
)
}
export default AdminLayout