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: '/hall', icon: , label: '抢单大厅' },
{ key: '/orders', icon: , label: '我的订单' },
{ key: '/profile', icon: , label: '个人中心' },
]
const tabItems = [
{ key: '/hall', icon: ShoppingOutlined, label: '抢单大厅' },
{ key: '/orders', icon: ContainerOutlined, label: '我的订单' },
{ key: '/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('已退出登录')
void navigate('/', { replace: true })
}
}
function confirmLogout() {
modal.confirm({
title: '确认退出登录',
content: '退出后需要重新登录才能继续抢单和处理订单。',
okText: '确认退出',
cancelText: '取消',
okButtonProps: { danger: true },
onOk: submitLogout,
})
}
if (isMobile) {
return (
)
}
return (
{username}
{formatWorkerStatus(status)}
)
}
function resolveSelectedKey(pathname: string) {
if (pathname.startsWith('/orders')) return '/orders'
if (pathname.startsWith('/profile')) return '/profile'
return '/hall'
}
function formatWorkerStatus(status: string) {
if (status === 'active') return '已审核'
if (status === 'pending_review') return '待审核'
if (status === 'rejected') return '审核未通过'
if (status === 'disabled') return '已停用'
return '未登录'
}