寻车功能 和返航按键 还有 任务excuting 推送 刷新功能 但是 没用,另一个电脑还没有 连接ws呢 难搞 加 另一个车道辅助线 组件实现
This commit is contained in:
@@ -160,6 +160,7 @@ const RealTimeMonitorPage = () => {
|
||||
// 连接逻辑统一封装在 DeviceController 中
|
||||
// ============================================================
|
||||
const controllerRef = useRef<any>(null);
|
||||
const mapRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!userInfo || !stationId) return;
|
||||
@@ -430,6 +431,43 @@ const RealTimeMonitorPage = () => {
|
||||
// ============================================================
|
||||
// 点击设备:仅打开侧边栏 + 地图定位(不再连接单台设备 WebSocket)
|
||||
// ============================================================
|
||||
// 仅定位设备(不打开抽屉):用于点击表格行
|
||||
const handleLocateDevice = (robot) => {
|
||||
const dev = robot;
|
||||
const isDroneDevice = dev?.type === 'plane' || !!dev?.gateway_sn;
|
||||
|
||||
// 1. 优先使用实时经纬度(realtimeMap)
|
||||
const rt = pickRealtimeRecord(realtimeMap, dev);
|
||||
let lon = rt?.lng;
|
||||
let lat = rt?.lat;
|
||||
|
||||
// 2. 没有实时经纬度时,使用 lastRunningStatus 中的经纬度
|
||||
if ((!lon || !lat) && dev?.lastRunningStatus?.longitude && dev?.lastRunningStatus?.latitude) {
|
||||
lon = dev.lastRunningStatus.longitude;
|
||||
lat = dev.lastRunningStatus.latitude;
|
||||
}
|
||||
|
||||
// 3. 兜底:locationMessage / 静态经纬度
|
||||
if ((!lon || !lat) && dev?.locationMessage?.longitude && dev?.locationMessage?.latitude) {
|
||||
lon = dev.locationMessage.longitude;
|
||||
lat = dev.locationMessage.latitude;
|
||||
}
|
||||
if ((!lon || !lat) && dev?.longitude && dev?.latitude) {
|
||||
lon = dev.longitude;
|
||||
lat = dev.latitude;
|
||||
}
|
||||
|
||||
if (lon && lat && !isNaN(Number(lon)) && !isNaN(Number(lat))) {
|
||||
setFocusLocation({
|
||||
lon: Number(lon),
|
||||
lat: Number(lat),
|
||||
type: isDroneDevice ? 'plane' : 'robot',
|
||||
name: dev.deviceAlias || dev.deviceName || dev.drone_callsign || dev.serialNumber || dev.device_sn,
|
||||
sn: dev.serialNumber || dev.device_sn || dev.id,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeviceClick = (robot) => {
|
||||
console.log('[RTMonitor] 点击设备:', robot);
|
||||
const dev = robot;
|
||||
@@ -440,15 +478,7 @@ const RealTimeMonitorPage = () => {
|
||||
const isDroneDevice = dev?.type === 'plane' || !!dev?.gateway_sn;
|
||||
|
||||
// ---- 地图定位 ----
|
||||
if ((dev?.lastRunningStatus?.longitude && dev?.lastRunningStatus?.latitude) || (dev?.locationMessage?.longitude && dev?.locationMessage?.latitude) || (dev?.longitude && dev?.latitude)) {
|
||||
setFocusLocation({
|
||||
lon: Number(dev.lastRunningStatus?.longitude || dev.locationMessage?.longitude || dev.longitude),
|
||||
lat: Number(dev.lastRunningStatus?.latitude || dev.locationMessage?.latitude || dev.latitude),
|
||||
type: isDroneDevice ? 'plane' : 'robot',
|
||||
name: dev.deviceAlias || dev.deviceName || dev.drone_callsign || dev.serialNumber || dev.device_sn,
|
||||
sn: dev.serialNumber || dev.device_sn || dev.id,
|
||||
});
|
||||
}
|
||||
handleLocateDevice(dev);
|
||||
|
||||
// ---- 逆变器/模拟设备:仅地图定位,不打开抽屉 ----
|
||||
if (isMockDevice) {
|
||||
@@ -547,36 +577,37 @@ const RealTimeMonitorPage = () => {
|
||||
{
|
||||
title: t('devices.deviceName'), dataIndex: 'name', key: 'name',
|
||||
render: (text, record) => (
|
||||
<a onClick={() => handleDeviceClick(record.raw || record)} style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<div style={{ width: 24, height: 24, background: '#f5f5f5', borderRadius: 4, display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
|
||||
{record.type?.includes?.('INV') ? <ThunderboltOutlined style={{ fontSize: 14 }} /> : getDeviceTypeIcon(record.type)}
|
||||
</div>
|
||||
<span style={{ fontSize: 13 }}>{text}</span>
|
||||
</a>
|
||||
</span>
|
||||
)
|
||||
},
|
||||
{ title: t('common.type'), dataIndex: 'typeText', render: (t) => <span style={{ fontSize: 13, color: '#666' }}>{t}</span> },
|
||||
{ title: t('workOrder.currentStatus'), dataIndex: 'feStatus', render: getStatusTag },
|
||||
//{ title: t('page.fixed2RealtimePower'), dataIndex: 'data', render: (d) => <span style={{ fontSize: 13, fontWeight: 500 }}>{d}</span> },
|
||||
//{
|
||||
// title: t('page.statusFixed2'), dataIndex: 'communication',
|
||||
// render: (c) => (
|
||||
// <Space size={4}>
|
||||
// <span style={{ fontSize: 13 }}>{c}</span>
|
||||
// <RiseOutlined style={{ color: '#52c41a' }} />
|
||||
// </Space>
|
||||
// )
|
||||
//},
|
||||
//{
|
||||
// title: t('common.action'), key: 'action', width: 80,
|
||||
// render: (_, record) => (
|
||||
// <Tooltip title={t('page.viewDeviceDetailAndTask')}>
|
||||
// <Button type="link" size="small" onClick={() => handleDeviceClick(record.raw || record)} icon={<LockOutlined />}>
|
||||
// {t('common.locate')}
|
||||
// </Button>
|
||||
// </Tooltip>
|
||||
// )
|
||||
//}
|
||||
{
|
||||
title: t('common.detail'),
|
||||
key: 'action',
|
||||
width: 80,
|
||||
render: (_, record) => {
|
||||
const isMockDevice = record?.isMock || ['INVERTER', 'COMBINER_BOX', 'WEATHER_STATION', 'METER'].includes(record?.type);
|
||||
return (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleDeviceClick(record.raw || record);
|
||||
}}
|
||||
disabled={isMockDevice}
|
||||
>
|
||||
{t('common.detail')}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
// 任务池(当前选中设备)
|
||||
@@ -785,6 +816,55 @@ const RealTimeMonitorPage = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 寻车:定位到当前选中的设备
|
||||
const handleFindCar = useCallback(async () => {
|
||||
if (!selectedDevice) {
|
||||
messageApi.warning(t('devices.selectExecuteDevice'));
|
||||
return;
|
||||
}
|
||||
const isDroneDevice = selectedDevice?.type === 'plane' || !!selectedDevice?.gateway_sn;
|
||||
|
||||
// 无人机:调用接口获取实时位置
|
||||
if (isDroneDevice) {
|
||||
if (selectedDevice?.gateway_sn && selectedDevice?.device_sn) {
|
||||
try {
|
||||
const res = await getUAVState({ sn: selectedDevice.gateway_sn, droneSn: selectedDevice.device_sn });
|
||||
const pos = res?.data;
|
||||
if (pos && pos.longitude && pos.latitude) {
|
||||
mapRef.current?.flyToPosition?.({ lon: Number(pos.longitude), lat: Number(pos.latitude) }, { height: 300 });
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[RTMonitor] 寻车获取无人机位置失败', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 机器人/其他设备:优先实时经纬度 -> lastRunningStatus -> locationMessage -> 静态经纬度
|
||||
const rt = pickRealtimeRecord(realtimeMap, selectedDevice);
|
||||
let lon = rt?.lng;
|
||||
let lat = rt?.lat;
|
||||
|
||||
if ((!lon || !lat) && selectedDevice.lastRunningStatus?.longitude && selectedDevice.lastRunningStatus?.latitude) {
|
||||
lon = selectedDevice.lastRunningStatus.longitude;
|
||||
lat = selectedDevice.lastRunningStatus.latitude;
|
||||
}
|
||||
if ((!lon || !lat) && selectedDevice.locationMessage?.longitude && selectedDevice.locationMessage?.latitude) {
|
||||
lon = selectedDevice.locationMessage.longitude;
|
||||
lat = selectedDevice.locationMessage.latitude;
|
||||
}
|
||||
if ((!lon || !lat) && selectedDevice.longitude && selectedDevice.latitude) {
|
||||
lon = selectedDevice.longitude;
|
||||
lat = selectedDevice.latitude;
|
||||
}
|
||||
|
||||
if (lon && lat && !isNaN(Number(lon)) && !isNaN(Number(lat))) {
|
||||
mapRef.current?.flyToPosition?.({ lon: Number(lon), lat: Number(lat) }, { height: 300 });
|
||||
} else {
|
||||
messageApi.warning(t('devices.locationUnknown'));
|
||||
}
|
||||
}, [selectedDevice, t, realtimeMap]);
|
||||
|
||||
// ============================================================
|
||||
// 路径操作:执行/暂停/恢复/取消
|
||||
// ============================================================
|
||||
@@ -949,6 +1029,9 @@ const RealTimeMonitorPage = () => {
|
||||
<span style={{ width: 6, height: 6, borderRadius: '50%', background: '#888' }}></span>{t('devices.offline')}
|
||||
</span>
|
||||
<Divider type="vertical" />
|
||||
<Button size="small" type="primary" icon={<EnvironmentOutlined />} onClick={handleFindCar}>
|
||||
{t('devices.features.findCar')}
|
||||
</Button>
|
||||
<Button size="small" icon={<DeleteOutlined />} onClick={() => setClearNavLine(c => c + 1)}>
|
||||
{t('devices.clearRealtimeTrack')}
|
||||
</Button>
|
||||
@@ -963,6 +1046,7 @@ const RealTimeMonitorPage = () => {
|
||||
>
|
||||
<div style={{ height: '100%', background: '#111827', borderRadius: 8, width: '100%', overflow: 'hidden', position: 'relative' }}>
|
||||
<CesiumMap
|
||||
ref={mapRef}
|
||||
from="devicesTask"
|
||||
mapLayer={currentStation?.siteMapName}
|
||||
devices={mapDevices}
|
||||
@@ -1044,6 +1128,10 @@ const RealTimeMonitorPage = () => {
|
||||
loading={loading}
|
||||
pagination={false}
|
||||
size="small"
|
||||
onRow={(record) => ({
|
||||
onClick: () => handleLocateDevice(record.raw || record),
|
||||
style: { cursor: 'pointer' },
|
||||
})}
|
||||
/>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 12, alignItems: 'center' }}>
|
||||
<span style={{ color: '#999', fontSize: 11 }}>{t('common.totalCount', { count: filteredDeviceList.length })}</span>
|
||||
@@ -1176,7 +1264,7 @@ const RealTimeMonitorPage = () => {
|
||||
width={560}
|
||||
open={deviceDrawerOpen}
|
||||
onClose={() => {
|
||||
; setDeviceDrawerOpen(false); setMqttDrone(null);
|
||||
setDeviceDrawerOpen(false); setMqttDrone(null);
|
||||
}}
|
||||
destroyOnClose
|
||||
extra={(selectedDevice?.gateway_sn || selectedDevice?.type === 'plane') ? null : <Button size="small" icon={<SyncOutlined />} onClick={() => { fetchTaskPoolList(selectedDeviceSn); }}></Button>}
|
||||
|
||||
Reference in New Issue
Block a user