From 0d76b14556f8e3870c4900ffbcd672047fa26661 Mon Sep 17 00:00:00 2001 From: Iamasoldier <1272745473@qq.com> Date: Mon, 19 May 2025 13:27:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86)?= =?UTF-8?q?=EF=BC=9A=E6=96=B0=E5=A2=9E=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E9=9D=A2=E6=9D=BF=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/components/DeviceControlPanel.less | 27 ++ .../Device/components/DeviceControlPanel.tsx | 231 ++++++++++++++++++ .../src/pages/device/Device/index.tsx | 24 +- 3 files changed, 281 insertions(+), 1 deletion(-) create mode 100644 zlt-web/react-web/src/main/frontend/src/pages/device/Device/components/DeviceControlPanel.less create mode 100644 zlt-web/react-web/src/main/frontend/src/pages/device/Device/components/DeviceControlPanel.tsx diff --git a/zlt-web/react-web/src/main/frontend/src/pages/device/Device/components/DeviceControlPanel.less b/zlt-web/react-web/src/main/frontend/src/pages/device/Device/components/DeviceControlPanel.less new file mode 100644 index 00000000..7e3a9392 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/device/Device/components/DeviceControlPanel.less @@ -0,0 +1,27 @@ +.videoCard { + margin-bottom: 16px; + + :global { + .ant-card-body { + padding: 0; + } + } +} + +.controlCard { + margin-bottom: 16px; + + :global { + .ant-space { + width: 100%; + } + } +} + +.statusCard { + :global { + .ant-statistic { + margin-bottom: 16px; + } + } +} \ No newline at end of file diff --git a/zlt-web/react-web/src/main/frontend/src/pages/device/Device/components/DeviceControlPanel.tsx b/zlt-web/react-web/src/main/frontend/src/pages/device/Device/components/DeviceControlPanel.tsx new file mode 100644 index 00000000..acaf8200 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/device/Device/components/DeviceControlPanel.tsx @@ -0,0 +1,231 @@ +import React, { useState, useEffect, useRef } from 'react'; +import { Modal, Tabs, Button, Space, Card, Row, Col, Statistic, message, Badge } from 'antd'; +import { + PlayCircleOutlined, + PauseOutlined, + CameraOutlined, + VideoCameraOutlined, + HomeOutlined, + PauseCircleOutlined, + ControlOutlined +} from '@ant-design/icons'; +import ReactPlayer from 'react-player'; +import { getStreamUrls } from '@/services/device/api'; +import styles from './DeviceControlPanel.less'; + +interface DeviceControlPanelProps { + visible: boolean; + onClose: () => void; + deviceSn: string; +} + +const DeviceControlPanel: React.FC = ({ visible, onClose, deviceSn }) => { + const [streamUrls, setStreamUrls] = useState(null); + const [isPlaying, setIsPlaying] = useState(true); + const [cameraMode, setCameraMode] = useState(0); // 0=拍照,1=录像 + const [isRecording, setIsRecording] = useState(false); + const [wsConnected, setWsConnected] = useState(false); + const wsRef = useRef(null); + const playerRef = useRef(null); + + // 初始化WebSocket连接 + useEffect(() => { + if (visible) { + const ws = new WebSocket('ws://your-websocket-server'); + wsRef.current = ws; + + ws.onopen = () => { + setWsConnected(true); + message.success('设备连接成功'); + }; + + ws.onclose = () => { + setWsConnected(false); + message.error('设备连接断开'); + }; + + ws.onerror = (error) => { + console.error('WebSocket错误:', error); + message.error('设备连接错误'); + }; + + return () => { + ws.close(); + }; + } + }, [visible]); + + // 获取视频流地址 + useEffect(() => { + if (visible) { + getStreamUrls(deviceSn).then(res => { + if (res.resp_code === 0) { + setStreamUrls(res.data); + } + }); + } + }, [visible, deviceSn]); + + // 发送控制指令 + const sendControlCommand = (method: string, data: any = {}) => { + if (!wsRef.current || wsRef.current.readyState !== WebSocket.OPEN) { + message.error('设备未连接'); + return; + } + + const command = { + type: 'sub', + topic: `/device-message-sender/D-Dock2/${deviceSn}`, + parameter: { + messageType: 'WRITE_PROPERTY', + properties: { + method, + data + }, + headers: { + async: false + } + }, + id: `cmd_${Date.now()}` + }; + + wsRef.current.send(JSON.stringify(command)); + }; + + // 控制按钮事件处理 + const handleTakePhoto = () => { + sendControlCommand('camera_photo_take'); + message.success('拍照指令已发送'); + }; + + const handleStartRecording = () => { + sendControlCommand('camera_recording_start'); + setIsRecording(true); + message.success('开始录像'); + }; + + const handleStopRecording = () => { + sendControlCommand('camera_recording_stop'); + setIsRecording(false); + message.success('停止录像'); + }; + + const handleReturnHome = () => { + sendControlCommand('return_home'); + message.success('返航指令已发送'); + }; + + const handlePauseTask = () => { + sendControlCommand('flighttask_pause'); + message.success('暂停任务指令已发送'); + }; + + const handleEnterDRCMode = () => { + sendControlCommand('drc_mode_enter'); + message.success('进入指令飞行模式'); + }; + + return ( + + 设备控制面板 + + + } + open={visible} + onCancel={onClose} + width={1200} + footer={null} + > + + + + {streamUrls && ( + + )} + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +}; + +export default DeviceControlPanel; \ No newline at end of file diff --git a/zlt-web/react-web/src/main/frontend/src/pages/device/Device/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/device/Device/index.tsx index 03a8748b..62f682db 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/device/Device/index.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/device/Device/index.tsx @@ -5,7 +5,7 @@ import { updateDeviceBoundStatus, getStreamUrls, } from '@/services/device/api'; -import { PlusOutlined, ExportOutlined, ImportOutlined, DownloadOutlined, VideoCameraOutlined } from '@ant-design/icons'; +import { PlusOutlined, ExportOutlined, ImportOutlined, DownloadOutlined, VideoCameraOutlined, ControlOutlined } from '@ant-design/icons'; import type { ActionType, ProColumns } from '@ant-design/pro-components'; import { ModalForm, @@ -22,6 +22,7 @@ import React, { useRef, useState } from 'react'; import moment from 'moment'; import UpdateForm from './components/UpdateForm'; import VideoPlayer from './components/VideoPlayer'; +import DeviceControlPanel from './components/DeviceControlPanel'; const DEVICE_TYPE = { DOCK: 1, @@ -43,6 +44,7 @@ const TableList: React.FC = () => { const [videoModalVisible, setVideoModalVisible] = useState(false); const [streamUrls, setStreamUrls] = useState(null); const [loading, setLoading] = useState(false); + const [controlPanelVisible, setControlPanelVisible] = useState(false); // 统一的API请求处理函数 const handleRequest = async ( @@ -204,6 +206,15 @@ const TableList: React.FC = () => { > 视频流 , + { + setCurrentRow(record); + setControlPanelVisible(true); + }} + > + 控制面板 + , { @@ -412,6 +423,17 @@ const TableList: React.FC = () => { deviceSn={currentRow?.deviceSn || ''} /> )} + + {currentRow && ( + { + setControlPanelVisible(false); + setCurrentRow(undefined); + }} + deviceSn={currentRow.deviceSn} + /> + )} ); };