'use client'; import { FC } from 'react'; import Link from 'next/link'; import Image from 'next/image'; import { usePathname, useRouter } from 'next/navigation'; import { cn } from '@/utils/helpers'; import { useAppSelector, useAppDispatch } from '@/store/redux/hooks'; import { toggleSidebar } from '@/store/redux/slices/settingsSlice'; import { logoutService } from '@/services/authService'; import { toast } from '@/components/common'; import styles from './Sidebar.module.scss'; /** * 侧边栏菜单项配置 */ interface MenuItem { key: string; icon: string; label: string; path: string; } // 主导航菜单 const topMenuItems: MenuItem[] = [ { key: 'dashboard', icon: '/images/Container1.svg', label: '仪表板', path: '/dashboard' }, { key: 'users', icon: '/images/Container2.svg', label: '用户管理', path: '/users' }, { key: 'leaderboard', icon: '/images/Container3.svg', label: '龙虎榜', path: '/leaderboard' }, { key: 'authorization', icon: '/images/Container4.svg', label: '授权管理', path: '/authorization' }, { key: 'co-managed-wallet', icon: '/images/Container4.svg', label: '共管钱包', path: '/co-managed-wallet' }, { key: 'notifications', icon: '/images/Container3.svg', label: '通知管理', path: '/notifications' }, { key: 'pending-actions', icon: '/images/Container3.svg', label: '待办操作', path: '/pending-actions' }, { key: 'withdrawals', icon: '/images/Container5.svg', label: '提现审核', path: '/withdrawals' }, { key: 'statistics', icon: '/images/Container5.svg', label: '数据统计', path: '/statistics' }, { key: 'maintenance', icon: '/images/Container6.svg', label: '系统维护', path: '/maintenance' }, { key: 'settings', icon: '/images/Container6.svg', label: '系统设置', path: '/settings' }, ]; // 底部导航菜单 const bottomMenuItems: MenuItem[] = [ { key: 'help', icon: '/images/Container7.svg', label: '帮助中心', path: '/help' }, ]; /** * 侧边栏组件 * 基于 UIPro Figma 设计实现 */ export const Sidebar: FC = () => { const pathname = usePathname(); const router = useRouter(); const dispatch = useAppDispatch(); const collapsed = useAppSelector((state) => state.settings.sidebarCollapsed); // 切换侧边栏展开/收起 const handleToggle = () => { dispatch(toggleSidebar()); }; // 退出登录 const handleLogout = () => { // 清除所有上下文和存储 logoutService.logout(); toast.success('已安全退出登录'); // 跳转到登录页 router.push('/login'); }; // 渲染菜单项 const renderMenuItem = (item: MenuItem) => { const isActive = pathname === item.path || pathname.startsWith(`${item.path}/`); return ( {item.label} {!collapsed && {item.label}} ); }; return ( ); };