Files
gofly-platform-services/zlt-web/yingyan/src/pages/client/components/LeftPanel/index.tsx
T
2026-04-13 19:17:47 +08:00

213 lines
7.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import React from 'react';
import { Spin, Empty } from 'antd';
import {
EnvironmentOutlined,
AimOutlined,
ThunderboltOutlined,
WifiOutlined,
PlayCircleOutlined,
EyeOutlined,
CompassOutlined,
DownOutlined,
} from '@ant-design/icons';
import type { BoatRouteListVO, BoatWaypointVO, BoatTelemetryData } from '@/types/boatRoute';
import styles from './index.less';
interface LeftPanelProps {
routes: BoatRouteListVO[];
routeWaypointsMap: Record<string, BoatWaypointVO[]>;
loading: boolean;
selectedRouteId: string | null;
onSelectRoute: (routeId: string | null) => void;
deviceInfo: any;
boatData: BoatTelemetryData | null;
sseConnected: boolean;
onStartSailing: (routeId: string) => Promise<void>;
onPreviewRoute: (routeId: string) => void;
sailingLoading: boolean;
}
/** 格式化距离 */
const formatDistance = (meters?: number) => {
if (!meters || meters <= 0) return null;
return meters >= 1000 ? `${(meters / 1000).toFixed(1)}km` : `${Math.round(meters)}m`;
};
/** 格式化时间(秒 → "XX分钟") */
const formatDuration = (seconds?: number) => {
if (!seconds || seconds <= 0) return null;
const min = Math.round(seconds / 60);
return min > 0 ? `${min}分钟` : '<1分钟';
};
const LeftPanel: React.FC<LeftPanelProps> = ({
routes,
routeWaypointsMap,
loading,
selectedRouteId,
onSelectRoute,
deviceInfo,
boatData,
sseConnected,
onStartSailing,
onPreviewRoute,
sailingLoading,
}) => {
const battery = boatData?.battery ?? 0;
const isOnline = sseConnected;
return (
<div className={styles.panel}>
{/* ========== 设备状态卡片 ========== */}
<div className={`${styles.infoCard} ${styles.deviceCard}`}>
<div className={styles.cardHeader}>
<span className={styles.cardTitle}>设备状态</span>
<span className={`${styles.badge} ${isOnline ? styles.badgeGreen : styles.badgeAmber}`}>
<span className={styles.badgeDot} style={{ background: isOnline ? '#10b981' : '#f59e0b' }} />
{isOnline ? '在线' : '离线'}
</span>
</div>
<div className={styles.cardRow}>
<span className={styles.cardLabel}>
<AimOutlined className={styles.cardLabelIcon} />
GPS 信号
</span>
<span className={`${styles.cardValue} ${styles.cardValueGreen}`}>
{boatData?.longitude ? '强' : '弱'}
</span>
</div>
<div className={styles.cardRow}>
<span className={styles.cardLabel}>
<CompassOutlined className={styles.cardLabelIcon} />
当前位置
</span>
<span className={`${styles.cardValue} ${styles.cardValueCyan}`}>
{boatData?.longitude
? `${boatData.longitude.toFixed(2)}°E ${boatData.latitude.toFixed(2)}°N`
: '--'}
</span>
</div>
<div className={styles.cardRow}>
<span className={styles.cardLabel}>
<ThunderboltOutlined className={styles.cardLabelIcon} />
电池电量
</span>
<div className={styles.barGroup}>
<div className={styles.progressBar}>
<div
className={styles.progressFill}
style={{
width: `${battery}%`,
background: battery > 20 ? '#10b981' : '#ff4d4f',
}}
/>
</div>
<span className={`${styles.cardValue} ${styles.cardValueGreen}`}>{battery}%</span>
</div>
</div>
<div className={styles.cardRow}>
<span className={styles.cardLabel}>
<WifiOutlined className={styles.cardLabelIcon} />
通信信号
</span>
<div className={styles.barGroup}>
<div className={styles.progressBar}>
<div
className={styles.progressFill}
style={{
width: `${boatData?.signalStrength ?? 0}%`,
background: '#10b981',
}}
/>
</div>
<span className={`${styles.cardValue} ${styles.cardValueGreen}`}>
{isOnline ? '4G LTE' : '无信号'}
</span>
</div>
</div>
</div>
{/* ========== 分隔线 ========== */}
<div className={styles.divider} />
{/* ========== 航线区域 ========== */}
<div className={styles.routeHeader}>
<span className={styles.routeHeaderTitle}>浏览线路</span>
<span className={styles.routeCountBadge}>
{routes.length} 条航线
<DownOutlined style={{ fontSize: 8 }} />
</span>
</div>
<div className={styles.routeScrollArea}>
{loading ? (
<div className={styles.center}><Spin /></div>
) : routes.length === 0 ? (
<div className={styles.center}>
<Empty description="暂无航线" image={Empty.PRESENTED_IMAGE_SIMPLE} />
</div>
) : (
<div className={styles.routeList}>
{routes.map((route) => {
const isSelected = selectedRouteId === route.routeId;
const waypoints = routeWaypointsMap[route.routeId] || [];
const duration = formatDuration(route.totalDuration);
const distance = formatDistance(route.totalDistance);
const wpCount = route.waypointCount || waypoints.length;
return (
<div
key={route.routeId}
className={`${styles.routeCard} ${isSelected ? styles.routeCardActive : ''}`}
onClick={() => onSelectRoute(isSelected ? null : route.routeId)}
>
<div className={styles.routeCardTop}>
<div className={styles.routeNameRow}>
<EnvironmentOutlined className={styles.routeIcon} />
<span className={styles.routeName}>{route.routeName}</span>
</div>
<span className={`${styles.badge} ${styles.badgeGreen}`}>就绪</span>
</div>
<div className={styles.routeMeta}>
{wpCount}个航点{distance ? ` · 约${distance}` : ''}{duration ? ` · 预计${duration}` : ''}
</div>
{/* 选中时显示操作按钮 */}
{isSelected && (
<div className={styles.routeActions} onClick={(e) => e.stopPropagation()}>
<button
className={styles.btnPreview}
onClick={(e) => { e.stopPropagation(); onPreviewRoute(route.routeId); }}
onTouchEnd={(e) => { e.stopPropagation(); e.preventDefault(); onPreviewRoute(route.routeId); }}
>
<EyeOutlined />
预览航线
</button>
<button
className={styles.btnExecute}
disabled={sailingLoading}
onClick={(e) => { e.stopPropagation(); onStartSailing(route.routeId); }}
onTouchEnd={(e) => { if (sailingLoading) return; e.stopPropagation(); e.preventDefault(); onStartSailing(route.routeId); }}
>
<PlayCircleOutlined />
{sailingLoading ? '启动中...' : '执行航线'}
</button>
</div>
)}
</div>
);
})}
</div>
)}
{routes.length > 2 && <div className={styles.scrollHint}>上下滑动查看更多航线</div>}
</div>
</div>
);
};
export default LeftPanel;