添加问号 优化错误

This commit is contained in:
mmc
2026-09-02 15:38:05 +08:00
parent 1b558f6376
commit 008af5111f

View File

@@ -452,15 +452,15 @@ export default function DeviceStatusPage() {
}
// 2. 机器人:从 wsDeviceInfo / runningStatus 取实时经纬度
const robotLon = runningStatus.longitude || locationInfo.longitude;
const robotLat = runningStatus.latitude || locationInfo.latitude;
const robotLon = runningStatus?.longitude || wsDeviceInfo?.longitude;
const robotLat = runningStatus?.latitude || wsDeviceInfo?.latitude;
if (robotLon && robotLat) {
return {
lon: robotLon,
lat: robotLat,
//heading: -98
heading: runningStatus.yaw || wsDeviceInfo.yaw || 0,
heading: runningStatus?.yaw || wsDeviceInfo?.yaw || 0,
};
}
@@ -593,8 +593,8 @@ export default function DeviceStatusPage() {
if (!device) return null;
// 优先使用持久化MQTT数据,其次使用uavState
const lng = currentDroneData?.longitude ?? uavState?.longitude ?? runningStatus.longitude ?? device.longitude;
const lat = currentDroneData?.latitude ?? uavState?.latitude ?? runningStatus.latitude ?? device.latitude;
const lng = currentDroneData?.longitude ?? uavState?.longitude ?? runningStatus?.longitude ?? device.longitude;
const lat = currentDroneData?.latitude ?? uavState?.latitude ?? runningStatus?.latitude ?? device.latitude;
return {
...device,
@@ -606,10 +606,10 @@ export default function DeviceStatusPage() {
// 让地图取最新经纬度
longitude: lng,
latitude: lat,
name: device.deviceAlias || device.callsign || device.deviceName || t('devices.device'),
name: device?.deviceAlias || device?.callsign || device?.deviceName || t('devices.device'),
type: isUAV
? 'drone'
: device.productName?.includes(t('constants.mower'))
: device?.productName?.includes(t('constants.mower'))
? 'mower'
: 'robot',
};
@@ -905,7 +905,7 @@ 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 type="secondary">{t('devices.markedPointsCount', { count: markedPoints?.length })}</Text>
</div>
<Space size="middle">
<Space>
@@ -934,7 +934,7 @@ export default function DeviceStatusPage() {
type="primary"
ghost
onClick={handleComplete}
disabled={markedPoints.length < 2}
disabled={markedPoints?.length < 2}
>
{t('devices.complete')}
</Button>*/}
@@ -968,12 +968,12 @@ export default function DeviceStatusPage() {
optionFilterProp="label"
placeholder={t('video.selectDevice')}
allowClear={false}
loading={devicesAll.length === 0}
loading={devicesAll?.length === 0}
options={[
{
label: t('devices.robot'),
title: 'robot',
options: devicesAll.filter(item => !item.gateway_sn && !item.drone_callsign && item.serialNumber).map(item => ({
options: devicesAll?.filter(item => !item.gateway_sn && !item.drone_callsign && item.serialNumber).map(item => ({
value: item.device_sn || item.serialNumber,
label: `${item.deviceAlias || item.deviceName || t('devices.unknownDevice')} `,
})),
@@ -981,12 +981,12 @@ export default function DeviceStatusPage() {
{
label: t('constants.uav'),
title: 'uav',
options: devicesAll.filter(item => item.gateway_sn || item.drone_callsign).map(item => ({
value: item.device_sn,
label: `${item.drone_callsign || item.callsign || t('devices.unknownDrone')}`,
options: devicesAll?.filter(item => item?.gateway_sn || item?.drone_callsign).map(item => ({
value: item?.device_sn,
label: `${item?.drone_callsign || item?.callsign || t('devices.unknownDrone')}`,
})),
},
].filter(group => group.options.length > 0)}
].filter(group => group?.options?.length > 0)}
/>
<Tag color={isUAV ? 'cyan' : 'blue'}>
@@ -1153,42 +1153,46 @@ 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 style={{ color: (runningStatus.battery || 0) < 20 ? '#ff4d4f' : '#52c41a' }}>
{runningStatus.battery !== undefined ? `${runningStatus.battery}%` : '-'}
<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>{runningStatus.voltage !== undefined ? `${Number(runningStatus.voltage).toFixed(2)}V` : '-'}</span>
<span>{t('devices.rtLeftMotor')}:</span>
<span>{runningStatus.leftCurrent !== undefined ? `${Number(runningStatus.leftCurrent).toFixed(2)}A` : '-'}</span>
<span>{t('devices.rtRightMotor')}:</span>
<span>{runningStatus.rightCurrent !== undefined ? `${Number(runningStatus.rightCurrent).toFixed(2)}A` : '-'}</span>
<span>{t('devices.rtLeftSpeed')}:</span>
<span>{runningStatus.leftMeasureSpeed !== undefined ? `${Number(runningStatus.leftMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
<span>{t('devices.rtRightSpeed')}:</span>
<span>{runningStatus.rightMeasureSpeed !== undefined ? `${Number(runningStatus.rightMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
<span>{t('devices.rtLeftTemp')}:</span>
<span>{runningStatus.leftMotorTemp !== undefined ? `${Number(runningStatus.leftMotorTemp).toFixed(1)}℃` : '-'}</span>
<span>{t('devices.rtRightTemp')}:</span>
<span>{runningStatus.rightMotorTemp !== undefined ? `${Number(runningStatus.rightMotorTemp).toFixed(1)}℃` : '-'}</span>
<span>{t('devices.rtMainTemp')}:</span>
<span>{runningStatus.chipTemp !== undefined ? `${Number(runningStatus.chipTemp).toFixed(1)}℃` : '-'}</span>
<span>{t('devices.rtHeadingAngle')}:</span>
<span>{runningStatus.yaw !== undefined ? `${Number(runningStatus.yaw).toFixed(1)}°` : '-'}</span>
<span>{t('devices.rtPitchAngle')}:</span>
<span>{runningStatus.pitch !== undefined ? `${Number(runningStatus.pitch).toFixed(1)}°` : '-'}</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.rtVoltage')}</span>
<span>{runningStatus?.voltage !== undefined ? `${Number(runningStatus?.voltage).toFixed(2)}V` : '-'}</span>
<span>{t('devices.rtLeftMotor')}</span>
<span>{runningStatus?.leftCurrent !== undefined ? `${Number(runningStatus?.leftCurrent).toFixed(2)}A` : '-'}</span>
<span>{t('devices.rtRightMotor')}</span>
<span>{runningStatus?.rightCurrent !== undefined ? `${Number(runningStatus?.rightCurrent).toFixed(2)}A` : '-'}</span>
<span>{t('devices.rtLeftSpeed')}</span>
<span>{runningStatus?.leftMeasureSpeed !== undefined ? `${Number(runningStatus?.leftMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
<span>{t('devices.rtRightSpeed')}</span>
<span>{runningStatus?.rightMeasureSpeed !== undefined ? `${Number(runningStatus?.rightMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
<span>{t('devices.rtLeftTemp')}</span>
<span>{runningStatus?.leftMotorTemp !== undefined ? `${Number(runningStatus?.leftMotorTemp).toFixed(1)}℃` : '-'}</span>
<span>{t('devices.rtRightTemp')}</span>
<span>{runningStatus?.rightMotorTemp !== undefined ? `${Number(runningStatus?.rightMotorTemp).toFixed(1)}℃` : '-'}</span>
<span>{t('devices.rtMainTemp')}</span>
<span>{runningStatus?.chipTemp !== undefined ? `${Number(runningStatus?.chipTemp).toFixed(1)}℃` : '-'}</span>
<span>{t('devices.rtHeadingAngle')}</span>
<span>{runningStatus?.yaw !== undefined ? `${Number(runningStatus?.yaw).toFixed(1)}°` : '-'}</span>
<span>{t('devices.rtPitchAngle')}</span>
<span>{runningStatus?.pitch !== undefined ? `${Number(runningStatus?.pitch).toFixed(1)}°` : '-'}</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>
{runningStatus.fix_status ? fixStatusMap[runningStatus.fix_status] : t('constants.locationUnknown')}
{runningStatus?.qual == 0 ? t('constants.locationInvalid') :
runningStatus?.qual == 1 ? t('devices.gpsSingle') :
runningStatus?.qual == 2 ? t('devices.dgpsDiff') :
runningStatus?.qual == 4 ? t('devices.rtkFixed2') :
runningStatus?.qual == 5 ? t('devices.rtkFloat') : t('constants.locationUnknown')}
</span>
<span>{t('devices.rtSatellites')}:</span>
<span>{t('devices.satelliteCount', { count: runningStatus.satelliteCnt || 0 })}</span>
<span>{t('devices.rtMode')}:</span>
<span>{t('devices.rtSatellites')}</span>
<span>{t('devices.satelliteCount', { count: runningStatus?.satelliteCnt || 0 })}</span>
<span>{t('devices.rtMode')}</span>
<span>
{runningStatus.controlMode == 1 ? t('devices.localMode') :
runningStatus.controlMode == 3 ? t('devices.remoteMode') : t('constants.locationUnknown')}
{runningStatus?.controlMode == 1 ? t('devices.localMode') :
runningStatus?.controlMode == 3 ? t('devices.remoteMode') : t('constants.locationUnknown')}
</span>
</div>
</div>
@@ -1263,42 +1267,42 @@ export default function DeviceStatusPage() {
<div style={{ marginBottom: 6, fontWeight: 600, color: '#1890ff' }}>{t('devices.robotStatus')}</div>
<div style={{ display: 'grid', gridTemplateColumns: 'auto auto', gap: '3px 10px' }}>
<span>{t('devices.rtBattery')}</span>
<span style={{ color: (runningStatus.battery || 0) < 20 ? '#ff4d4f' : '#52c41a' }}>
{runningStatus.battery !== undefined ? `${runningStatus.battery}%` : '-'}
<span style={{ color: (runningStatus?.battery || 0) < 20 ? '#ff4d4f' : '#52c41a' }}>
{runningStatus?.battery !== undefined ? `${runningStatus?.battery}%` : '-'}
</span>
<span>{t('devices.rtVoltage')}</span>
<span>{runningStatus.voltage !== undefined ? `${Number(runningStatus.voltage).toFixed(2)}V` : '-'}</span>
<span>{runningStatus?.voltage !== undefined ? `${Number(runningStatus?.voltage).toFixed(2)}V` : '-'}</span>
<span>{t('devices.rtLeftMotor')}</span>
<span>{runningStatus.leftCurrent !== undefined ? `${Number(runningStatus.leftCurrent).toFixed(2)}A` : '-'}</span>
<span>{runningStatus?.leftCurrent !== undefined ? `${Number(runningStatus?.leftCurrent).toFixed(2)}A` : '-'}</span>
<span>{t('devices.rtRightMotor')}</span>
<span>{runningStatus.rightCurrent !== undefined ? `${Number(runningStatus.rightCurrent).toFixed(2)}A` : '-'}</span>
<span>{runningStatus?.rightCurrent !== undefined ? `${Number(runningStatus?.rightCurrent).toFixed(2)}A` : '-'}</span>
<span>{t('devices.rtLeftSpeed')}</span>
<span>{runningStatus.leftMeasureSpeed !== undefined ? `${Number(runningStatus.leftMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
<span>{runningStatus?.leftMeasureSpeed !== undefined ? `${Number(runningStatus?.leftMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
<span>{t('devices.rtRightSpeed')}</span>
<span>{runningStatus.rightMeasureSpeed !== undefined ? `${Number(runningStatus.rightMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
<span>{runningStatus?.rightMeasureSpeed !== undefined ? `${Number(runningStatus?.rightMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
<span>{t('devices.rtLeftTemp')}</span>
<span>{runningStatus.leftMotorTemp !== undefined ? `${Number(runningStatus.leftMotorTemp).toFixed(1)}℃` : '-'}</span>
<span>{runningStatus?.leftMotorTemp !== undefined ? `${Number(runningStatus?.leftMotorTemp).toFixed(1)}℃` : '-'}</span>
<span>{t('devices.rtRightTemp')}</span>
<span>{runningStatus.rightMotorTemp !== undefined ? `${Number(runningStatus.rightMotorTemp).toFixed(1)}℃` : '-'}</span>
<span>{runningStatus?.rightMotorTemp !== undefined ? `${Number(runningStatus?.rightMotorTemp).toFixed(1)}℃` : '-'}</span>
<span>{t('devices.rtMainTemp')}</span>
<span>{runningStatus.chipTemp !== undefined ? `${Number(runningStatus.chipTemp).toFixed(1)}℃` : '-'}</span>
<span>{runningStatus?.chipTemp !== undefined ? `${Number(runningStatus?.chipTemp).toFixed(1)}℃` : '-'}</span>
<span>{t('devices.rtHeadingAngle')}</span>
<span>{runningStatus.yaw !== undefined ? `${Number(runningStatus.yaw).toFixed(1)}°` : '-'}</span>
<span>{runningStatus?.yaw !== undefined ? `${Number(runningStatus?.yaw).toFixed(1)}°` : '-'}</span>
<span>{t('devices.rtPitchAngle')}</span>
<span>{runningStatus.pitch !== undefined ? `${Number(runningStatus.pitch).toFixed(1)}°` : '-'}</span>
<span>{runningStatus?.pitch !== undefined ? `${Number(runningStatus?.pitch).toFixed(1)}°` : '-'}</span>
<span>{t('devices.rtHeadingStatus')}</span>
<span>{runningStatus.headingStatus !== undefined ? `${runningStatus.headingStatus == 1 ? t('devices.rtInitialized') : t('devices.uninitialized')}` : '-'}</span>
<span>{runningStatus?.headingStatus !== undefined ? `${runningStatus?.headingStatus == 1 ? t('devices.rtInitialized') : t('devices.uninitialized')}` : '-'}</span>
<span>{t('devices.rtPositioning')}</span>
<span>
{runningStatus.fix_status ? fixStatusMap[runningStatus.fix_status] : t('constants.locationUnknown')}
{runningStatus?.fix_status ? fixStatusMap[runningStatus?.fix_status] : t('constants.locationUnknown')}
</span>
<span>{t('devices.rtSatellites')}</span>
<span>{t('devices.satelliteCount', { count: runningStatus.satelliteCnt || 0 })}</span>
<span>{t('devices.satelliteCount', { count: runningStatus?.satelliteCnt || 0 })}</span>
<span>{t('devices.rtMode')}</span>
<span>
{runningStatus.controlMode == 1 ? t('devices.localMode') :
runningStatus.controlMode == 3 ? t('devices.remoteMode') : t('constants.locationUnknown')}
{runningStatus?.controlMode == 1 ? t('devices.localMode') :
runningStatus?.controlMode == 3 ? t('devices.remoteMode') : t('constants.locationUnknown')}
</span>
</div>
</div>
@@ -1391,11 +1395,11 @@ export default function DeviceStatusPage() {
open={isModalOpen}
onOk={handleOk}
onCancel={handleCancel}
title={modalContent.title}
title={modalContent?.title}
okText={t('common.ok')}
cancelText={t('common.cancel')}
>
<p>{modalContent.content}</p>
<p>{modalContent?.content}</p>
</Modal>
{/* 保存路径模态框 */}