feat: 通过接口获取机库和无人机数据
This commit is contained in:
+234
-45
@@ -18,6 +18,9 @@ import {
|
||||
UploadOutlined,
|
||||
DeleteOutlined,
|
||||
PlayCircleOutlined,
|
||||
VideoCameraOutlined,
|
||||
LeftOutlined,
|
||||
RightOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { DroneData } from '../hooks/useDroneSSE';
|
||||
import { waylineRouteApi, WaylineRouteListItemVO, WaypointVO } from '@/services/waylineRoute';
|
||||
@@ -115,9 +118,10 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
const [selectedMissionCode, setSelectedMissionCode] = useState<string | null>(null);
|
||||
const [missionLoading, setMissionLoading] = useState(false);
|
||||
const [createLoading, setCreateLoading] = useState(false);
|
||||
const [imagePreviewVisible, setImagePreviewVisible] = useState(false);
|
||||
const [previewImages, setPreviewImages] = useState<MissionImage[]>([]);
|
||||
const [imageLoading, setImageLoading] = useState(false);
|
||||
const [mediaPreviewVisible, setMediaPreviewVisible] = useState(false);
|
||||
const [previewMediaList, setPreviewMediaList] = useState<MissionImage[]>([]);
|
||||
const [currentMediaIndex, setCurrentMediaIndex] = useState(0);
|
||||
const [mediaLoading, setMediaLoading] = useState(false);
|
||||
|
||||
// Tab 状态
|
||||
const [activeTab, setActiveTab] = useState<string>('route');
|
||||
@@ -261,58 +265,68 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
|
||||
clearWaylineEntities();
|
||||
|
||||
// 调试:打印航点高度信息
|
||||
console.log('[航线绘制] 航点数量:', waypoints.length);
|
||||
console.log('[航线绘制] 前3个航点:', waypoints.slice(0, 3).map(wp => ({
|
||||
index: wp.index,
|
||||
lng: wp.longitude,
|
||||
lat: wp.latitude,
|
||||
height: wp.height,
|
||||
ellipsoidHeight: wp.ellipsoidHeight,
|
||||
})));
|
||||
|
||||
// 使用 height(相对高度)
|
||||
const positions = waypoints.map(wp =>
|
||||
Cesium.Cartesian3.fromDegrees(wp.longitude, wp.latitude, wp.height || 100)
|
||||
Cesium.Cartesian3.fromDegrees(
|
||||
wp.longitude,
|
||||
wp.latitude,
|
||||
wp.height ?? 100
|
||||
)
|
||||
);
|
||||
|
||||
// 计划航线(蓝色)
|
||||
// 计划航线(蓝色)- 使用简单的实线,加粗
|
||||
waylineEntityRef.current = viewer.entities.add({
|
||||
name: '计划航线',
|
||||
polyline: {
|
||||
positions: positions,
|
||||
width: 3,
|
||||
material: new Cesium.PolylineGlowMaterialProperty({
|
||||
glowPower: 0.2,
|
||||
color: Cesium.Color.fromCssColorString('#1890ff'),
|
||||
}),
|
||||
width: 6,
|
||||
material: Cesium.Color.fromCssColorString('#1890ff').withAlpha(0.9),
|
||||
clampToGround: false,
|
||||
},
|
||||
});
|
||||
|
||||
// 航点标记 - 只标注关键航点(首尾和间隔点)避免重叠
|
||||
// 航点标记
|
||||
const totalPoints = waypoints.length;
|
||||
// 根据航点数量决定标注间隔:超过20个点时每5个标一个,超过50个每10个标一个
|
||||
const labelInterval = totalPoints > 50 ? 10 : totalPoints > 20 ? 5 : totalPoints > 10 ? 3 : 1;
|
||||
|
||||
waypoints.forEach((wp, index) => {
|
||||
const isFirst = index === 0;
|
||||
const isLast = index === totalPoints - 1;
|
||||
const isKeyPoint = isFirst || isLast || (index % labelInterval === 0);
|
||||
|
||||
// 航点统一用蓝色系,起点用深蓝,终点用紫色,中间用浅蓝
|
||||
// 避免与无人机(红色)和飞行轨迹(绿色)混淆
|
||||
const pointColor = isFirst ? '#0050b3' : isLast ? '#722ed1' : '#1890ff';
|
||||
const altitude = wp.height ?? 100;
|
||||
|
||||
const entity = viewer.entities.add({
|
||||
name: `航点${index + 1}`,
|
||||
position: Cesium.Cartesian3.fromDegrees(wp.longitude, wp.latitude, wp.height || 100),
|
||||
position: Cesium.Cartesian3.fromDegrees(wp.longitude, wp.latitude, altitude),
|
||||
point: {
|
||||
pixelSize: isKeyPoint ? 8 : 5, // 关键点稍大,普通点更小
|
||||
pixelSize: isKeyPoint ? 12 : 8,
|
||||
color: Cesium.Color.fromCssColorString(pointColor),
|
||||
outlineColor: Cesium.Color.WHITE,
|
||||
outlineWidth: isKeyPoint ? 2 : 1,
|
||||
outlineWidth: 2,
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
},
|
||||
label: isKeyPoint ? {
|
||||
text: isFirst ? '起' : isLast ? '终' : `${index + 1}`,
|
||||
font: '10px sans-serif',
|
||||
font: '12px sans-serif',
|
||||
fillColor: Cesium.Color.WHITE,
|
||||
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
||||
outlineWidth: 2,
|
||||
outlineColor: Cesium.Color.BLACK,
|
||||
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
||||
pixelOffset: new Cesium.Cartesian2(0, -10),
|
||||
scaleByDistance: new Cesium.NearFarScalar(100, 1.0, 5000, 0.5), // 远处缩小
|
||||
} : undefined, // 非关键点不显示标签
|
||||
pixelOffset: new Cesium.Cartesian2(0, -12),
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
} : undefined,
|
||||
});
|
||||
waypointEntitiesRef.current.push(entity);
|
||||
});
|
||||
@@ -442,31 +456,54 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
}
|
||||
}, [selectedRouteId, routeList, deviceSn, tourismId, isDockIdle, loadMissionsByDevice]);
|
||||
|
||||
// 查看任务图片
|
||||
const handleViewMissionImages = useCallback(async (mission: Mission) => {
|
||||
// 判断是否为视频文件
|
||||
const isVideoFile = useCallback((fileType?: string) => {
|
||||
if (!fileType) return false;
|
||||
const videoTypes = ['video/mp4', 'video/webm', 'video/ogg', 'video/quicktime', 'video/x-msvideo'];
|
||||
return videoTypes.includes(fileType.toLowerCase()) || fileType.toLowerCase().startsWith('video/');
|
||||
}, []);
|
||||
|
||||
// 查看任务媒体(图片和视频)
|
||||
const handleViewMissionMedia = useCallback(async (mission: Mission) => {
|
||||
if (!mission.missionCode) return;
|
||||
|
||||
try {
|
||||
setImageLoading(true);
|
||||
setMediaLoading(true);
|
||||
const res = await listMissionImage(mission.missionCode);
|
||||
if (res.resp_code === 0) {
|
||||
setPreviewImages(res.data || []);
|
||||
setPreviewMediaList(res.data || []);
|
||||
setCurrentMediaIndex(0);
|
||||
if (res.data && res.data.length > 0) {
|
||||
setImagePreviewVisible(true);
|
||||
setMediaPreviewVisible(true);
|
||||
} else {
|
||||
message.info('该任务暂无图片');
|
||||
message.info('该任务暂无媒体文件');
|
||||
}
|
||||
} else {
|
||||
message.error(res.resp_msg || '获取图片失败');
|
||||
message.error(res.resp_msg || '获取媒体文件失败');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('获取任务图片失败:', e);
|
||||
message.error('获取任务图片失败');
|
||||
console.error('获取任务媒体失败:', e);
|
||||
message.error('获取媒体文件失败');
|
||||
} finally {
|
||||
setImageLoading(false);
|
||||
setMediaLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 切换到上一个媒体
|
||||
const handlePrevMedia = useCallback(() => {
|
||||
setCurrentMediaIndex(prev => (prev > 0 ? prev - 1 : previewMediaList.length - 1));
|
||||
}, [previewMediaList.length]);
|
||||
|
||||
// 切换到下一个媒体
|
||||
const handleNextMedia = useCallback(() => {
|
||||
setCurrentMediaIndex(prev => (prev < previewMediaList.length - 1 ? prev + 1 : 0));
|
||||
}, [previewMediaList.length]);
|
||||
|
||||
// 当前预览的媒体
|
||||
const currentMedia = useMemo(() => {
|
||||
return previewMediaList[currentMediaIndex];
|
||||
}, [previewMediaList, currentMediaIndex]);
|
||||
|
||||
// 完成任务
|
||||
const handleCompleteMission = useCallback(async (mission: Mission) => {
|
||||
if (!mission.missionCode) return;
|
||||
@@ -801,14 +838,14 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
<div className={styles.taskActions}>
|
||||
<Tooltip title="查看图片">
|
||||
<Tooltip title="查看媒体">
|
||||
<button
|
||||
className={styles.actionBtn}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleViewMissionImages(mission);
|
||||
handleViewMissionMedia(mission);
|
||||
}}
|
||||
disabled={imageLoading}
|
||||
disabled={mediaLoading}
|
||||
>
|
||||
<PictureOutlined />
|
||||
</button>
|
||||
@@ -907,17 +944,169 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 图片预览 */}
|
||||
<Image.PreviewGroup
|
||||
preview={{
|
||||
visible: imagePreviewVisible,
|
||||
onVisibleChange: (vis) => setImagePreviewVisible(vis),
|
||||
}}
|
||||
{/* 媒体预览 Modal(支持图片和视频) */}
|
||||
<Modal
|
||||
title={
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
{currentMedia && isVideoFile(currentMedia.fileType) ? (
|
||||
<VideoCameraOutlined />
|
||||
) : (
|
||||
<PictureOutlined />
|
||||
)}
|
||||
<span>媒体预览</span>
|
||||
{previewMediaList.length > 1 && (
|
||||
<span style={{ fontSize: 12, color: '#999', marginLeft: 8 }}>
|
||||
{currentMediaIndex + 1} / {previewMediaList.length}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
}
|
||||
open={mediaPreviewVisible}
|
||||
onCancel={() => setMediaPreviewVisible(false)}
|
||||
footer={null}
|
||||
width={800}
|
||||
centered
|
||||
destroyOnClose
|
||||
bodyStyle={{ padding: 0, background: '#000', minHeight: 400 }}
|
||||
>
|
||||
{previewImages.map((img, index) => (
|
||||
<Image key={img.id || index} src={img.viewUrl} style={{ display: 'none' }} />
|
||||
))}
|
||||
</Image.PreviewGroup>
|
||||
{currentMedia && (
|
||||
<div style={{ position: 'relative' }}>
|
||||
{/* 媒体内容 */}
|
||||
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', minHeight: 400 }}>
|
||||
{isVideoFile(currentMedia.fileType) ? (
|
||||
<video
|
||||
key={currentMedia.id || currentMediaIndex}
|
||||
src={currentMedia.viewUrl}
|
||||
controls
|
||||
autoPlay
|
||||
style={{ maxWidth: '100%', maxHeight: '70vh' }}
|
||||
>
|
||||
您的浏览器不支持视频播放
|
||||
</video>
|
||||
) : (
|
||||
<Image
|
||||
src={currentMedia.viewUrl}
|
||||
style={{ maxWidth: '100%', maxHeight: '70vh' }}
|
||||
preview={false}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 左右切换按钮 */}
|
||||
{previewMediaList.length > 1 && (
|
||||
<>
|
||||
<button
|
||||
onClick={handlePrevMedia}
|
||||
style={{
|
||||
position: 'absolute',
|
||||
left: 10,
|
||||
top: '50%',
|
||||
transform: 'translateY(-50%)',
|
||||
background: 'rgba(0,0,0,0.5)',
|
||||
border: 'none',
|
||||
borderRadius: '50%',
|
||||
width: 40,
|
||||
height: 40,
|
||||
color: '#fff',
|
||||
cursor: 'pointer',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<LeftOutlined />
|
||||
</button>
|
||||
<button
|
||||
onClick={handleNextMedia}
|
||||
style={{
|
||||
position: 'absolute',
|
||||
right: 10,
|
||||
top: '50%',
|
||||
transform: 'translateY(-50%)',
|
||||
background: 'rgba(0,0,0,0.5)',
|
||||
border: 'none',
|
||||
borderRadius: '50%',
|
||||
width: 40,
|
||||
height: 40,
|
||||
color: '#fff',
|
||||
cursor: 'pointer',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<RightOutlined />
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* 媒体信息 */}
|
||||
<div style={{ padding: '12px 16px', background: '#1f1f1f', color: '#fff' }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||
<span>
|
||||
{isVideoFile(currentMedia.fileType) ? (
|
||||
<Tag color="blue" icon={<VideoCameraOutlined />}>视频</Tag>
|
||||
) : (
|
||||
<Tag color="green" icon={<PictureOutlined />}>图片</Tag>
|
||||
)}
|
||||
</span>
|
||||
{currentMedia.shootTime && (
|
||||
<span style={{ fontSize: 12, color: '#999' }}>
|
||||
拍摄时间: {formatTime(currentMedia.shootTime)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 缩略图列表 */}
|
||||
{previewMediaList.length > 1 && (
|
||||
<div style={{
|
||||
padding: '8px 16px',
|
||||
background: '#1f1f1f',
|
||||
display: 'flex',
|
||||
gap: 8,
|
||||
overflowX: 'auto',
|
||||
}}>
|
||||
{previewMediaList.map((media, index) => (
|
||||
<div
|
||||
key={media.id || index}
|
||||
onClick={() => setCurrentMediaIndex(index)}
|
||||
style={{
|
||||
width: 60,
|
||||
height: 60,
|
||||
flexShrink: 0,
|
||||
cursor: 'pointer',
|
||||
border: index === currentMediaIndex ? '2px solid #1890ff' : '2px solid transparent',
|
||||
borderRadius: 4,
|
||||
overflow: 'hidden',
|
||||
position: 'relative',
|
||||
}}
|
||||
>
|
||||
{isVideoFile(media.fileType) ? (
|
||||
<div style={{
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
background: '#333',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}>
|
||||
<VideoCameraOutlined style={{ fontSize: 20, color: '#fff' }} />
|
||||
</div>
|
||||
) : (
|
||||
<img
|
||||
src={media.viewUrl}
|
||||
alt={`媒体${index + 1}`}
|
||||
style={{ width: '100%', height: '100%', objectFit: 'cover' }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
+5
-4
@@ -395,8 +395,9 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
longitude: droneData.longitude,
|
||||
latitude: droneData.latitude,
|
||||
height: droneData.height, // 相对高度(相对于起飞点)
|
||||
elevation: droneData.elevation, // 海拔高度
|
||||
altitude: droneData.height, // 3D地图显示用
|
||||
elevation: droneData.elevation, // 海拔高度(椭球高度)
|
||||
// 3D地图显示用 height(相对高度),与航线的 height 对应
|
||||
altitude: droneData.height,
|
||||
heading: droneData.attitude_head,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
@@ -407,7 +408,7 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
if (!viewerRef.current || !Cesium || !realtimePosition) return;
|
||||
if (!realtimePosition.longitude || !realtimePosition.latitude) return;
|
||||
|
||||
const droneHeight = realtimePosition.height ?? 50;
|
||||
const droneHeight = realtimePosition.altitude ?? 50;
|
||||
|
||||
viewerRef.current.camera.flyTo({
|
||||
destination: Cesium.Cartesian3.fromDegrees(
|
||||
@@ -434,7 +435,7 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
const currentPos = {
|
||||
lon: realtimePosition.longitude,
|
||||
lat: realtimePosition.latitude,
|
||||
height: realtimePosition.height ?? 0,
|
||||
height: realtimePosition.altitude ?? 0,
|
||||
};
|
||||
|
||||
// 节流:1秒内且位置没变化则跳过
|
||||
|
||||
Reference in New Issue
Block a user