和算法测试成功第一步 状态界面看到经纬度信息和保存可以成功
This commit is contained in:
@@ -95,6 +95,7 @@ export default function DeviceStatusPage() {
|
||||
const [connecting, setConnecting] = useState(false);
|
||||
const [wsStatus, setWsStatus] = useState('disconnected');
|
||||
const [wsDeviceInfo, setWsDeviceInfo] = useState({});
|
||||
const [locationInfo, setLocationInfo] = useState({});
|
||||
|
||||
|
||||
// 👇 加上这两个
|
||||
@@ -387,8 +388,9 @@ export default function DeviceStatusPage() {
|
||||
|
||||
|
||||
const runningStatus = useMemo(() => {
|
||||
console.log(locationInfo, "locationInfo")
|
||||
// 判断对象是否为空
|
||||
if ((!wsDeviceInfo || Object.keys(wsDeviceInfo).length === 0) && !isUAV) {
|
||||
if ((!wsDeviceInfo || Object.keys(wsDeviceInfo).length === 0) && (!locationInfo || Object.keys(locationInfo).length === 0) && !isUAV) {
|
||||
return {};
|
||||
}
|
||||
if (isUAV) {
|
||||
@@ -403,8 +405,10 @@ export default function DeviceStatusPage() {
|
||||
: {
|
||||
...base,
|
||||
...wsDeviceInfo,
|
||||
...locationInfo
|
||||
};
|
||||
}, [device, wsDeviceInfo, isUAV]);
|
||||
}, [device, wsDeviceInfo, isUAV, locationInfo]);
|
||||
console.log(runningStatus, "runningStatus")
|
||||
|
||||
const { video: robotVideo, error, ready } = useWebRTCPlayer(
|
||||
(!isUAV && isVideoPlaying) ? (device?.serialNumber || '') : '',
|
||||
@@ -433,8 +437,8 @@ export default function DeviceStatusPage() {
|
||||
}
|
||||
|
||||
// 2. 机器人:从 wsDeviceInfo / runningStatus 取实时经纬度
|
||||
const robotLon = runningStatus.longitude || wsDeviceInfo.longitude;
|
||||
const robotLat = runningStatus.latitude || wsDeviceInfo.latitude;
|
||||
const robotLon = runningStatus.longitude || locationInfo.longitude;
|
||||
const robotLat = runningStatus.latitude || locationInfo.latitude;
|
||||
|
||||
if (robotLon && robotLat) {
|
||||
return {
|
||||
@@ -453,6 +457,7 @@ export default function DeviceStatusPage() {
|
||||
const controller = new DeviceController(userInfo, messageApi);
|
||||
|
||||
controller.onDeviceInfoUpdate = setWsDeviceInfo;
|
||||
controller.onLocationInfoUpdate = setLocationInfo;
|
||||
controller.onControlStatusChange = setIsControlled;
|
||||
controller.onHasControlRightChange = setHasControlRight;
|
||||
controller.onRequestControlStatusChange = setConnecting;
|
||||
@@ -485,6 +490,7 @@ export default function DeviceStatusPage() {
|
||||
return;
|
||||
}
|
||||
setWsDeviceInfo({});
|
||||
setLocationInfo({});
|
||||
|
||||
controllerRef.current.connectDevice(device);
|
||||
|
||||
@@ -656,103 +662,6 @@ export default function DeviceStatusPage() {
|
||||
};
|
||||
|
||||
// 完成功能 - 调用路径规划接口
|
||||
const handleComplete = async () => {
|
||||
//如果时弓子模式
|
||||
if (isLoopMode) {
|
||||
if (markedPoints.length < 3) {
|
||||
messageApi.warning(t('devices.minThreePoints'));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 准备路径规划请求参数
|
||||
const positionPoints = [...markedPoints];
|
||||
|
||||
|
||||
const requestParams = {
|
||||
reference: {
|
||||
lat: positionPoints[0].lat,
|
||||
lon: positionPoints[0].lon,
|
||||
},
|
||||
heading: 0,
|
||||
outer: {
|
||||
position: positionPoints.map(point => ({
|
||||
lat: point.lat,
|
||||
lon: point.lon,
|
||||
})),
|
||||
sideWidth: 0.0,
|
||||
},
|
||||
holes: [],
|
||||
workType: 0,
|
||||
};
|
||||
|
||||
const response = await fetch('https://servicepathplan.satabot.com/api/path', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(requestParams),
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result) {
|
||||
const path = result?.data?.path?.map(p => {
|
||||
return {
|
||||
lng: p.lon,
|
||||
lat: p.lat
|
||||
}
|
||||
})
|
||||
setPoints(path);
|
||||
setSavePath({
|
||||
path: path, // 存储返回的路径结果
|
||||
outer: requestParams?.outer?.position?.map(p => {
|
||||
return {
|
||||
lng: p.lon,
|
||||
lat: p.lat
|
||||
}
|
||||
}
|
||||
),
|
||||
planModel: 0,
|
||||
});
|
||||
setCompleteFlag(true);
|
||||
messageApi.success(t('devices.pathPlanDone'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('路径规划失败:', error);
|
||||
messageApi.error(t('devices.pathPlanFailRetry'));
|
||||
}
|
||||
} else {
|
||||
const positionPoints = [...markedPoints].map(item => {
|
||||
return {
|
||||
lng: item.lon,
|
||||
lat: item.lat
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
setPoints(positionPoints);
|
||||
setSavePath({
|
||||
path: positionPoints, // 存储返回的路径结果
|
||||
outer: [],
|
||||
planModel: 2,
|
||||
});
|
||||
setCompleteFlag(true);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// 打开保存模态框
|
||||
const handleOpenSaveModal = () => {
|
||||
if (!completeFlag) {
|
||||
messageApi.warning(t('devices.completePathFirst'));
|
||||
return;
|
||||
}
|
||||
setPlotName('');
|
||||
setIsSaveModalVisible(true);
|
||||
};
|
||||
|
||||
// 保存功能
|
||||
const handleSave = async () => {
|
||||
if (!plotName.trim()) {
|
||||
messageApi.warning(t('devices.inputPlotName'));
|
||||
@@ -761,6 +670,15 @@ export default function DeviceStatusPage() {
|
||||
|
||||
setIsSaving(true);
|
||||
try {
|
||||
// ✅重点:接收handleComplete返回的path数据,不再读组件savePath state
|
||||
const pathResult = await handleComplete();
|
||||
if (!pathResult) {
|
||||
messageApi.warning(t('devices.saveFail'));
|
||||
|
||||
// 路径规划失败/校验不通过直接终止
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. 获取地图截图
|
||||
let screenshotDataUrl = null;
|
||||
if (mapRef.current) {
|
||||
@@ -776,18 +694,20 @@ export default function DeviceStatusPage() {
|
||||
const file = dataUrlToFile(screenshotDataUrl, "screenshot.jpg");
|
||||
console.log("blob", file)
|
||||
|
||||
|
||||
if (file instanceof File) {
|
||||
formData.append('file', file);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 添加 workRecord
|
||||
// 4. 添加 workRecord,直接使用函数返回的 pathResult,不读取state savePath
|
||||
const workRecord = {
|
||||
workName: plotName,
|
||||
siteId: stationId,
|
||||
jsonData: savePath,
|
||||
orgId: currentStation?.orgId,
|
||||
jsonData: pathResult, // 直接用返回值,彻底规避state异步延迟
|
||||
mode: isLoopMode ? "coverage" : "single_point",//"区域还是单点"
|
||||
};
|
||||
console.log("workRecord", workRecord)
|
||||
formData.append(
|
||||
"workRecord",
|
||||
new Blob([JSON.stringify(workRecord)], {
|
||||
@@ -795,8 +715,6 @@ export default function DeviceStatusPage() {
|
||||
})
|
||||
);
|
||||
|
||||
//formData.append('workRecord', JSON.stringify(workRecord));
|
||||
|
||||
// 5. 调用保存接口
|
||||
const res = await addRoute(formData);
|
||||
|
||||
@@ -818,6 +736,95 @@ export default function DeviceStatusPage() {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 修改handleComplete:计算完成后 return路径对象;失败返回null
|
||||
*/
|
||||
const handleComplete = async () => {
|
||||
//如果是闭环模式
|
||||
if (isLoopMode) {
|
||||
if (markedPoints.length < 3) {
|
||||
messageApi.warning(t('devices.minThreePoints'));
|
||||
return null; //校验失败返回null
|
||||
}
|
||||
|
||||
try {
|
||||
// 准备路径规划请求参数
|
||||
let positionPoints = [...markedPoints];
|
||||
|
||||
// =========新增:保证闭环,第一个点和最后一个点一致=========
|
||||
const firstPt = positionPoints[0];
|
||||
const lastPt = positionPoints[positionPoints.length - 1];
|
||||
// 判断经纬度是否相等,不相等就把首点追加到末尾
|
||||
if (!(firstPt.lat === lastPt.lat && firstPt.lon === lastPt.lon)) {
|
||||
positionPoints.push({ ...firstPt });
|
||||
}
|
||||
|
||||
const requestParams = {
|
||||
outer: {
|
||||
position: positionPoints.map(point => ({
|
||||
lat: point.lat,
|
||||
lng: point.lon,
|
||||
})),
|
||||
},
|
||||
};
|
||||
|
||||
const path = requestParams?.outer?.position
|
||||
setPoints(path);
|
||||
|
||||
const resultObj = {
|
||||
path: path,
|
||||
outer: requestParams?.outer?.position?.map(p => {
|
||||
return {
|
||||
lng: p.lon,
|
||||
lat: p.lat
|
||||
}
|
||||
}),
|
||||
};
|
||||
|
||||
setSavePath(resultObj);
|
||||
setCompleteFlag(true);
|
||||
messageApi.success(t('devices.pathPlanDone'));
|
||||
return resultObj; // ✅返回计算好的数据给上层调用
|
||||
} catch (error) {
|
||||
console.error('路径规划失败:', error);
|
||||
messageApi.error(t('devices.pathPlanFailRetry'));
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
// 单点模式
|
||||
const positionPoints = [...markedPoints].map(item => {
|
||||
return {
|
||||
lng: item.lon,
|
||||
lat: item.lat
|
||||
}
|
||||
});
|
||||
|
||||
setPoints(positionPoints);
|
||||
|
||||
const resultObj = {
|
||||
path: positionPoints,
|
||||
outer: [],
|
||||
};
|
||||
setSavePath(resultObj);
|
||||
setCompleteFlag(true);
|
||||
|
||||
return resultObj; // ✅返回
|
||||
}
|
||||
};
|
||||
|
||||
// 打开保存模态框
|
||||
const handleOpenSaveModal = () => {
|
||||
//if (!completeFlag) {
|
||||
// messageApi.warning(t('devices.completePathFirst'));
|
||||
// return;
|
||||
//}
|
||||
setPlotName('');
|
||||
setIsSaveModalVisible(true);
|
||||
};
|
||||
|
||||
|
||||
|
||||
const realtimeType = useMemo(() => {
|
||||
return isUAV ? 'plane' : 'car';
|
||||
}, [isUAV]);
|
||||
@@ -856,8 +863,8 @@ export default function DeviceStatusPage() {
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
|
||||
<Text strong>{t('devices.pathPlanning')}:</Text>
|
||||
<Text type="secondary">{t('devices.markedPointsCount', { count: markedPoints.length })}</Text>
|
||||
<Text strong>{t('devices.pathPlanning')}:</Text>
|
||||
<Text type="secondary">{t('devices.markedPointsCount', { count: markedPoints.length })}</Text>
|
||||
</div>
|
||||
<Space size="middle">
|
||||
<Space>
|
||||
@@ -882,18 +889,18 @@ export default function DeviceStatusPage() {
|
||||
>
|
||||
{t('devices.clearMarks')}
|
||||
</Button>
|
||||
<Button
|
||||
{/*<Button
|
||||
type="primary"
|
||||
ghost
|
||||
onClick={handleComplete}
|
||||
disabled={markedPoints.length < 2}
|
||||
>
|
||||
{t('devices.complete')}
|
||||
</Button>
|
||||
</Button>*/}
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={handleOpenSaveModal}
|
||||
disabled={!completeFlag}
|
||||
//disabled={!completeFlag}
|
||||
>
|
||||
{t('common.save')}
|
||||
</Button>
|
||||
@@ -961,7 +968,7 @@ export default function DeviceStatusPage() {
|
||||
title={
|
||||
<>
|
||||
<VideoCameraOutlined />
|
||||
{t('devices.stationVideo')}
|
||||
{t('devices.stationVideo')}
|
||||
</>
|
||||
}
|
||||
bordered={false}
|
||||
@@ -1039,7 +1046,7 @@ export default function DeviceStatusPage() {
|
||||
title={
|
||||
<>
|
||||
<VideoCameraOutlined />
|
||||
{t('devices.droneVideo')}
|
||||
{t('devices.droneVideo')}
|
||||
</>
|
||||
}
|
||||
bordered={false}
|
||||
@@ -1103,33 +1110,33 @@ export default function DeviceStatusPage() {
|
||||
}}>
|
||||
<div style={{ marginBottom: 6, fontWeight: 600, color: '#1890ff' }}>{t('devices.robotStatus')}</div>
|
||||
<div style={{ display: 'flex', gap: '3px 10px', flexWrap: 'wrap' }}>
|
||||
<span>{t('devices.rtBattery')}</span>
|
||||
<span>{t('devices.rtBattery')}:</span>
|
||||
<span style={{ color: (runningStatus.battery || 0) < 20 ? '#ff4d4f' : '#52c41a' }}>
|
||||
{runningStatus.battery !== undefined ? `${runningStatus.battery}%` : '-'}
|
||||
</span>
|
||||
<span>{t('devices.rtVoltage')}</span>
|
||||
<span>{t('devices.rtVoltage')}:</span>
|
||||
<span>{runningStatus.voltage !== undefined ? `${Number(runningStatus.voltage).toFixed(2)}V` : '-'}</span>
|
||||
<span>{t('devices.rtLeftMotor')}</span>
|
||||
<span>{t('devices.rtLeftMotor')}:</span>
|
||||
<span>{runningStatus.leftCurrent !== undefined ? `${Number(runningStatus.leftCurrent).toFixed(2)}A` : '-'}</span>
|
||||
<span>{t('devices.rtRightMotor')}</span>
|
||||
<span>{t('devices.rtRightMotor')}:</span>
|
||||
<span>{runningStatus.rightCurrent !== undefined ? `${Number(runningStatus.rightCurrent).toFixed(2)}A` : '-'}</span>
|
||||
<span>{t('devices.rtLeftSpeed')}</span>
|
||||
<span>{t('devices.rtLeftSpeed')}:</span>
|
||||
<span>{runningStatus.leftMeasureSpeed !== undefined ? `${Number(runningStatus.leftMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
|
||||
<span>{t('devices.rtRightSpeed')}</span>
|
||||
<span>{t('devices.rtRightSpeed')}:</span>
|
||||
<span>{runningStatus.rightMeasureSpeed !== undefined ? `${Number(runningStatus.rightMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
|
||||
<span>{t('devices.rtLeftTemp')}</span>
|
||||
<span>{t('devices.rtLeftTemp')}:</span>
|
||||
<span>{runningStatus.leftMotorTemp !== undefined ? `${Number(runningStatus.leftMotorTemp).toFixed(1)}℃` : '-'}</span>
|
||||
<span>{t('devices.rtRightTemp')}</span>
|
||||
<span>{t('devices.rtRightTemp')}:</span>
|
||||
<span>{runningStatus.rightMotorTemp !== undefined ? `${Number(runningStatus.rightMotorTemp).toFixed(1)}℃` : '-'}</span>
|
||||
<span>{t('devices.rtMainTemp')}</span>
|
||||
<span>{t('devices.rtMainTemp')}:</span>
|
||||
<span>{runningStatus.chipTemp !== undefined ? `${Number(runningStatus.chipTemp).toFixed(1)}℃` : '-'}</span>
|
||||
<span>{t('devices.rtHeadingAngle')}</span>
|
||||
<span>{t('devices.rtHeadingAngle')}:</span>
|
||||
<span>{runningStatus.yaw !== undefined ? `${Number(runningStatus.yaw).toFixed(1)}°` : '-'}</span>
|
||||
<span>{t('devices.rtPitchAngle')}</span>
|
||||
<span>{t('devices.rtPitchAngle')}:</span>
|
||||
<span>{runningStatus.pitch !== undefined ? `${Number(runningStatus.pitch).toFixed(1)}°` : '-'}</span>
|
||||
<span>{t('devices.rtHeadingStatus')}</span>
|
||||
<span>{t('devices.rtHeadingStatus')}:</span>
|
||||
<span>{runningStatus.headingStatus !== undefined ? `${runningStatus.headingStatus == 1 ? t('devices.rtInitialized') : t('devices.uninitialized')}` : '-'}</span>
|
||||
<span>{t('devices.rtPositioning')}</span>
|
||||
<span>{t('devices.rtPositioning')}:</span>
|
||||
<span>
|
||||
{runningStatus.qual == 0 ? t('constants.locationInvalid') :
|
||||
runningStatus.qual == 1 ? t('devices.gpsSingle') :
|
||||
@@ -1137,9 +1144,9 @@ export default function DeviceStatusPage() {
|
||||
runningStatus.qual == 4 ? t('devices.rtkFixed2') :
|
||||
runningStatus.qual == 5 ? t('devices.rtkFloat') : t('constants.locationUnknown')}
|
||||
</span>
|
||||
<span>{t('devices.rtSatellites')}</span>
|
||||
<span>{t('devices.rtSatellites')}:</span>
|
||||
<span>{t('devices.satelliteCount', { count: runningStatus.satelliteCnt || 0 })}</span>
|
||||
<span>{t('devices.rtMode')}</span>
|
||||
<span>{t('devices.rtMode')}:</span>
|
||||
<span>
|
||||
{runningStatus.controlMode == 1 ? t('devices.localMode') :
|
||||
runningStatus.controlMode == 3 ? t('devices.remoteMode') : t('constants.locationUnknown')}
|
||||
@@ -1322,7 +1329,7 @@ export default function DeviceStatusPage() {
|
||||
title={
|
||||
<>
|
||||
<ControlOutlined />
|
||||
{t('devices.remoteControl')}
|
||||
{t('devices.remoteControl')}
|
||||
</>
|
||||
}
|
||||
bordered={false}
|
||||
|
||||
Reference in New Issue
Block a user