import { useEffect, useState } from 'react' import { BrowserRouter, Link, Navigate, Route, Routes, useLocation, useNavigate } from 'react-router-dom' import { App, ConfigProvider, Layout, Menu, Typography, Button, Tag, Space, Spin, type MenuProps } from 'antd' import { AccountBookOutlined, ApiOutlined, DashboardOutlined, DollarCircleOutlined, EyeOutlined, FileSearchOutlined, LogoutOutlined, OrderedListOutlined, SettingOutlined, ShopOutlined, SkinOutlined, UserOutlined, WalletOutlined, } from '@ant-design/icons' import { getMe, logout, type CurrentMember, getStoredToken } from './api' import { MemberContext } from './MemberContext' import Dashboard from './pages/Dashboard' import Sites from './pages/Sites' import Rules from './pages/Rules' import Payments from './pages/Payments' import Accounts from './pages/Accounts' import Settlements from './pages/Settlements' import Orders from './pages/Orders' import Wallet from './pages/Wallet' import SiteSettings from './pages/SiteSettings' import Login from './pages/Login' import Storefront from './pages/Storefront' import './style.css' type MenuItem = Required['items'][number] function MainLayout({ member, onLogout }: { member: CurrentMember; onLogout: () => void }) { const location = useLocation() const menuItems: MenuItem[] = [ { key: '/', icon: , label: 仪表盘 }, ...(member.is_superadmin ? [{ key: '/sites', icon: , label: 分销站点管理 }] : []), { key: '/orders', icon: , label: 全部分销订单 }, { key: '/sold', icon: , label: 售出账号订单 }, { key: '/receive', icon: , label: 分销收号管理 }, { key: '/accounts', icon: , label: 商品货架与加价 }, { key: '/wallet', icon: , label: 资金与提现 }, { key: '/settlements', icon: , label: {member.is_superadmin ? '结算批次管理' : '周期对账单'}, }, { key: '/settings', icon: , label: 品牌装修 }, ...(member.is_superadmin ? [{ key: '/payments', icon: , label: 支付通道配置 }] : []), { key: '/rules', icon: , label: {member.is_superadmin ? '比例与税费规则' : '合作政策与权益'}, }, ] const selectedKey = menuItems.some((item) => item && 'key' in item && item.key === location.pathname) ? location.pathname : '/' const roleLabel = member.is_superadmin ? '平台超级管理员' : member.member_type === 'operator' ? '分销运营' : member.member_type === 'finance' ? '分销财务' : '分销成员' return (
HFB 分销后台
{member.is_superadmin ? ( 平台全局管理模式 ) : ( {member.site_name || '当前分销站点'} · {member.domain || member.site_code} )} 主站 hao858.com · 分销管理系统
{member.site_code && ( )}
{member.nickname || member.username} {roleLabel}
} /> {member.is_superadmin && } />} } /> } /> } /> } /> } /> } /> } /> } /> } /> } />
) } function AppContent() { const [member, setMember] = useState(null) const [loading, setLoading] = useState(true) const navigate = useNavigate() const location = useLocation() const isPublicStorefront = location.pathname.startsWith('/site') useEffect(() => { let active = true const checkAuth = async () => { // For public storefront, we do not force login if (isPublicStorefront) { try { const profile = await getMe() if (active) setMember(profile) } catch { // ignore auth error on public storefront } finally { if (active) setLoading(false) } return } // If no token exists and no session, skip getMe if (!getStoredToken() && location.pathname === '/login') { if (active) setLoading(false) return } try { const profile = await getMe() if (active) { setMember(profile) if (location.pathname === '/login') { navigate('/', { replace: true }) } } } catch { if (active) { setMember(null) if (location.pathname !== '/login') { navigate('/login', { replace: true }) } } } finally { if (active) setLoading(false) } } checkAuth() return () => { active = false } }, [location.pathname, navigate, isPublicStorefront]) const handleLogout = async () => { await logout() setMember(null) navigate('/login', { replace: true }) } const handleLoginSuccess = (current: CurrentMember) => { setMember(current) navigate('/', { replace: true }) } if (isPublicStorefront) { return ( } /> } /> } /> ) } if (loading) { return (
) } if (location.pathname === '/login') { return } if (!member) { return } return } export default function AppShell() { return ( ) }