feat:设备运维ops管理模块功能设备监控功能完善
This commit is contained in:
@@ -50,4 +50,11 @@ export default {
|
|||||||
'menu.editor.mind': '脑图编辑器',
|
'menu.editor.mind': '脑图编辑器',
|
||||||
'menu.editor.koni': '拓扑编辑器',
|
'menu.editor.koni': '拓扑编辑器',
|
||||||
'menu.首页': '首页',
|
'menu.首页': '首页',
|
||||||
|
'menu.设备运维': '设备运维',
|
||||||
|
'menu.设备运维.设备管理': '设备管理',
|
||||||
|
'menu.设备运维.分组管理': '分组管理',
|
||||||
|
'menu.设备运维.运维管理': '运维管理',
|
||||||
|
'menu.设备运维.设备监控': '设备监控',
|
||||||
|
'menu.设备运维.统计分析': '统计分析',
|
||||||
|
'menu.设备运维.设备详情': '设备详情',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,24 +29,24 @@ interface Statistics {
|
|||||||
totalDevices: number;
|
totalDevices: number;
|
||||||
onlineDevices: number;
|
onlineDevices: number;
|
||||||
deviceOnlineRate: number;
|
deviceOnlineRate: number;
|
||||||
orderTrend: Array<{
|
orderTrend: {
|
||||||
date: string;
|
date: string;
|
||||||
type: string;
|
type: string;
|
||||||
value: number;
|
value: number;
|
||||||
}>;
|
}[];
|
||||||
deviceDistribution: Array<{
|
deviceDistribution: {
|
||||||
type: string;
|
type: string;
|
||||||
value: number;
|
value: number;
|
||||||
}>;
|
}[];
|
||||||
incomeData: Array<{
|
incomeData: {
|
||||||
type: string;
|
type: string;
|
||||||
value: number;
|
value: number;
|
||||||
}>;
|
}[];
|
||||||
tourismRanking: Array<{
|
tourismRanking: {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
value: number;
|
value: number;
|
||||||
}>;
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const Welcome: React.FC = () => {
|
const Welcome: React.FC = () => {
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ const DeviceDetailPage: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getAlertLevelColor = (level: string) => {
|
const getAlertLevelColor = (level: string) => {
|
||||||
const colorMap: { [key: string]: string } = {
|
const colorMap: Record<string, string> = {
|
||||||
'高': 'red',
|
'高': 'red',
|
||||||
'中': 'orange',
|
'中': 'orange',
|
||||||
'低': 'blue',
|
'低': 'blue',
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { useRef, useState, useEffect } from 'react';
|
import React, { useRef, useState, useEffect } from 'react';
|
||||||
import { PageContainer } from '@ant-design/pro-layout';
|
import { PageContainer } from '@ant-design/pro-layout';
|
||||||
import { ProTable, ProColumns, ModalForm, ProFormText, ProFormSelect, ProFormUploadButton } from '@ant-design/pro-components';
|
import type { ProColumns} from '@ant-design/pro-components';
|
||||||
|
import { ProTable, ModalForm, ProFormText, ProFormSelect, ProFormUploadButton } from '@ant-design/pro-components';
|
||||||
import { Button, Space, message, Popconfirm, Tag, Select, Modal, Dropdown, Menu, Upload, Card, Row, Col, Statistic } from 'antd';
|
import { Button, Space, message, Popconfirm, Tag, Select, Modal, Dropdown, Menu, Upload, Card, Row, Col, Statistic } from 'antd';
|
||||||
import { history } from 'umi';
|
import { history } from 'umi';
|
||||||
import { DownOutlined, UploadOutlined, DownloadOutlined, FileExcelOutlined, CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons';
|
import { DownOutlined, UploadOutlined, DownloadOutlined, FileExcelOutlined, CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons';
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { useRef, useState } from 'react';
|
import React, { useRef, useState } from 'react';
|
||||||
import { PageContainer } from '@ant-design/pro-layout';
|
import { PageContainer } from '@ant-design/pro-layout';
|
||||||
import { ProTable, ProColumns, ModalForm, ProFormText, ProFormSelect } from '@ant-design/pro-components';
|
import type { ProColumns} from '@ant-design/pro-components';
|
||||||
|
import { ProTable, ModalForm, ProFormText, ProFormSelect } from '@ant-design/pro-components';
|
||||||
import { Button, Space, message, Popconfirm, Tag, Card, Row, Col, Statistic } from 'antd';
|
import { Button, Space, message, Popconfirm, Tag, Card, Row, Col, Statistic } from 'antd';
|
||||||
import { Pie } from '@ant-design/plots';
|
import { Pie } from '@ant-design/plots';
|
||||||
import { device } from '@/services/device/api';
|
import { device } from '@/services/device/api';
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { useRef, useState } from 'react';
|
import React, { useRef, useState } from 'react';
|
||||||
import { PageContainer } from '@ant-design/pro-layout';
|
import { PageContainer } from '@ant-design/pro-layout';
|
||||||
import { ProTable, ProColumns, ModalForm, ProFormText, ProFormSelect, ProFormDatePicker } from '@ant-design/pro-components';
|
import type { ProColumns} from '@ant-design/pro-components';
|
||||||
|
import { ProTable, ModalForm, ProFormText, ProFormSelect, ProFormDatePicker } from '@ant-design/pro-components';
|
||||||
import { Button, Space, message, Popconfirm, Tag } from 'antd';
|
import { Button, Space, message, Popconfirm, Tag } from 'antd';
|
||||||
|
|
||||||
interface MaintenanceTask {
|
interface MaintenanceTask {
|
||||||
@@ -83,7 +84,7 @@ const MaintenanceList: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getStatusColor = (status: string) => {
|
const getStatusColor = (status: string) => {
|
||||||
const colorMap: { [key: string]: string } = {
|
const colorMap: Record<string, string> = {
|
||||||
'待处理': 'orange',
|
'待处理': 'orange',
|
||||||
'进行中': 'blue',
|
'进行中': 'blue',
|
||||||
'已完成': 'green',
|
'已完成': 'green',
|
||||||
@@ -93,7 +94,7 @@ const MaintenanceList: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getPriorityColor = (priority: string) => {
|
const getPriorityColor = (priority: string) => {
|
||||||
const colorMap: { [key: string]: string } = {
|
const colorMap: Record<string, string> = {
|
||||||
'高': 'red',
|
'高': 'red',
|
||||||
'中': 'orange',
|
'中': 'orange',
|
||||||
'低': 'green',
|
'低': 'green',
|
||||||
|
|||||||
@@ -180,17 +180,6 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
timer: null as NodeJS.Timeout | null,
|
timer: null as NodeJS.Timeout | null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const refreshTokenAndReconnect = async () => {
|
|
||||||
// 强制获取新token
|
|
||||||
tokenCache.value = '';
|
|
||||||
await getToken();
|
|
||||||
// 关闭旧ws并重建
|
|
||||||
if (wsRef.current) {
|
|
||||||
wsRef.current.close();
|
|
||||||
}
|
|
||||||
await initWebSocket();
|
|
||||||
};
|
|
||||||
|
|
||||||
const getToken = async (expires: number = DEFAULT_EXPIRES) => {
|
const getToken = async (expires: number = DEFAULT_EXPIRES) => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (tokenCache.value && tokenCache.expire > now) {
|
if (tokenCache.value && tokenCache.expire > now) {
|
||||||
@@ -218,18 +207,29 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
return token;
|
return token;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const refreshTokenAndReconnect = async () => {
|
||||||
|
// 强制获取新token
|
||||||
|
tokenCache.value = '';
|
||||||
|
await getToken();
|
||||||
|
// 关闭旧ws并重建
|
||||||
|
if (wsRef.current) {
|
||||||
|
wsRef.current.close();
|
||||||
|
}
|
||||||
|
await initWebSocket();
|
||||||
|
};
|
||||||
|
|
||||||
// 获取设备列表
|
// 获取设备列表
|
||||||
const fetchDeviceList = async () => {
|
const fetchDeviceList = async () => {
|
||||||
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
|
||||||
const response = await device({
|
const response = await device({
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: 1000,
|
limit: 1000,
|
||||||
});
|
});
|
||||||
if (response.resp_code === 0) {
|
console.log('设备列表API响应:', response);
|
||||||
const devices = response.data || [];
|
|
||||||
// 初始化设备数据
|
if (response.resp_code === 0 && response.data) {
|
||||||
const initializedDevices = devices.map((item: Device) => ({
|
const devices = response.data.map((item: any) => ({
|
||||||
...item,
|
...item,
|
||||||
metrics: {
|
metrics: {
|
||||||
temperature: 0,
|
temperature: 0,
|
||||||
@@ -256,8 +256,11 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
'4gLinkQuality': 0,
|
'4gLinkQuality': 0,
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
setDeviceList(initializedDevices);
|
setDeviceList(devices);
|
||||||
console.log('设备列表已更新:', initializedDevices);
|
console.log('设备列表已更新:', devices);
|
||||||
|
} else {
|
||||||
|
console.error('获取设备列表失败:', response.resp_msg);
|
||||||
|
message.error(response.resp_msg || '获取设备列表失败');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取设备列表失败:', error);
|
console.error('获取设备列表失败:', error);
|
||||||
@@ -267,105 +270,6 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 修改 WebSocket 连接初始化
|
|
||||||
const initWebSocket = async () => {
|
|
||||||
try {
|
|
||||||
console.log('开始初始化WebSocket连接...');
|
|
||||||
const token = await getToken();
|
|
||||||
console.log('获取到WebSocket token:', token);
|
|
||||||
|
|
||||||
// 如果已经存在连接,且未关闭,不重复建立
|
|
||||||
if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) {
|
|
||||||
console.log('WebSocket已连接,无需重复建立');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (wsRef.current) {
|
|
||||||
console.log('关闭已存在的WebSocket连接');
|
|
||||||
wsRef.current.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 建立WebSocket连接
|
|
||||||
const wsUrl = `ws://119.45.169.13:8848/messaging/${token}`;
|
|
||||||
console.log('正在连接WebSocket:', wsUrl);
|
|
||||||
const ws = new WebSocket(wsUrl);
|
|
||||||
wsRef.current = ws;
|
|
||||||
|
|
||||||
ws.onopen = () => {
|
|
||||||
console.log('WebSocket连接已建立');
|
|
||||||
setWsConnected(true);
|
|
||||||
// 启动心跳检测
|
|
||||||
startHeartbeat();
|
|
||||||
// 根据当前选中的设备订阅消息
|
|
||||||
if (selectedDevice !== 'all') {
|
|
||||||
console.log('当前选中的设备:', selectedDevice);
|
|
||||||
subscribeDeviceMessages(selectedDevice);
|
|
||||||
} else {
|
|
||||||
console.log('未选择具体设备,订阅所有设备在线状态');
|
|
||||||
subscribeDeviceMessages();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onmessage = (event) => {
|
|
||||||
console.log('收到WebSocket原始消息:', event.data);
|
|
||||||
try {
|
|
||||||
const data = JSON.parse(event.data);
|
|
||||||
console.log('解析后的WebSocket消息:', JSON.stringify(data, null, 2));
|
|
||||||
// 处理心跳响应
|
|
||||||
if (data.type === 'pong') {
|
|
||||||
console.log('收到心跳响应');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 添加调试信息
|
|
||||||
console.log('准备处理WebSocket消息...');
|
|
||||||
console.log('消息类型:', data.type);
|
|
||||||
console.log('消息主题:', data.topic);
|
|
||||||
console.log('消息负载:', JSON.stringify(data.payload, null, 2));
|
|
||||||
handleWebSocketMessage(data);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('解析WebSocket消息失败:', error);
|
|
||||||
console.error('原始消息内容:', event.data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onerror = (error) => {
|
|
||||||
console.error('WebSocket错误:', error);
|
|
||||||
message.error('WebSocket连接错误');
|
|
||||||
setWsConnected(false);
|
|
||||||
// 尝试重连
|
|
||||||
scheduleReconnect();
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onclose = (event) => {
|
|
||||||
console.log('WebSocket连接已关闭,代码:', event.code, '原因:', event.reason);
|
|
||||||
setWsConnected(false);
|
|
||||||
// 尝试重连
|
|
||||||
scheduleReconnect();
|
|
||||||
};
|
|
||||||
} catch (error) {
|
|
||||||
console.error('初始化WebSocket失败:', error);
|
|
||||||
message.error('初始化WebSocket失败');
|
|
||||||
// 尝试重连
|
|
||||||
scheduleReconnect();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 切换设备时只发订阅,不重建ws
|
|
||||||
useEffect(() => {
|
|
||||||
console.log('选中的设备已更改:', selectedDevice);
|
|
||||||
if (wsRef.current?.readyState === WebSocket.OPEN) {
|
|
||||||
if (selectedDevice !== 'all') {
|
|
||||||
console.log('WebSocket已连接,开始订阅设备消息:', selectedDevice);
|
|
||||||
subscribeDeviceMessages(selectedDevice);
|
|
||||||
} else {
|
|
||||||
console.log('WebSocket已连接,订阅所有设备在线状态');
|
|
||||||
subscribeDeviceMessages();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log('WebSocket未连接,尝试重新连接...');
|
|
||||||
initWebSocket();
|
|
||||||
}
|
|
||||||
}, [selectedDevice]);
|
|
||||||
|
|
||||||
// 重连机制
|
// 重连机制
|
||||||
const scheduleReconnect = () => {
|
const scheduleReconnect = () => {
|
||||||
if (reconnectTimerRef.current) {
|
if (reconnectTimerRef.current) {
|
||||||
@@ -402,67 +306,60 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 添加调试函数
|
|
||||||
const debugWebSocketMessage = (data: any) => {
|
|
||||||
console.log('WebSocket消息调试信息:');
|
|
||||||
console.log('消息类型:', data.type);
|
|
||||||
console.log('消息主题:', data.topic);
|
|
||||||
console.log('消息负载:', JSON.stringify(data.payload, null, 2));
|
|
||||||
console.log('消息ID:', data.id);
|
|
||||||
};
|
|
||||||
|
|
||||||
// 修改WebSocket消息处理
|
|
||||||
const handleWebSocketMessage = (data: any) => {
|
|
||||||
console.log('开始处理WebSocket消息:', JSON.stringify(data, null, 2));
|
|
||||||
debugWebSocketMessage(data);
|
|
||||||
|
|
||||||
if (data.type === 'result') {
|
|
||||||
const { topic, payload } = data;
|
|
||||||
|
|
||||||
// 正确提取 deviceSn
|
|
||||||
const topicParts = topic.split('/');
|
|
||||||
// topic: /device/{productId}/{deviceSn}/message/event/fire_alarm
|
|
||||||
const deviceSn = topicParts[3];
|
|
||||||
console.log('从主题中提取的设备编号:', deviceSn);
|
|
||||||
|
|
||||||
// 处理设备在线状态
|
|
||||||
if (topic.endsWith('/online')) {
|
|
||||||
console.log('处理设备在线状态:', deviceSn);
|
|
||||||
updateDeviceStatus(deviceSn, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理设备离线状态
|
|
||||||
if (topic.endsWith('/offline')) {
|
|
||||||
console.log('处理设备离线状态:', deviceSn);
|
|
||||||
updateDeviceStatus(deviceSn, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理设备属性上报
|
|
||||||
if (topic.includes('/message/property/report')) {
|
|
||||||
console.log('处理设备属性上报:', deviceSn, JSON.stringify(payload, null, 2));
|
|
||||||
handlePropertyReport(deviceSn, payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理设备火警事件
|
|
||||||
if (topic.includes('/message/event/fire_alarm')) {
|
|
||||||
console.log('处理设备火警事件:', deviceSn, JSON.stringify(payload, null, 2));
|
|
||||||
handleDeviceEvent(deviceSn, payload);
|
|
||||||
}
|
|
||||||
} else if (data.type === 'error') {
|
|
||||||
console.error('WebSocket消息错误:', data);
|
|
||||||
message.error(data.message || '消息处理错误');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 更新设备状态
|
// 更新设备状态
|
||||||
const updateDeviceStatus = (deviceSn: string, status: number) => {
|
const updateDeviceStatus = (deviceSn: string, status: number) => {
|
||||||
console.log('更新设备状态:', deviceSn, status);
|
console.log('更新设备状态:', deviceSn, status);
|
||||||
setDeviceList(prev => {
|
setDeviceList(prev => {
|
||||||
|
// 检查设备是否已存在
|
||||||
|
const existingDevice = prev.find(d => d.deviceSn === deviceSn);
|
||||||
|
|
||||||
|
if (!existingDevice) {
|
||||||
|
console.log('设备不存在,创建新设备记录:', deviceSn);
|
||||||
|
// 如果设备不存在,创建一个新的设备记录
|
||||||
|
const newDevice: Device = {
|
||||||
|
deviceSn: deviceSn,
|
||||||
|
deviceName: deviceSn, // 使用设备编号作为名称
|
||||||
|
deviceType: 1, // 默认类型
|
||||||
|
boundStatus: (status as 0 | 1),
|
||||||
|
createTime: moment().format('YYYY-MM-DD HH:mm:ss'),
|
||||||
|
loginTime: status === 1 ? moment().format('YYYY-MM-DD HH:mm:ss') : '',
|
||||||
|
metrics: {
|
||||||
|
temperature: 0,
|
||||||
|
humidity: 0,
|
||||||
|
windSpeed: 0,
|
||||||
|
rainfall: 0,
|
||||||
|
environmentTemperature: 0,
|
||||||
|
positionQuality: 0,
|
||||||
|
networkQuality: 0,
|
||||||
|
droneInDock: 0,
|
||||||
|
batteryCapacity: 0,
|
||||||
|
batteryState: 0,
|
||||||
|
workingVoltage: 0,
|
||||||
|
workingCurrent: 0,
|
||||||
|
acdcPowerInput: 0,
|
||||||
|
backupBatteryVoltage: 0,
|
||||||
|
flightTaskStep: 0,
|
||||||
|
tiltAngle: 0,
|
||||||
|
sdrUpQuality: 0,
|
||||||
|
sdrDownQuality: 0,
|
||||||
|
wirelessLinkState: 0,
|
||||||
|
wirelessLinkQuality: 0,
|
||||||
|
'4gLinkState': 0,
|
||||||
|
'4gLinkQuality': 0,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log('创建的新设备:', JSON.stringify(newDevice, null, 2));
|
||||||
|
const newList = [...prev, newDevice];
|
||||||
|
console.log('设备状态更新后:', newList);
|
||||||
|
return newList;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果设备存在,更新现有设备
|
||||||
const newList = prev.map(device =>
|
const newList = prev.map(device =>
|
||||||
device.deviceSn === deviceSn
|
device.deviceSn === deviceSn
|
||||||
? {
|
? {
|
||||||
...device,
|
...device,
|
||||||
boundStatus: status,
|
boundStatus: (status as 0 | 1),
|
||||||
loginTime: status === 1 ? moment().format('YYYY-MM-DD HH:mm:ss') : device.loginTime
|
loginTime: status === 1 ? moment().format('YYYY-MM-DD HH:mm:ss') : device.loginTime
|
||||||
}
|
}
|
||||||
: device
|
: device
|
||||||
@@ -505,28 +402,74 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 新增:同步更新 deviceList 里对应设备的 metrics 字段
|
// 新增:同步更新 deviceList 里对应设备的 metrics 字段
|
||||||
setDeviceList(prev => prev.map(d =>
|
setDeviceList(prev => {
|
||||||
d.deviceSn === deviceSn
|
// 检查设备是否已存在
|
||||||
? {
|
const existingDevice = prev.find(d => d.deviceSn === deviceSn);
|
||||||
...d,
|
|
||||||
metrics: {
|
if (!existingDevice) {
|
||||||
...d.metrics,
|
console.log('设备不存在,创建新设备记录:', deviceSn);
|
||||||
temperature: payload.properties.temperature ?? d.metrics.temperature,
|
// 如果设备不存在,创建一个新的设备记录
|
||||||
humidity: payload.properties.humidity ?? d.metrics.humidity,
|
const newDevice: Device = {
|
||||||
windSpeed: payload.properties.wind_speed ?? d.metrics.windSpeed,
|
deviceSn: deviceSn,
|
||||||
rainfall: payload.properties.rainfall ?? d.metrics.rainfall,
|
deviceName: deviceSn, // 使用设备编号作为名称
|
||||||
environmentTemperature: payload.properties.environment_temperature ?? d.metrics.environmentTemperature,
|
deviceType: 1, // 默认类型
|
||||||
positionQuality: payload.properties.position_state?.quality ?? d.metrics.positionQuality,
|
boundStatus: 1,
|
||||||
networkQuality: payload.properties.network_state?.quality ?? d.metrics.networkQuality,
|
createTime: moment().format('YYYY-MM-DD HH:mm:ss'),
|
||||||
droneInDock: payload.properties.drone_in_dock ?? d.metrics.droneInDock,
|
loginTime: moment().format('YYYY-MM-DD HH:mm:ss'),
|
||||||
batteryCapacity: payload.properties.drone_charge_state?.capacity_percent ?? d.metrics.batteryCapacity,
|
metrics: {
|
||||||
batteryState: payload.properties.drone_charge_state?.state ?? d.metrics.batteryState,
|
temperature: payload.properties.temperature ?? 0,
|
||||||
}
|
humidity: payload.properties.humidity ?? 0,
|
||||||
|
windSpeed: payload.properties.wind_speed ?? 0,
|
||||||
|
rainfall: payload.properties.rainfall ?? 0,
|
||||||
|
environmentTemperature: payload.properties.environment_temperature ?? 0,
|
||||||
|
positionQuality: payload.properties.position_state?.quality ?? 0,
|
||||||
|
networkQuality: payload.properties.network_state?.quality ?? 0,
|
||||||
|
droneInDock: payload.properties.drone_in_dock ?? 0,
|
||||||
|
batteryCapacity: payload.properties.drone_charge_state?.capacity_percent ?? 0,
|
||||||
|
batteryState: payload.properties.drone_charge_state?.state ?? 0,
|
||||||
|
workingVoltage: 0,
|
||||||
|
workingCurrent: 0,
|
||||||
|
acdcPowerInput: 0,
|
||||||
|
backupBatteryVoltage: 0,
|
||||||
|
flightTaskStep: 0,
|
||||||
|
tiltAngle: 0,
|
||||||
|
sdrUpQuality: 0,
|
||||||
|
sdrDownQuality: 0,
|
||||||
|
wirelessLinkState: 0,
|
||||||
|
wirelessLinkQuality: 0,
|
||||||
|
'4gLinkState': 0,
|
||||||
|
'4gLinkQuality': 0,
|
||||||
}
|
}
|
||||||
: d
|
};
|
||||||
));
|
console.log('创建的新设备:', JSON.stringify(newDevice, null, 2));
|
||||||
|
return [...prev, newDevice];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果设备存在,更新现有设备
|
||||||
|
return prev.map(d =>
|
||||||
|
d.deviceSn === deviceSn
|
||||||
|
? {
|
||||||
|
...d,
|
||||||
|
metrics: {
|
||||||
|
...d.metrics,
|
||||||
|
temperature: payload.properties.temperature ?? d.metrics.temperature,
|
||||||
|
humidity: payload.properties.humidity ?? d.metrics.humidity,
|
||||||
|
windSpeed: payload.properties.wind_speed ?? d.metrics.windSpeed,
|
||||||
|
rainfall: payload.properties.rainfall ?? d.metrics.rainfall,
|
||||||
|
environmentTemperature: payload.properties.environment_temperature ?? d.metrics.environmentTemperature,
|
||||||
|
positionQuality: payload.properties.position_state?.quality ?? d.metrics.positionQuality,
|
||||||
|
networkQuality: payload.properties.network_state?.quality ?? d.metrics.networkQuality,
|
||||||
|
droneInDock: payload.properties.drone_in_dock ?? d.metrics.droneInDock,
|
||||||
|
batteryCapacity: payload.properties.drone_charge_state?.capacity_percent ?? d.metrics.batteryCapacity,
|
||||||
|
batteryState: payload.properties.drone_charge_state?.state ?? d.metrics.batteryState,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
: d
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
if (newMetrics.length > 0) {
|
if (newMetrics.length > 0) {
|
||||||
|
console.log('新的性能指标:', JSON.stringify(newMetrics, null, 2));
|
||||||
setMetricsMap(prev => ({
|
setMetricsMap(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
[deviceSn]: [...(prev[deviceSn] || []), ...newMetrics].slice(-72)
|
[deviceSn]: [...(prev[deviceSn] || []), ...newMetrics].slice(-72)
|
||||||
@@ -540,12 +483,6 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
console.log('开始处理设备事件:', deviceSn);
|
console.log('开始处理设备事件:', deviceSn);
|
||||||
console.log('设备列表当前状态:', JSON.stringify(deviceList, null, 2));
|
console.log('设备列表当前状态:', JSON.stringify(deviceList, null, 2));
|
||||||
|
|
||||||
const device = deviceList.find(d => d.deviceSn === deviceSn);
|
|
||||||
if (!device) {
|
|
||||||
console.log('未找到设备:', deviceSn);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { data } = payload;
|
const { data } = payload;
|
||||||
const deviceData = data.data;
|
const deviceData = data.data;
|
||||||
console.log('设备数据:', JSON.stringify(deviceData, null, 2));
|
console.log('设备数据:', JSON.stringify(deviceData, null, 2));
|
||||||
@@ -553,6 +490,52 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
// 更新设备状态和实时数据
|
// 更新设备状态和实时数据
|
||||||
setDeviceList(prev => {
|
setDeviceList(prev => {
|
||||||
console.log('更新前的设备列表:', JSON.stringify(prev, null, 2));
|
console.log('更新前的设备列表:', JSON.stringify(prev, null, 2));
|
||||||
|
|
||||||
|
// 检查设备是否已存在
|
||||||
|
const existingDevice = prev.find(d => d.deviceSn === deviceSn);
|
||||||
|
|
||||||
|
if (!existingDevice) {
|
||||||
|
console.log('设备不存在,创建新设备记录:', deviceSn);
|
||||||
|
// 如果设备不存在,创建一个新的设备记录
|
||||||
|
const newDevice: Device = {
|
||||||
|
deviceSn: deviceSn,
|
||||||
|
deviceName: payload.headers.deviceName || deviceSn,
|
||||||
|
deviceType: 1, // 默认类型
|
||||||
|
boundStatus: 1,
|
||||||
|
createTime: moment().format('YYYY-MM-DD HH:mm:ss'),
|
||||||
|
loginTime: moment(payload.timestamp).format('YYYY-MM-DD HH:mm:ss'),
|
||||||
|
metrics: {
|
||||||
|
temperature: deviceData.temperature ?? 0,
|
||||||
|
humidity: deviceData.humidity ?? 0,
|
||||||
|
windSpeed: deviceData.wind_speed ?? 0,
|
||||||
|
rainfall: deviceData.rainfall ?? 0,
|
||||||
|
environmentTemperature: deviceData.environment_temperature ?? 0,
|
||||||
|
positionQuality: deviceData.position_state?.quality ?? 0,
|
||||||
|
networkQuality: deviceData.network_state?.quality ?? 0,
|
||||||
|
droneInDock: deviceData.drone_in_dock ?? 0,
|
||||||
|
batteryCapacity: deviceData.drone_charge_state?.capacity_percent ?? 0,
|
||||||
|
batteryState: deviceData.drone_charge_state?.state ?? 0,
|
||||||
|
workingVoltage: 0,
|
||||||
|
workingCurrent: 0,
|
||||||
|
acdcPowerInput: 0,
|
||||||
|
backupBatteryVoltage: 0,
|
||||||
|
flightTaskStep: 0,
|
||||||
|
tiltAngle: 0,
|
||||||
|
sdrUpQuality: 0,
|
||||||
|
sdrDownQuality: 0,
|
||||||
|
wirelessLinkState: 0,
|
||||||
|
wirelessLinkQuality: 0,
|
||||||
|
'4gLinkState': 0,
|
||||||
|
'4gLinkQuality': 0,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log('创建的新设备:', JSON.stringify(newDevice, null, 2));
|
||||||
|
const newList = [...prev, newDevice];
|
||||||
|
console.log('更新后的设备列表:', JSON.stringify(newList, null, 2));
|
||||||
|
return newList;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果设备存在,更新现有设备
|
||||||
const newList = prev.map(d => {
|
const newList = prev.map(d => {
|
||||||
if (d.deviceSn === deviceSn) {
|
if (d.deviceSn === deviceSn) {
|
||||||
console.log('更新设备数据:', deviceSn, JSON.stringify(deviceData, null, 2));
|
console.log('更新设备数据:', deviceSn, JSON.stringify(deviceData, null, 2));
|
||||||
@@ -660,21 +643,223 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 修改WebSocket消息处理
|
||||||
|
const handleWebSocketMessage = (data: any) => {
|
||||||
|
console.log('开始处理WebSocket消息:', JSON.stringify(data, null, 2));
|
||||||
|
|
||||||
|
if (data.type === 'result') {
|
||||||
|
const { topic, payload } = data;
|
||||||
|
|
||||||
|
// 正确提取 deviceSn
|
||||||
|
const topicParts = topic.split('/');
|
||||||
|
// topic: /device/{productId}/{deviceSn}/message/event/fire_alarm
|
||||||
|
const deviceSn = topicParts[3];
|
||||||
|
console.log('从主题中提取的设备编号:', deviceSn);
|
||||||
|
|
||||||
|
// 处理设备在线状态
|
||||||
|
if (topic.endsWith('/online')) {
|
||||||
|
console.log('处理设备在线状态:', deviceSn);
|
||||||
|
updateDeviceStatus(deviceSn, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理设备离线状态
|
||||||
|
if (topic.endsWith('/offline')) {
|
||||||
|
console.log('处理设备离线状态:', deviceSn);
|
||||||
|
updateDeviceStatus(deviceSn, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理设备属性上报
|
||||||
|
if (topic.includes('/message/property/report')) {
|
||||||
|
console.log('处理设备属性上报:', deviceSn, JSON.stringify(payload, null, 2));
|
||||||
|
handlePropertyReport(deviceSn, payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理设备火警事件
|
||||||
|
if (topic.includes('/message/event/fire_alarm')) {
|
||||||
|
console.log('处理设备火警事件:', deviceSn, JSON.stringify(payload, null, 2));
|
||||||
|
handleDeviceEvent(deviceSn, payload);
|
||||||
|
}
|
||||||
|
} else if (data.type === 'error') {
|
||||||
|
console.error('WebSocket消息错误:', data);
|
||||||
|
message.error(data.message || '消息处理错误');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 订阅设备消息
|
||||||
|
const subscribeDeviceMessages = (deviceSn?: string) => {
|
||||||
|
if (!wsRef.current || wsRef.current.readyState !== WebSocket.OPEN) {
|
||||||
|
console.log('WebSocket未连接,无法订阅消息');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('开始订阅设备消息:', deviceSn);
|
||||||
|
|
||||||
|
// 取消所有现有订阅
|
||||||
|
const unsubAll = {
|
||||||
|
type: 'unsub',
|
||||||
|
topic: '/device/*',
|
||||||
|
id: 'unsub-all',
|
||||||
|
};
|
||||||
|
console.log('取消所有订阅:', JSON.stringify(unsubAll, null, 2));
|
||||||
|
wsRef.current.send(JSON.stringify(unsubAll));
|
||||||
|
|
||||||
|
if (deviceSn) {
|
||||||
|
// 订阅指定设备的消息
|
||||||
|
const subscriptions = [
|
||||||
|
{
|
||||||
|
type: 'sub',
|
||||||
|
topic: `/device/*/${deviceSn}/online`,
|
||||||
|
id: 'online-sub',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'sub',
|
||||||
|
topic: `/device/*/${deviceSn}/offline`,
|
||||||
|
id: 'offline-sub',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'sub',
|
||||||
|
topic: `/device/*/${deviceSn}/message/property/report`,
|
||||||
|
id: 'property-sub',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'sub',
|
||||||
|
topic: `/device/*/${deviceSn}/message/event/fire_alarm`,
|
||||||
|
id: 'fire-alarm-sub',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
subscriptions.forEach(sub => {
|
||||||
|
console.log('发送订阅请求:', JSON.stringify(sub, null, 2));
|
||||||
|
wsRef.current?.send(JSON.stringify(sub));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 订阅所有设备的在线状态
|
||||||
|
const onlineSub = {
|
||||||
|
type: 'sub',
|
||||||
|
topic: '/device/*/online',
|
||||||
|
id: 'online-sub',
|
||||||
|
};
|
||||||
|
console.log('发送在线状态订阅请求:', JSON.stringify(onlineSub, null, 2));
|
||||||
|
wsRef.current.send(JSON.stringify(onlineSub));
|
||||||
|
}
|
||||||
|
console.log('设备消息订阅请求已发送');
|
||||||
|
};
|
||||||
|
|
||||||
|
// 修改 WebSocket 连接初始化
|
||||||
|
const initWebSocket = async () => {
|
||||||
|
try {
|
||||||
|
console.log('开始初始化WebSocket连接...');
|
||||||
|
const token = await getToken();
|
||||||
|
console.log('获取到WebSocket token:', token);
|
||||||
|
|
||||||
|
// 如果已经存在连接,且未关闭,不重复建立
|
||||||
|
if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) {
|
||||||
|
console.log('WebSocket已连接,无需重复建立');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (wsRef.current) {
|
||||||
|
console.log('关闭已存在的WebSocket连接');
|
||||||
|
wsRef.current.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 建立WebSocket连接
|
||||||
|
const wsUrl = `ws://119.45.169.13:8848/messaging/${token}`;
|
||||||
|
console.log('正在连接WebSocket:', wsUrl);
|
||||||
|
const ws = new WebSocket(wsUrl);
|
||||||
|
wsRef.current = ws;
|
||||||
|
|
||||||
|
ws.onopen = () => {
|
||||||
|
console.log('WebSocket连接已建立');
|
||||||
|
setWsConnected(true);
|
||||||
|
// 启动心跳检测
|
||||||
|
startHeartbeat();
|
||||||
|
// 根据当前选中的设备订阅消息
|
||||||
|
if (selectedDevice !== 'all') {
|
||||||
|
console.log('当前选中的设备:', selectedDevice);
|
||||||
|
subscribeDeviceMessages(selectedDevice);
|
||||||
|
} else {
|
||||||
|
console.log('未选择具体设备,订阅所有设备在线状态');
|
||||||
|
subscribeDeviceMessages();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onmessage = (event) => {
|
||||||
|
console.log('收到WebSocket原始消息:', event.data);
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(event.data);
|
||||||
|
console.log('解析后的WebSocket消息:', JSON.stringify(data, null, 2));
|
||||||
|
// 处理心跳响应
|
||||||
|
if (data.type === 'pong') {
|
||||||
|
console.log('收到心跳响应');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 添加调试信息
|
||||||
|
console.log('准备处理WebSocket消息...');
|
||||||
|
console.log('消息类型:', data.type);
|
||||||
|
console.log('消息主题:', data.topic);
|
||||||
|
console.log('消息负载:', JSON.stringify(data.payload, null, 2));
|
||||||
|
handleWebSocketMessage(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('解析WebSocket消息失败:', error);
|
||||||
|
console.error('原始消息内容:', event.data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onerror = (error) => {
|
||||||
|
console.error('WebSocket错误:', error);
|
||||||
|
message.error('WebSocket连接错误');
|
||||||
|
setWsConnected(false);
|
||||||
|
// 尝试重连
|
||||||
|
scheduleReconnect();
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onclose = (event) => {
|
||||||
|
console.log('WebSocket连接已关闭,代码:', event.code, '原因:', event.reason);
|
||||||
|
setWsConnected(false);
|
||||||
|
// 尝试重连
|
||||||
|
scheduleReconnect();
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error('初始化WebSocket失败:', error);
|
||||||
|
message.error('初始化WebSocket失败');
|
||||||
|
// 尝试重连
|
||||||
|
scheduleReconnect();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('组件初始化');
|
console.log('设备监控页面初始化');
|
||||||
(async () => {
|
fetchDeviceList();
|
||||||
await fetchDeviceList();
|
initWebSocket();
|
||||||
await initWebSocket();
|
|
||||||
})();
|
return () => {
|
||||||
return cleanup;
|
console.log('设备监控页面卸载,清理资源');
|
||||||
|
cleanup();
|
||||||
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// 在组件中添加调试日志
|
// 切换设备时只发订阅,不重建ws
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('选中的设备:', selectedDevice);
|
console.log('选中的设备已更改:', selectedDevice);
|
||||||
console.log('当前设备列表:', JSON.stringify(deviceList, null, 2));
|
if (wsRef.current?.readyState === WebSocket.OPEN) {
|
||||||
console.log('当前性能指标:', JSON.stringify(metricsMap, null, 2));
|
if (selectedDevice !== 'all') {
|
||||||
}, [selectedDevice, deviceList, metricsMap]);
|
console.log('WebSocket已连接,开始订阅设备消息:', selectedDevice);
|
||||||
|
subscribeDeviceMessages(selectedDevice);
|
||||||
|
} else {
|
||||||
|
console.log('WebSocket已连接,订阅所有设备在线状态');
|
||||||
|
subscribeDeviceMessages();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('WebSocket未连接,尝试重新连接...');
|
||||||
|
initWebSocket();
|
||||||
|
}
|
||||||
|
}, [selectedDevice]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedDevice !== 'all') {
|
||||||
|
console.log(`设备选择变更: ${selectedDevice}`);
|
||||||
|
subscribeDeviceMessages(selectedDevice);
|
||||||
|
}
|
||||||
|
}, [selectedDevice]);
|
||||||
|
|
||||||
const alertColumns = [
|
const alertColumns = [
|
||||||
{
|
{
|
||||||
@@ -759,25 +944,25 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
|
|
||||||
// 修改实时数据卡片的渲染逻辑
|
// 修改实时数据卡片的渲染逻辑
|
||||||
const renderRealTimeData = () => {
|
const renderRealTimeData = () => {
|
||||||
const device = deviceList.find(d => d.deviceSn === selectedDevice);
|
const currentDevice = deviceList.find(d => d.deviceSn === selectedDevice);
|
||||||
console.log('渲染实时数据卡片,当前设备:', JSON.stringify(device, null, 2));
|
console.log('渲染实时数据卡片,当前设备:', JSON.stringify(currentDevice, null, 2));
|
||||||
|
|
||||||
if (!device) {
|
if (!currentDevice) {
|
||||||
console.log('未找到选中的设备');
|
console.log('未找到选中的设备');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加设备指标值的日志
|
// 添加设备指标值的日志
|
||||||
console.log('设备指标值:', {
|
console.log('设备指标值:', JSON.stringify({
|
||||||
temperature: device.metrics.temperature,
|
temperature: currentDevice.metrics.temperature,
|
||||||
humidity: device.metrics.humidity,
|
humidity: currentDevice.metrics.humidity,
|
||||||
environmentTemperature: device.metrics.environmentTemperature,
|
environmentTemperature: currentDevice.metrics.environmentTemperature,
|
||||||
batteryCapacity: device.metrics.batteryCapacity,
|
batteryCapacity: currentDevice.metrics.batteryCapacity,
|
||||||
windSpeed: device.metrics.windSpeed,
|
windSpeed: currentDevice.metrics.windSpeed,
|
||||||
rainfall: device.metrics.rainfall,
|
rainfall: currentDevice.metrics.rainfall,
|
||||||
positionQuality: device.metrics.positionQuality,
|
positionQuality: currentDevice.metrics.positionQuality,
|
||||||
networkQuality: device.metrics.networkQuality,
|
networkQuality: currentDevice.metrics.networkQuality,
|
||||||
});
|
}, null, 2));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row gutter={[16, 16]}>
|
<Row gutter={[16, 16]}>
|
||||||
@@ -785,7 +970,7 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
<Card loading={loading}>
|
<Card loading={loading}>
|
||||||
<Statistic
|
<Statistic
|
||||||
title="温度"
|
title="温度"
|
||||||
value={device.metrics.temperature}
|
value={currentDevice.metrics.temperature}
|
||||||
suffix="°C"
|
suffix="°C"
|
||||||
valueStyle={{ color: '#3f8600' }}
|
valueStyle={{ color: '#3f8600' }}
|
||||||
/>
|
/>
|
||||||
@@ -795,7 +980,7 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
<Card loading={loading}>
|
<Card loading={loading}>
|
||||||
<Statistic
|
<Statistic
|
||||||
title="湿度"
|
title="湿度"
|
||||||
value={device.metrics.humidity}
|
value={currentDevice.metrics.humidity}
|
||||||
suffix="%"
|
suffix="%"
|
||||||
valueStyle={{ color: '#3f8600' }}
|
valueStyle={{ color: '#3f8600' }}
|
||||||
/>
|
/>
|
||||||
@@ -805,7 +990,7 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
<Card loading={loading}>
|
<Card loading={loading}>
|
||||||
<Statistic
|
<Statistic
|
||||||
title="环境温度"
|
title="环境温度"
|
||||||
value={device.metrics.environmentTemperature}
|
value={currentDevice.metrics.environmentTemperature}
|
||||||
suffix="°C"
|
suffix="°C"
|
||||||
valueStyle={{ color: '#3f8600' }}
|
valueStyle={{ color: '#3f8600' }}
|
||||||
/>
|
/>
|
||||||
@@ -815,7 +1000,7 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
<Card loading={loading}>
|
<Card loading={loading}>
|
||||||
<Statistic
|
<Statistic
|
||||||
title="电池电量"
|
title="电池电量"
|
||||||
value={device.metrics.batteryCapacity}
|
value={currentDevice.metrics.batteryCapacity}
|
||||||
suffix="%"
|
suffix="%"
|
||||||
valueStyle={{ color: '#3f8600' }}
|
valueStyle={{ color: '#3f8600' }}
|
||||||
/>
|
/>
|
||||||
@@ -825,7 +1010,7 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
<Card loading={loading}>
|
<Card loading={loading}>
|
||||||
<Statistic
|
<Statistic
|
||||||
title="风速"
|
title="风速"
|
||||||
value={device.metrics.windSpeed}
|
value={currentDevice.metrics.windSpeed}
|
||||||
suffix="m/s"
|
suffix="m/s"
|
||||||
valueStyle={{ color: '#3f8600' }}
|
valueStyle={{ color: '#3f8600' }}
|
||||||
/>
|
/>
|
||||||
@@ -835,7 +1020,7 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
<Card loading={loading}>
|
<Card loading={loading}>
|
||||||
<Statistic
|
<Statistic
|
||||||
title="降雨量"
|
title="降雨量"
|
||||||
value={device.metrics.rainfall}
|
value={currentDevice.metrics.rainfall}
|
||||||
suffix="mm"
|
suffix="mm"
|
||||||
valueStyle={{ color: '#3f8600' }}
|
valueStyle={{ color: '#3f8600' }}
|
||||||
/>
|
/>
|
||||||
@@ -845,7 +1030,7 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
<Card loading={loading}>
|
<Card loading={loading}>
|
||||||
<Statistic
|
<Statistic
|
||||||
title="定位质量"
|
title="定位质量"
|
||||||
value={device.metrics.positionQuality}
|
value={currentDevice.metrics.positionQuality}
|
||||||
suffix="级"
|
suffix="级"
|
||||||
valueStyle={{ color: '#3f8600' }}
|
valueStyle={{ color: '#3f8600' }}
|
||||||
/>
|
/>
|
||||||
@@ -855,7 +1040,7 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
<Card loading={loading}>
|
<Card loading={loading}>
|
||||||
<Statistic
|
<Statistic
|
||||||
title="网络质量"
|
title="网络质量"
|
||||||
value={device.metrics.networkQuality}
|
value={currentDevice.metrics.networkQuality}
|
||||||
suffix="级"
|
suffix="级"
|
||||||
valueStyle={{ color: '#3f8600' }}
|
valueStyle={{ color: '#3f8600' }}
|
||||||
/>
|
/>
|
||||||
@@ -865,65 +1050,6 @@ const DeviceMonitor: React.FC = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 订阅设备消息
|
|
||||||
const subscribeDeviceMessages = (deviceSn?: string) => {
|
|
||||||
if (!wsRef.current || wsRef.current.readyState !== WebSocket.OPEN) {
|
|
||||||
console.log('WebSocket未连接,无法订阅消息');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('开始订阅设备消息:', deviceSn);
|
|
||||||
|
|
||||||
// 取消所有现有订阅
|
|
||||||
const unsubAll = {
|
|
||||||
type: 'unsub',
|
|
||||||
topic: '/device/*',
|
|
||||||
id: 'unsub-all',
|
|
||||||
};
|
|
||||||
console.log('取消所有订阅:', JSON.stringify(unsubAll, null, 2));
|
|
||||||
wsRef.current.send(JSON.stringify(unsubAll));
|
|
||||||
|
|
||||||
if (deviceSn) {
|
|
||||||
// 订阅指定设备的消息
|
|
||||||
const subscriptions = [
|
|
||||||
{
|
|
||||||
type: 'sub',
|
|
||||||
topic: `/device/*/${deviceSn}/online`,
|
|
||||||
id: 'online-sub',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'sub',
|
|
||||||
topic: `/device/*/${deviceSn}/offline`,
|
|
||||||
id: 'offline-sub',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'sub',
|
|
||||||
topic: `/device/*/${deviceSn}/message/property/report`,
|
|
||||||
id: 'property-sub',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'sub',
|
|
||||||
topic: `/device/*/${deviceSn}/message/event/fire_alarm`,
|
|
||||||
id: 'fire-alarm-sub',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
subscriptions.forEach(sub => {
|
|
||||||
console.log('发送订阅请求:', JSON.stringify(sub, null, 2));
|
|
||||||
wsRef.current?.send(JSON.stringify(sub));
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// 订阅所有设备的在线状态
|
|
||||||
const onlineSub = {
|
|
||||||
type: 'sub',
|
|
||||||
topic: '/device/*/online',
|
|
||||||
id: 'online-sub',
|
|
||||||
};
|
|
||||||
console.log('发送在线状态订阅请求:', JSON.stringify(onlineSub, null, 2));
|
|
||||||
wsRef.current.send(JSON.stringify(onlineSub));
|
|
||||||
}
|
|
||||||
console.log('设备消息订阅请求已发送');
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer>
|
<PageContainer>
|
||||||
<Row gutter={[16, 16]}>
|
<Row gutter={[16, 16]}>
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ import {
|
|||||||
ProFormText,
|
ProFormText,
|
||||||
} from '@ant-design/pro-components';
|
} from '@ant-design/pro-components';
|
||||||
import { Button, Form, message, Upload } from 'antd';
|
import { Button, Form, message, Upload } from 'antd';
|
||||||
import { RcFile } from 'antd/lib/upload';
|
import type { RcFile } from 'antd/lib/upload';
|
||||||
import { useState, useRef, useEffect } from 'react';
|
import { useState, useRef, useEffect } from 'react';
|
||||||
import styles from '../index.less';
|
import styles from '../index.less';
|
||||||
import { TOURISM_OPTIONS, TYPE_OPTIONS, WORKSPACE_OPTIONS } from '../index';
|
import { TOURISM_OPTIONS, TYPE_OPTIONS, WORKSPACE_OPTIONS } from '../index';
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import React, { useRef, useState, useCallback } from 'react';
|
|||||||
import UpdateForm from './components/UpdateForm';
|
import UpdateForm from './components/UpdateForm';
|
||||||
import styles from './index.less';
|
import styles from './index.less';
|
||||||
import SparkMD5 from 'spark-md5';
|
import SparkMD5 from 'spark-md5';
|
||||||
import { DefaultOptionType } from 'antd/es/select';
|
import type { DefaultOptionType } from 'antd/es/select';
|
||||||
|
|
||||||
const { Link } = Typography;
|
const { Link } = Typography;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ import {
|
|||||||
import { Button, Upload, Image, message, Form } from 'antd';
|
import { Button, Upload, Image, message, Form } from 'antd';
|
||||||
import type { RcFile } from 'antd/lib/upload';
|
import type { RcFile } from 'antd/lib/upload';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { TYPE_OPTIONS } from '../constants';
|
import type { TYPE_OPTIONS } from '../constants';
|
||||||
|
|
||||||
interface UpdateFormProps {
|
interface UpdateFormProps {
|
||||||
onSubmit: (values: any) => Promise<void>;
|
onSubmit: (values: any) => Promise<void>;
|
||||||
|
|||||||
@@ -49,11 +49,11 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
|||||||
request={async () => {
|
request={async () => {
|
||||||
const menus = await menuOnes();
|
const menus = await menuOnes();
|
||||||
if (menus) {
|
if (menus) {
|
||||||
let a = menus.map(item => {
|
const a = menus.map(item => {
|
||||||
return { ...item, key: item.id, title: item.name, value: item.id }
|
return { ...item, key: item.id, title: item.name, value: item.id }
|
||||||
})
|
})
|
||||||
let treeData = treeify(a, {});
|
const treeData = treeify(a, {});
|
||||||
let root = {
|
const root = {
|
||||||
title: '顶级目录',
|
title: '顶级目录',
|
||||||
value: -1,
|
value: -1,
|
||||||
key: -1,
|
key: -1,
|
||||||
|
|||||||
Reference in New Issue
Block a user