feat:平板页面
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import React from 'react';
|
||||
import { Spin, Empty } from 'antd';
|
||||
import {
|
||||
ClockCircleOutlined,
|
||||
EnvironmentOutlined,
|
||||
SendOutlined,
|
||||
NodeIndexOutlined,
|
||||
AimOutlined,
|
||||
ThunderboltOutlined,
|
||||
WifiOutlined,
|
||||
PlayCircleOutlined,
|
||||
EyeOutlined,
|
||||
CompassOutlined,
|
||||
DownOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import type { BoatRouteListVO, BoatWaypointVO } from '@/types/boatRoute';
|
||||
import type { BoatRouteListVO, BoatWaypointVO, BoatTelemetryData } from '@/types/boatRoute';
|
||||
import styles from './index.less';
|
||||
|
||||
interface LeftPanelProps {
|
||||
@@ -15,8 +19,20 @@ interface LeftPanelProps {
|
||||
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;
|
||||
@@ -24,98 +40,170 @@ const formatDuration = (seconds?: number) => {
|
||||
return min > 0 ? `${min}分钟` : '<1分钟';
|
||||
};
|
||||
|
||||
/** 格式化距离 */
|
||||
const formatDistance = (meters?: number) => {
|
||||
if (!meters || meters <= 0) return null;
|
||||
return meters >= 1000 ? `${(meters / 1000).toFixed(1)}km` : `${Math.round(meters)}m`;
|
||||
};
|
||||
|
||||
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.header}>
|
||||
<div className={styles.headerIcon}>
|
||||
<SendOutlined />
|
||||
{/* ========== 设备状态卡片 ========== */}
|
||||
<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>
|
||||
<div className={styles.headerTitle}>游览线路</div>
|
||||
<div className={styles.headerSub}>选择线路开始游览</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>
|
||||
<span className={styles.count}>{routes.length}</span>
|
||||
</div>
|
||||
|
||||
<div className={styles.list}>
|
||||
{/* ========== 分隔线 ========== */}
|
||||
<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} />
|
||||
<Empty description="暂无航线" image={Empty.PRESENTED_IMAGE_SIMPLE} />
|
||||
</div>
|
||||
) : (
|
||||
routes.map((route) => {
|
||||
const isSelected = selectedRouteId === route.routeId;
|
||||
const waypoints = routeWaypointsMap[route.routeId] || [];
|
||||
const duration = formatDuration(route.totalDuration);
|
||||
const distance = formatDistance(route.totalDistance);
|
||||
<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;
|
||||
|
||||
// 构建航点路径名称列表
|
||||
const waypointNames = waypoints
|
||||
.filter((wp) => wp.pointName)
|
||||
.map((wp) => wp.pointName);
|
||||
|
||||
return (
|
||||
<div
|
||||
key={route.routeId}
|
||||
className={`${styles.routeCard} ${isSelected ? styles.routeCardActive : ''}`}
|
||||
onClick={() => onSelectRoute(isSelected ? null : route.routeId)}
|
||||
>
|
||||
{/* 线路名称 */}
|
||||
<div className={styles.routeName}>{route.routeName}</div>
|
||||
|
||||
{/* 时长 + 距离 标签 */}
|
||||
<div className={styles.tagRow}>
|
||||
{duration && (
|
||||
<span className={styles.tag}>
|
||||
<ClockCircleOutlined className={styles.tagIcon} />
|
||||
{duration}
|
||||
</span>
|
||||
)}
|
||||
{distance && (
|
||||
<span className={styles.tag}>
|
||||
<EnvironmentOutlined className={styles.tagIcon} />
|
||||
{distance}
|
||||
</span>
|
||||
)}
|
||||
<span className={styles.tag}>
|
||||
<NodeIndexOutlined className={styles.tagIcon} />
|
||||
{route.waypointCount || waypoints.length}个景点
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 航点路径 */}
|
||||
{waypointNames.length > 0 && (
|
||||
<div className={styles.waypointPath}>
|
||||
{waypointNames.map((name, idx) => (
|
||||
<React.Fragment key={idx}>
|
||||
<span className={styles.waypointDot} />
|
||||
<span className={styles.waypointName}>{name}</span>
|
||||
{idx < waypointNames.length - 1 && (
|
||||
<span className={styles.waypointArrow}>→</span>
|
||||
)}
|
||||
</React.Fragment>
|
||||
))}
|
||||
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>
|
||||
);
|
||||
})
|
||||
<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>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user