import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Settings2 } from "lucide-react"; import { Switch } from "@/components/ui/switch"; import { Button } from "@/components/ui/button"; import { formatBytes } from "@/utils"; import { useIsMobile } from "@/hooks/useMobile"; interface StatsBarProps { displayOptions: { time: boolean; online: boolean; regions: boolean; traffic: boolean; speed: boolean; }; setDisplayOptions: (options: any) => void; stats: { onlineCount: number; totalCount: number; uniqueRegions: number; totalTrafficUp: number; totalTrafficDown: number; currentSpeedUp: number; currentSpeedDown: number; }; loading: boolean; currentTime: Date; } export const StatsBar = ({ displayOptions, setDisplayOptions, stats, loading, currentTime, }: StatsBarProps) => { const isMobile = useIsMobile(); // 获取已启用的统计项列表 const enabledStats = Object.keys(displayOptions).filter( (key) => displayOptions[key as keyof typeof displayOptions] ); // 渲染统计项 const renderStatItem = (key: string) => { switch (key) { case "time": return ( displayOptions.time && (
) ); case "online": return ( displayOptions.online && (
) ); case "regions": return ( displayOptions.regions && (
) ); case "traffic": return ( displayOptions.traffic && (
{loading ? ( "..." ) : (
{`↑ ${formatBytes(stats.totalTrafficUp)}`} {`↓ ${formatBytes(stats.totalTrafficDown)}`}
)}
) ); case "speed": return ( displayOptions.speed && (
{loading ? ( "..." ) : (
{`↑ ${formatBytes(stats.currentSpeedUp)}/s`} {`↓ ${formatBytes( stats.currentSpeedDown )}/s`}
)}
) ); default: return null; } }; return (
状态显示设置 当前时间 setDisplayOptions({ ...displayOptions, time: checked }) } /> 当前在线 setDisplayOptions({ ...displayOptions, online: checked }) } /> 点亮地区 setDisplayOptions({ ...displayOptions, regions: checked }) } /> 流量概览 setDisplayOptions({ ...displayOptions, traffic: checked }) } /> 网络速率 setDisplayOptions({ ...displayOptions, speed: checked }) } />
{enabledStats.map((key) => renderStatItem(key))}
); };