import { ContainerOutlined, LogoutOutlined, ShoppingOutlined, UserOutlined, } from '@ant-design/icons' import { App, Button, Layout, Menu, Typography } from 'antd' import type { MenuProps } from 'antd' import { Outlet, useLocation, useNavigate } from 'react-router' import { logoutWorker } from '@/services/worker' import { useIsMobile } from '@/utils/use-is-mobile' import { clearWorkerSession, getWorkerStatus, getWorkerUsername } from '@/utils/worker-auth' const menuItems: MenuProps['items'] = [ { key: '/worker/hall', icon: , label: '抢单大厅' }, { key: '/worker/orders', icon: , label: '我的订单' }, { key: '/worker/profile', icon: , label: '个人中心' }, ] const tabItems = [ { key: '/worker/hall', icon: ShoppingOutlined, label: '抢单大厅' }, { key: '/worker/orders', icon: ContainerOutlined, label: '我的订单' }, { key: '/worker/profile', icon: UserOutlined, label: '个人中心' }, ] export default function WorkerLayout() { const navigate = useNavigate() const location = useLocation() const isMobile = useIsMobile() const { message, modal } = App.useApp() const username = getWorkerUsername() || '打手' const status = getWorkerStatus() const currentKey = resolveSelectedKey(location.pathname) async function submitLogout() { try { await logoutWorker() } catch { // 接单端退出为无状态操作,本地清理优先。 } finally { clearWorkerSession() message.success('已退出登录') navigate('/worker/login', { replace: true }) } } function confirmLogout() { modal.confirm({ title: '确认退出登录', content: '退出后需要重新登录才能继续抢单和处理订单。', okText: '确认退出', cancelText: '取消', okButtonProps: { danger: true }, onOk: submitLogout, }) } if (isMobile) { return (
王大锤接单
) } return (
王大锤 接单平台
{username} {formatWorkerStatus(status)}
navigate(String(key))} />
) } function resolveSelectedKey(pathname: string) { if (pathname.startsWith('/worker/orders')) return '/worker/orders' if (pathname.startsWith('/worker/profile')) return '/worker/profile' return '/worker/hall' } function formatWorkerStatus(status: string) { if (status === 'active') return '已审核' if (status === 'pending_review') return '待审核' if (status === 'rejected') return '审核未通过' if (status === 'disabled') return '已停用' return '未登录' }