'use client';
import { useEffect, useState } from 'react';
import { usePathname, useRouter } from 'next/navigation';
import {
DashboardOutlined,
FileSearchOutlined,
LogoutOutlined,
MessageOutlined,
MoneyCollectOutlined,
SettingOutlined,
TeamOutlined,
UserOutlined,
} from '@ant-design/icons';
import { Avatar, Dropdown, Layout, Menu } from 'antd';
import { clearAuth, getAdmin, getToken } from '@/lib/auth';
import type { AdminInfo } from '@/lib/types';
const { Sider, Header, Content } = Layout;
const MENU = [
{ key: '/dashboard', icon: , label: '数据大盘' },
{ key: '/users', icon: , label: '用户管理' },
{ key: '/withdraws', icon: , label: '提现管理' },
{ key: '/feedbacks', icon: , label: '反馈工单' },
{ key: '/config', icon: , label: '系统配置' },
{ key: '/admins', icon: , label: '管理员', superOnly: true },
{ key: '/audit-logs', icon: , label: '审计日志' },
];
export default function MainLayout({ children }: { children: React.ReactNode }) {
const router = useRouter();
const pathname = usePathname();
const [admin, setAdmin] = useState(null);
useEffect(() => {
if (!getToken()) {
router.replace('/login');
return;
}
setAdmin(getAdmin());
}, [router]);
if (!admin) return null; // 守卫期间不闪烁内容
const items = MENU.filter((m) => !m.superOnly || admin.role === 'super_admin').map((m) => ({
key: m.key,
icon: m.icon,
label: m.label,
}));
// 选中态:取路径一级(/users/123 → /users)
const selectedKey = '/' + (pathname.split('/')[1] || 'dashboard');
const logout = () => {
clearAuth();
router.replace('/login');
};
return (
运营后台
, label: '退出登录', onClick: logout },
],
}}
>
} /> {admin.username}({admin.role})
{children}
);
}