优化一些细节

This commit is contained in:
mmc
2026-11-16 14:33:48 +08:00
parent 831e1086d3
commit d9f4b752dd
5 changed files with 71 additions and 53 deletions

View File

@@ -79,10 +79,9 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
const tiandituLayersRef = useRef(null);
const esriFallbackLayerRef = useRef(null);
const [baseMapType, setBaseMapType] = useState('satellite');
// 天地图不可用标记:瓦片连续加载失败后降级为 Esri 影像,并隐藏底图切换
// 天地图不可用标记:只要有一个瓦片加载成功即判定可用(不统计失败次数)
const [tiandituUnavailable, setTiandituUnavailable] = useState(false);
const tiandituUnavailableRef = useRef(false);
const tiandituErrorCountRef = useRef(0);
// 场站已配置的返航点 / 分区叠加显示
const stationId = useSelector((state) => state?.station?.stationId || state?.station?.currentStation?.id);
@@ -323,26 +322,16 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
esriFallbackLayer.show = true;
esriFallbackLayerRef.current = esriFallbackLayer;
// 天地图瓦片加载失败累计超过阈值后判定不可用,后续只显示 Esri 影像
const handleTiandituError = () => {
if (tiandituUnavailableRef.current) return;
tiandituErrorCountRef.current += 1;
if (tiandituErrorCountRef.current >= 6) {
tiandituUnavailableRef.current = true;
setTiandituUnavailable(true);
}
// 天地图可用性检测:只要任意一个瓦片加载成功,即判定天地图可用(不判断失败次数)
const handleTiandituLoad = () => {
if (!tiandituUnavailableRef.current) return;
tiandituUnavailableRef.current = false;
setTiandituUnavailable(false);
viewerRef.current?.scene?.requestRender?.();
};
Object.values(tdtLayers).forEach((layer) => {
layer.imageryProvider?.errorEvent?.addEventListener(handleTiandituError);
layer.imageryProvider?.loadEvent?.addEventListener(handleTiandituLoad);
});
// 主动探测天地图服务可达性:请求 0 级瓦片,失败即判定不可用
const probeImg = new Image();
probeImg.onerror = () => {
tiandituUnavailableRef.current = true;
setTiandituUnavailable(true);
};
probeImg.src = `https://t0.tianditu.gov.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX=0&TILEROW=0&TILECOL=0&tk=${TIANDITU_TK}`;
viewer.scene.globe.baseColor = Cesium.Color.BLACK;
viewer.scene.globe.depthTestAgainstTerrain = false;
viewer.scene.requestRenderMode = true; // 👈 加这个(只在需要时渲染)
@@ -364,7 +353,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
return () => {
if (lastFlightPromiseRef.current) viewer.camera.cancelFlight();
Object.values(tdtLayers).forEach((layer) => {
layer.imageryProvider?.errorEvent?.removeEventListener(handleTiandituError);
layer.imageryProvider?.loadEvent?.removeEventListener(handleTiandituLoad);
});
};
}, []);
@@ -3503,11 +3492,17 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
const _allowedFrom = ["mapEditor"];
if (!_allowedFrom.includes(from))
return;
const cartesian = viewer.camera.pickEllipsoid(movement.position, viewer.scene.globe.ellipsoid);
// 优先拾取椭球面;失败时回退到地形拾取,避免视角偏远/贴地平线时打点无效
let cartesian = viewer.camera.pickEllipsoid(movement.position, viewer.scene.globe.ellipsoid);
if (!cartesian) {
const ray = viewer.camera.getPickRay(movement.position);
if (ray) cartesian = viewer.scene.globe.pick(ray, viewer.scene);
}
if (!cartesian) return;
const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
const lon = Cesium.Math.toDegrees(cartographic.longitude);
const lat = Cesium.Math.toDegrees(cartographic.latitude);
if (!Number.isFinite(lon) || !Number.isFinite(lat)) return;
onMarkPointRef.current?.({ lon, lat });
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
@@ -3518,7 +3513,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
return () => {
handler.destroy();
};
}, [drawPoints, from, devices]);
}, [from]);
//useEffect(() => {
// const viewer = viewerRef.current;

View File

@@ -423,7 +423,7 @@ export default function DeviceOverviewPage() {
if (!selectedDevice) return null;
const sn = selectedDevice.device_sn || selectedDevice.serialNumber;
const wsData = realtimeMap[sn] || {};
setDeviceStatistics(wsData || {})
//setDeviceStatistics(wsData || {})
return {
@@ -1181,7 +1181,7 @@ export default function DeviceOverviewPage() {
</div>
<div style={{ display: 'flex', justifyContent: "space-between", flexWrap: 'wrap', gap: 6 }}>
<Button type="primary" style={{ borderRadius: 8, flex: 1 }} onClick={handleStart}>{t('devices.s23')}</Button>
{/*<Button type="primary" style={{ borderRadius: 8, flex: 1 }} onClick={handleStart}>{t('devices.s23')}</Button>*/}
{/*<Button style={{ borderRadius: 8, flex: 1 }} onClick={handlePause}>{t('video.pause')}</Button>*/}
<Button type="primary" style={{ borderRadius: 8, flex: 1 }} onClick={handleAutoBack}>{t('devices.returnHome')}</Button>
{/*<Button style={{ flex: 1, background: '#52c41a', borderColor: '#52c41a', color: "#fff", borderRadius: 8, }} onClick={handleRecharge}>{t('devices.s24')}</Button>*/}
@@ -1359,9 +1359,9 @@ export default function DeviceOverviewPage() {
}}
>
<Statistic
title={<span style={{ fontSize: 11, color: '#666666', fontWeight: 400 }}>{t('devices.statTotalDistance')}</span>}
title={<span style={{ fontSize: 11, color: '#666666', fontWeight: 400 }}>{t('devices.statTotalDistance')}(m)</span>}
value={deviceStatistics?.distance ? Number(deviceStatistics.distance).toFixed(2) : Number(deviceStatistics?.workArea / 0.7 || 0).toFixed(2)}
suffix="m"
suffix=""
valueStyle={{ fontSize: 20, fontWeight: 700, color: '#165DFF', marginTop: 4 }}
/>
</div>
@@ -1378,9 +1378,9 @@ export default function DeviceOverviewPage() {
}}
>
<Statistic
title={<span style={{ fontSize: 11, color: '#666666', fontWeight: 400 }}>{t('devices.s50')}</span>}
title={<span style={{ fontSize: 11, color: '#666666', fontWeight: 400 }}>{t('devices.s50')}(㎡)</span>}
value={Number(deviceStatistics?.workArea || 0).toFixed(2)}
suffix="㎡"
suffix=""
valueStyle={{ fontSize: 20, fontWeight: 700, color: '#165DFF', marginTop: 4 }}
/>
</div>
@@ -1397,9 +1397,9 @@ export default function DeviceOverviewPage() {
}}
>
<Statistic
title={<span style={{ fontSize: 11, color: '#666666', fontWeight: 400 }}>{t('devices.s51')}</span>}
title={<span style={{ fontSize: 11, color: '#666666', fontWeight: 400 }}>{t('devices.s51')}(min)</span>}
value={Number(deviceStatistics?.time || 0).toFixed(2)}
suffix="min"
suffix=""
valueStyle={{ fontSize: 20, fontWeight: 700, color: '#165DFF', marginTop: 4 }}
/>
</div>

View File

@@ -738,12 +738,12 @@ export default function DeviceStatusPage() {
// hasRequestedControlRef.current = true;
// handleControlModal();
//}
return;
//return;
}
console.log(realtimePosition?.controlMode, "现在的控制controlmode")
if (realtimePosition?.controlMode && (realtimePosition?.controlMode != 3 || realtimePosition?.control_mode != 3)) {
if (realtimePosition?.controlMode && (realtimePosition?.controlMode != 3 || realtimePosition?.controlMode != 0)) {
messageApi.warning(t('devices.noRemoteControl'));
return;
//return;
}
console.log('Gamepad state updated:', state);
// 记录方向盘 xy 坐标,用于倒车影像叠加层
@@ -763,6 +763,7 @@ export default function DeviceStatusPage() {
messageApi.warning(t('devices.disconnectGamepadFirst'));
}
return true;
}, [isGamepadConnected, isControlled, t, messageApi]);
// 方向盘功能按钮:复用与手柄一致的遥控帧(指定位按下后短暂释放)
// 方向盘按键按下/释放帧(长按模式:onDown 每 100ms 调用一次;短按模式:sendSteerButton 一次性发送后 300ms 自动释放)
@@ -1347,9 +1348,9 @@ export default function DeviceStatusPage() {
{/*<ConsoleRow icon={<DashboardOutlined />} label={t('devices.rtRightMeasureRpm')} value={(runningStatus?.right_measured_rpm ?? runningStatus?.rightMeasureSpeed) !== undefined ? Number(runningStatus?.right_measured_rpm ?? runningStatus?.rightMeasureSpeed).toFixed(1) + 'rpm' : '-'} />*/}
<ConsoleRow icon={<DashboardOutlined />} label={t('devices.rtLeftMotorRpm')} value={runningStatus?.left_motor_rpm !== undefined ? Number(runningStatus?.left_motor_rpm).toFixed(1) + 'rpm' : '-'} />
<ConsoleRow icon={<DashboardOutlined />} label={t('devices.rtRightMotorRpm')} value={runningStatus?.right_motor_rpm !== undefined ? Number(runningStatus?.right_motor_rpm).toFixed(1) + 'rpm' : '-'} />
<ConsoleRow icon={<GlobalOutlined />} label={t('devices.totalWorkArea')} value={runningStatus?.total_work_area !== undefined ? Number(runningStatus?.total_work_area).toFixed(2) : '-'} />
{/*<ConsoleRow icon={<GlobalOutlined />} label={t('devices.totalWorkArea')} value={runningStatus?.total_work_area !== undefined ? Number(runningStatus?.total_work_area).toFixed(2) : '-'} />
<ConsoleRow icon={<GlobalOutlined />} label={t('devices.totalWorkDuration')} value={runningStatus?.total_work_duration !== undefined ? Number(runningStatus?.total_work_duration).toFixed(0) : '-'} />
<ConsoleRow icon={<GlobalOutlined />} label={t('devices.totalWorkDistance')} value={runningStatus?.total_work_distance !== undefined ? Number(runningStatus?.total_work_distance).toFixed(2) : '-'} />
<ConsoleRow icon={<GlobalOutlined />} label={t('devices.totalWorkDistance')} value={runningStatus?.total_work_distance !== undefined ? Number(runningStatus?.total_work_distance).toFixed(2) : '-'} />*/}
</div>
</div>
</ConsolePanel>

View File

@@ -1555,21 +1555,37 @@ export const MapEditorView = React.forwardRef(function MapEditorView(
}}
>
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{ fontSize: 13, fontWeight: 500 }}>
{route.workName || route.name || t('devices.mapEditor.unnamed')}
</div>
<div style={{ fontSize: 11, color: '#86909C', marginTop: 2 }}>
{t('devices.mapEditor.mode')}: {route.mode === 'coverage' || route.mode === 'coverage_area'
? t('devices.coverageMode') : route.mode === 'predefined_path' ? t('devices.predefinedPathMode')
: t('devices.singleMode')}
{route.routeType && (
<span style={{ marginLeft: 8 }}>
· {route.routeType === 'MOWING_TASK' ? t('devices.mapEditor.typeMowing')
: route.routeType === 'INSPECTION_TASK' ? t('devices.mapEditor.typeInspection')
: t('devices.mapEditor.typeOther')}
</span>
)}
<div style={{ flex: 1, display: 'flex', alignItems: 'center', gap: 8, marginBottom: 4, flexDirection: 'row' }}>
<div>
{route?.imgUrl && (
<img
src={route.imgUrl}
alt=""
style={{ width: 20, height: 20, objectFit: 'cover' }}
/>
)}
</div>
<div>
<div style={{ fontSize: 13, fontWeight: 500 }}>
{route.workName || route.name || t('devices.mapEditor.unnamed')}
</div>
<div style={{ fontSize: 11, color: '#86909C', marginTop: 2 }}>
{t('devices.mapEditor.mode')}: {route.mode === 'coverage' || route.mode === 'coverage_area'
? t('devices.coverageMode') : route.mode === 'predefined_path' ? t('devices.predefinedPathMode')
: t('devices.singleMode')}
{route.routeType && (
<span style={{ marginLeft: 8 }}>
· {route.routeType === 'MOWING_TASK' ? t('devices.mapEditor.typeMowing')
: route.routeType === 'INSPECTION_TASK' ? t('devices.mapEditor.typeInspection')
: t('devices.mapEditor.typeOther')}
</span>
)}
</div>
</div>
</div>
</div>
<Button
size="small"

View File

@@ -1745,7 +1745,7 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
/>
{/* 机器人操作面板(状态信息改为鼠标悬浮机器时在地图上显示) */}
{execute && executingRobot && (
{targetRobot && (
<div
style={{
position: 'absolute',
@@ -1768,7 +1768,7 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
}}
>
<span style={{ fontWeight: 600 }}>
🤖 {executingRobot.deviceAlias || executingRobot.serialNumber}
🤖 {targetRobot.deviceAlias || targetRobot.serialNumber}
</span>
<span>
@@ -2277,7 +2277,7 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
<div style={{ fontWeight: 600, marginBottom: 8 }}>{t('devices.dispatchSource')}</div>
<Radio.Group value={dispatchSource} onChange={e => { setDispatchSource(e.target.value); setDispatchRouteIds([]); setDispatchRegionIds([]); }} buttonStyle="solid">
<Radio.Button value="route">{t('devices.dispatchByRoute')}</Radio.Button>
<Radio.Button value="region">{t('devices.dispatchByRegion')}</Radio.Button>
{/*<Radio.Button value="region">{t('devices.dispatchByRegion')}</Radio.Button>*/}
</Radio.Group>
</div>
@@ -2334,7 +2334,13 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
}}
>
<span style={{ width: 6, height: 6, borderRadius: '50%', background: group.color, flex: '0 0 auto' }} />
<span style={{ flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{route.workName || route.name}</span>
{route?.imgUrl && (
<img
src={route.imgUrl}
alt=""
style={{ width: 20, height: 20, objectFit: 'cover' }}
/>
)} <span style={{ flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{route.workName || route.name}</span>
{checked && <span style={{ color: '#1677ff', fontWeight: 700 }}>✓</span>}
</div>
);