import React, { useMemo } from 'react'; import { Tabs } from 'antd'; import { useLocation } from 'react-router-dom'; import MinesweeperGame from './MinesweeperGame'; import MinesweeperLeaderboard from './MinesweeperLeaderboard'; import SpectatorMinesweeper from './SpectatorMinesweeper'; const MinesweeperTabs: React.FC = () => { const location = useLocation(); // 检查是否在旁观模式 const isSpectatorMode = location.pathname.startsWith('/spectate/'); const roomId = isSpectatorMode ? location.pathname.split('/')[2] : null; // 选项卡内容 const items = useMemo(() => { if (isSpectatorMode && roomId) { // 旁观模式:只显示旁观组件 return [ { key: 'spectator', label: '旁观模式', children: , }, ]; } else { // 正常模式:显示游戏和排行榜 return [ { key: 'game', label: '扫雷游戏', children: , }, { key: 'leaderboard', label: '排行榜', children: , }, ]; } }, [isSpectatorMode, roomId]); return (
{isSpectatorMode && roomId ? ( ) : ( )}
); }; export default MinesweeperTabs;