'use client'; import React, { useEffect, useState } from 'react'; import { Avatar, Badge, Button, Dropdown, Layout, Menu, Space, Switch, Typography, message, theme } from 'antd'; import { BellOutlined, DashboardOutlined, FileTextOutlined, SafetyCertificateOutlined, ScanOutlined, SearchOutlined, SettingOutlined, UserOutlined, VideoCameraOutlined, } from '@ant-design/icons'; import { usePathname, useRouter } from 'next/navigation'; import { BackendApi } from '@/services/backendApi'; import { useAppStore } from '@/store/useAppStore'; import type { ApiMode } from '@/types'; const { Header } = Layout; const { Text, Paragraph, Title } = Typography; export const TopHeader: React.FC = () => { const pathname = usePathname(); const router = useRouter(); const { user, notifications } = useAppStore(); const { token } = theme.useToken(); const [apiMode, setApiMode] = useState(null); const [switchingMode, setSwitchingMode] = useState(false); const [messageApi, contextHolder] = message.useMessage(); const unreadCount = notifications.filter((notification) => !notification.read).length; useEffect(() => { BackendApi.getApiMode() .then(setApiMode) .catch(() => setApiMode(null)); }, []); const menuItems = [ { key: '/', icon: , label: '首页' }, { key: '/video', icon: , label: '视频监控' }, { key: '/machines', icon: , label: '机器查询' }, { key: '/customs', icon: , label: '报关单' }, { key: '/inspection', icon: , label: '远程查验' }, ]; const notificationMenu = { items: notifications.map((notification) => ({ key: notification.id, label: (
{notification.title} {notification.message} {notification.time}
), })), }; const toggleApiMode = async (nextTestMode: boolean) => { setSwitchingMode(true); try { const nextMode = await BackendApi.setApiMode(nextTestMode); setApiMode(nextMode); messageApi.success(`已切换至${nextMode.label}`); } catch (error) { messageApi.error(error instanceof Error ? error.message : '切换 API 环境失败'); } finally { setSwitchingMode(false); } }; return ( <> {contextHolder}
router.push('/')} style={{ cursor: 'pointer', marginRight: 48, display: 'flex', alignItems: 'center' }} > 海关智慧查验平台 router.push(key)} style={{ flex: 1, minWidth: 0, borderBottom: 'none', lineHeight: '62px' }} /> {apiMode?.label ?? '环境'}
); };