Files
gofly-platform-services/zlt-web/yingyan/src/components/PlatformSwitcher/index.tsx
T

105 lines
3.4 KiB
TypeScript

import React from 'react';
import { history, useLocation } from 'umi';
import { Dropdown, Space } from 'antd';
import { SwapOutlined } from '@ant-design/icons';
import type { MenuProps } from 'antd';
import './PlatformSwitcher.less';
// 船舶图标
const ShipIcon = () => (
<svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor">
<path d="M20 21c-1.39 0-2.78-.47-4-1.32-2.44 1.71-5.56 1.71-8 0C6.78 20.53 5.39 21 4 21H2v2h2c1.38 0 2.74-.35 4-.99 2.52 1.29 5.48 1.29 8 0 1.26.64 2.63.99 4 .99h2v-2h-2zM3.95 19H4c1.6 0 3.02-.88 4-2 .98 1.12 2.4 2 4 2s3.02-.88 4-2c.98 1.12 2.4 2 4 2h.05l1.89-6.68c.08-.26.06-.54-.06-.78s-.34-.42-.6-.5L20 10.62V6c0-1.1-.9-2-2-2h-3V1H9v3H6c-1.1 0-2 .9-2 2v4.62l-1.29.42c-.26.08-.48.26-.6.5s-.15.52-.06.78L3.95 19zM6 6h12v3.97L12 8 6 9.97V6z"/>
</svg>
);
// 仪表盘图标
const DashboardIcon = () => (
<svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor">
<path d="M3 13h8V3H3v10zm0 8h8v-6H3v6zm10 0h8V11h-8v10zm0-18v6h8V3h-8z"/>
</svg>
);
interface Platform {
key: string;
label: string;
path: string;
icon: React.ReactNode;
description: string;
theme: 'cyan' | 'ocean';
}
const platforms: Platform[] = [
{
key: 'dashboard',
label: '无人机智慧城市',
path: '/dashboard',
icon: <DashboardIcon />,
description: '城市态势与空地协同',
theme: 'cyan',
},
{
key: 'maritime',
label: '海事智慧监控',
path: '/maritime',
icon: <ShipIcon />,
description: '船舶追踪与海域监控',
theme: 'ocean',
},
];
interface PlatformSwitcherProps {
className?: string;
}
const PlatformSwitcher: React.FC<PlatformSwitcherProps> = ({ className }) => {
const location = useLocation();
// 确定当前平台
const currentPlatform = platforms.find(p => location.pathname.startsWith(p.path)) || platforms[0];
const isMaritime = currentPlatform.key === 'maritime';
const handlePlatformChange = (path: string) => {
history.push(path);
};
const menuItems: MenuProps['items'] = platforms.map(platform => ({
key: platform.key,
label: (
<div className={`platform-menu-item ${platform.key === currentPlatform.key ? 'active' : ''}`}>
<span className={`platform-menu-item__icon platform-menu-item__icon--${platform.theme}`}>
{platform.icon}
</span>
<div className="platform-menu-item__content">
<div className="platform-menu-item__label">{platform.label}</div>
<div className="platform-menu-item__desc">{platform.description}</div>
</div>
{platform.key === currentPlatform.key && (
<span className="platform-menu-item__check">&#10003;</span>
)}
</div>
),
onClick: () => handlePlatformChange(platform.path),
}));
return (
<Dropdown
menu={{ items: menuItems }}
placement="bottomLeft"
trigger={['click']}
overlayClassName="platform-switcher-dropdown"
>
<div className={`platform-switcher ${isMaritime ? 'platform-switcher--ocean' : ''} ${className || ''}`}>
<Space>
<span className={`platform-switcher__icon platform-switcher__icon--${currentPlatform.theme}`}>
{currentPlatform.icon}
</span>
<span className="platform-switcher__label">{currentPlatform.label}</span>
<SwapOutlined className="platform-switcher__arrow" />
</Space>
</div>
</Dropdown>
);
};
export default PlatformSwitcher;