From 89d18ea0da2333ff4066a696264914934684f502 Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Mon, 11 May 2026 14:59:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A3=85=E5=A4=87=20=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 16 + package.json | 1 + src/api/api.ts | 8 +- src/api/device.ts | 8 + src/components/VolcRtcPlayer.jsx | 108 +++ src/components/alerts/AlarmOverview.tsx | 605 +++++++++---- src/components/devices/DeviceOverviewPage.tsx | 236 +++--- src/components/droneplayer.jsx | 34 + src/pages/AIAnalysis.tsx | 800 ++++++++---------- src/pages/Devices.tsx | 74 +- 10 files changed, 1117 insertions(+), 773 deletions(-) create mode 100644 src/components/VolcRtcPlayer.jsx create mode 100644 src/components/droneplayer.jsx diff --git a/package-lock.json b/package-lock.json index 4f2253c..e6b7dc7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@reduxjs/toolkit": "^2.11.2", "@tailwindcss/vite": "^4.1.14", "@vitejs/plugin-react": "^5.0.4", + "@volcengine/rtc": "^4.66.37", "antd": "^5.24.1", "axios": "^1.15.1", "clsx": "^2.1.1", @@ -2477,6 +2478,21 @@ "vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/@volcengine/rtc": { + "version": "4.66.37", + "resolved": "https://registry.npmjs.org/@volcengine/rtc/-/rtc-4.66.37.tgz", + "integrity": "sha512-VU/ktMFACfzqjQ4eRUmefKu0DaCmVc2wzsn+vFHSNmwXsbRLsodwjqA34zp/y6vfU6gjsMmCPku2iSV/YQIV/A==", + "license": "BSD-3-Clause", + "dependencies": { + "eventemitter3": "^4.0.7" + } + }, + "node_modules/@volcengine/rtc/node_modules/eventemitter3": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", + "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==", + "license": "MIT" + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", diff --git a/package.json b/package.json index 21ed66a..28bc4df 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@reduxjs/toolkit": "^2.11.2", "@tailwindcss/vite": "^4.1.14", "@vitejs/plugin-react": "^5.0.4", + "@volcengine/rtc": "^4.66.37", "antd": "^5.24.1", "axios": "^1.15.1", "clsx": "^2.1.1", diff --git a/src/api/api.ts b/src/api/api.ts index fc66694..6c2d6ee 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -180,13 +180,7 @@ export function getWayLine() { } //直播流 -export function getLiveStream(data) { - return api({ - url: '/iot/UAV/liveStream', - method: 'post', - data - }) -} + ///iot/UAV/flightTaskCommand export function postFlightCommmand(data) { return api({ diff --git a/src/api/device.ts b/src/api/device.ts index 781d316..349305d 100644 --- a/src/api/device.ts +++ b/src/api/device.ts @@ -15,3 +15,11 @@ export function getPlaneDeviceList() { }) } +export function getLiveStream(data) { + return request({ + url: '/iot/UAV/liveStream', + method: 'post', + data + }) +} + diff --git a/src/components/VolcRtcPlayer.jsx b/src/components/VolcRtcPlayer.jsx new file mode 100644 index 0000000..a8645ea --- /dev/null +++ b/src/components/VolcRtcPlayer.jsx @@ -0,0 +1,108 @@ +import React, { useEffect, useRef } from "react"; +import { joinRoom, leaveRoom } from "./droneplayer"; +import { postLiveHeartbeat } from "@/api/api"; + +export default function DroneLivePlayer({ streamData, videoMode = "NORMAL" }) { + console.log(streamData) + const containerRef = useRef(null); + const timerRef = useRef(null); + + // ------------ 核心修复:防止异步竞态 ------------ + const isBusyRef = useRef(false); // 正在加入/离开,禁止重复操作 + const mountedRef = useRef(true); // 组件是否挂载 + + useEffect(() => { + mountedRef.current = true; + const container = containerRef.current; + + // 清空容器,防止 DOM 不为空 + if (container) container.innerHTML = ""; + + if (!container || !streamData?.url) return; + + // 解析参数 + const params = new URLSearchParams(streamData.url); + const appId = (params.get("app_id") || params.get("appid") || "").trim(); + const roomId = (params.get("room_id") || params.get("roomid") || "").trim(); + const token = decodeURIComponent((params.get("token") || "").trim()); + const userId = (params.get("user_id") || params.get("uid") || "").trim(); + + if (!appId || !roomId || !token || !userId) return; + + // 心跳 + const liveheartbeat = async () => { + try { + await postLiveHeartbeat({ + sn: streamData.sn, + cameraIndex: streamData.camera_index, + }); + } catch (err) { + console.error("心跳失败", err); + } + }; + + // ---------------- 真正安全的初始化流程 ---------------- + const safeInit = async () => { + // 1. 防止并发:正在忙就直接退出 + if (isBusyRef.current) return; + isBusyRef.current = true; + + try { + // 2. 【强制顺序】先销毁旧房间 + 清心跳 + if (timerRef.current) { + clearInterval(timerRef.current); + timerRef.current = null; + } + leaveRoom(); // 先离开旧房间 + await new Promise((resolve) => setTimeout(resolve, 100)); // 等待 SDK 内部清理完成 + + // 3. 组件已卸载,直接放弃 + if (!mountedRef.current) { + isBusyRef.current = false; + return; + } + + // 4. 加入新房间(此时绝对安全) + await joinRoom(container, appId, roomId, token, userId, videoMode); + + // 5. 开启心跳 + //timerRef.current = setInterval(liveheartbeat, 3000); + //liveheartbeat(); + } catch (err) { + console.error("RTC 初始化失败", err); + } finally { + // 解锁 + isBusyRef.current = false; + } + }; + + safeInit(); + + // ---------------- 清理函数 ---------------- + return () => { + mountedRef.current = false; + + // 清理心跳 + if (timerRef.current) { + clearInterval(timerRef.current); + timerRef.current = null; + } + + // 离开房间 + leaveRoom(); + }; + }, [ + streamData?.url, + streamData?.sn, + streamData?.camera_index, + videoMode, + ]); + + return ( +
+ ); +} diff --git a/src/components/alerts/AlarmOverview.tsx b/src/components/alerts/AlarmOverview.tsx index 3ec66dc..046bc49 100644 --- a/src/components/alerts/AlarmOverview.tsx +++ b/src/components/alerts/AlarmOverview.tsx @@ -1,37 +1,44 @@ import React, { useState } from 'react'; import { Card, Row, Col, Select, DatePicker, Input, Button, Space, Table, Tag, - Statistic, Typography, Modal, Form, Checkbox, message + Statistic, Typography, Modal, Form, Checkbox, message, Switch, Divider, Pagination } from 'antd'; import { - BellOutlined, ClockCircleOutlined, CheckCircleOutlined, ExclamationCircleOutlined + BellOutlined, ClockCircleOutlined, CheckCircleOutlined, ExclamationCircleOutlined, + SearchOutlined, ReloadOutlined, CloseOutlined, InfoCircleOutlined, + SendOutlined, MailOutlined, MessageOutlined, DesktopOutlined, + FileTextOutlined, LineChartOutlined, PieChartOutlined, BarChartOutlined, + RiseOutlined } from '@ant-design/icons'; import { Line, Pie, Bar } from '@ant-design/charts'; const { RangePicker } = DatePicker; -const { Text } = Typography; +const { Text, Title } = Typography; // 级别 + 状态颜色 const levelColor = { - 严重: 'red', - 重要: 'orange', - 一般: 'gold', - 提示: 'blue' + 严重: '#F53F3F', + 重要: '#FF7D00', + 一般: '#F7BA1E', + 提示: '#165DFF' }; const statusColor = { - 处理中: 'processing', - 待处理: 'warning', - 已关闭: 'success' + 处理中: '#165DFF', + 待处理: '#F7BA1E', + 已关闭: '#00B42A' }; // 模拟数据 const mockAlerts = [ - { id: 'DEVICE_OFFLINE_CAM-02', content: '设备离线', device: 'CAM-02', level: '提示', time: '2026-04-28 17:22:04', duration: '1小时23分', status: '待处理', handler: '-' }, - { id: 'INV_TEMP_HIGH_INV-A02', content: '逆变器温度过高', device: 'INV-A02', level: '重要', time: '2026-04-28 17:21:54', duration: '1小时23分', status: '待处理', handler: '-' }, - { id: 'AL-20260428-001', content: 'INV-A02 温度过高', device: 'INV-A02', level: '重要', time: '2026-04-28 10:54:45', duration: '36分钟', status: '待处理', handler: '-' }, - { id: 'AL-20260428-002', content: 'CMB-A01 组串电流异常', device: 'CMB-A01', level: '一般', time: '2026-04-28 10:32:45', duration: '52分钟', status: '处理中', handler: '张运维' }, - { id: 'AL-20260428-003', content: 'CAM-02 视频离线', device: 'CAM-02', level: '提示', time: '2026-04-28 09:32:45', duration: '0分钟', status: '待处理', handler: '-' }, + { id: 'AL20250525001', content: '逆变器停机', device: '逆变器 12 (组串式)', level: '严重', time: '2025-05-25 09:18:32', duration: '2小时18分', status: '处理中', handler: '张运维' }, + { id: 'AL20250525002', content: '发电量下降 > 15%', device: '汇流箱 05', level: '重要', time: '2025-05-25 08:46:11', duration: '3小时50分', status: '处理中', handler: '李工程师' }, + { id: 'AL20250525003', content: '逆变器温度过高', device: '逆变器 07 (组串式)', level: '重要', time: '2025-05-25 07:32:45', duration: '4小时24分', status: '待处理', handler: '-' }, + { id: 'AL20250525004', content: '通信中断', device: '气象站 01', level: '一般', time: '2025-05-25 06:51:20', duration: '5小时05分', status: '待处理', handler: '王运维' }, + { id: 'AL20250525005', content: '数据异常', device: '电表 01 (并网点)', level: '提示', time: '2025-05-25 06:20:18', duration: '3小时36分', status: '已关闭', handler: '赵工程师' }, + { id: 'AL20250525006', content: '发电量下降 > 15%', device: '组串 3-15', level: '重要', time: '2025-05-25 05:45:02', duration: '6小时10分', status: '处理中', handler: '李工程师' }, + { id: 'AL20250525007', content: '逆变器停机', device: '逆变器 03 (组串式)', level: '严重', time: '2025-05-25 04:28:33', duration: '7小时28分', status: '处理中', handler: '张运维' }, + { id: 'AL20250525008', content: '通信中断', device: '智能汇流箱 08', level: '一般', time: '2025-05-25 03:15:47', duration: '2小时18分', status: '已关闭', handler: '王运维' }, ]; // 通知渠道 @@ -43,28 +50,50 @@ const channelOptions = [ ]; export default function AlarmCenterPage() { - const [selectedAlert, setSelectedAlert] = useState