feat(设备管理):新增设备管理控制面板功能
This commit is contained in:
+27
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+231
@@ -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<DeviceControlPanelProps> = ({ visible, onClose, deviceSn }) => {
|
||||
const [streamUrls, setStreamUrls] = useState<any>(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<WebSocket | null>(null);
|
||||
const playerRef = useRef<any>(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 (
|
||||
<Modal
|
||||
title={
|
||||
<Space>
|
||||
<span>设备控制面板</span>
|
||||
<Badge
|
||||
status={wsConnected ? 'success' : 'error'}
|
||||
text={wsConnected ? '已连接' : '未连接'}
|
||||
/>
|
||||
</Space>
|
||||
}
|
||||
open={visible}
|
||||
onCancel={onClose}
|
||||
width={1200}
|
||||
footer={null}
|
||||
>
|
||||
<Row gutter={16}>
|
||||
<Col span={16}>
|
||||
<Card title="视频流" className={styles.videoCard}>
|
||||
{streamUrls && (
|
||||
<ReactPlayer
|
||||
ref={playerRef}
|
||||
url={streamUrls.playFlvUrl}
|
||||
controls
|
||||
width="100%"
|
||||
height={450}
|
||||
playing={isPlaying}
|
||||
/>
|
||||
)}
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Card title="设备控制" className={styles.controlCard}>
|
||||
<Space direction="vertical" style={{ width: '100%' }}>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={isPlaying ? <PauseOutlined /> : <PlayCircleOutlined />}
|
||||
onClick={() => setIsPlaying(!isPlaying)}
|
||||
block
|
||||
>
|
||||
{isPlaying ? '暂停' : '播放'}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
icon={<CameraOutlined />}
|
||||
onClick={handleTakePhoto}
|
||||
block
|
||||
>
|
||||
拍照
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
type={isRecording ? 'primary' : 'default'}
|
||||
icon={<VideoCameraOutlined />}
|
||||
onClick={isRecording ? handleStopRecording : handleStartRecording}
|
||||
block
|
||||
>
|
||||
{isRecording ? '停止录像' : '开始录像'}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
icon={<HomeOutlined />}
|
||||
onClick={handleReturnHome}
|
||||
block
|
||||
>
|
||||
返航
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
icon={<PauseCircleOutlined />}
|
||||
onClick={handlePauseTask}
|
||||
block
|
||||
>
|
||||
暂停任务
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
icon={<ControlOutlined />}
|
||||
onClick={handleEnterDRCMode}
|
||||
block
|
||||
>
|
||||
指令飞行
|
||||
</Button>
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
<Card title="设备状态" className={styles.statusCard}>
|
||||
<Statistic title="设备SN" value={deviceSn} />
|
||||
<Statistic
|
||||
title="相机模式"
|
||||
value={cameraMode === 0 ? '拍照模式' : '录像模式'}
|
||||
/>
|
||||
<Statistic
|
||||
title="录像状态"
|
||||
value={isRecording ? '录制中' : '未录制'}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default DeviceControlPanel;
|
||||
@@ -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<boolean>(false);
|
||||
const [streamUrls, setStreamUrls] = useState<any>(null);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [controlPanelVisible, setControlPanelVisible] = useState<boolean>(false);
|
||||
|
||||
// 统一的API请求处理函数
|
||||
const handleRequest = async (
|
||||
@@ -204,6 +206,15 @@ const TableList: React.FC = () => {
|
||||
>
|
||||
<VideoCameraOutlined /> 视频流
|
||||
</a>,
|
||||
<a
|
||||
key="control"
|
||||
onClick={() => {
|
||||
setCurrentRow(record);
|
||||
setControlPanelVisible(true);
|
||||
}}
|
||||
>
|
||||
<ControlOutlined /> 控制面板
|
||||
</a>,
|
||||
<a
|
||||
key="edit"
|
||||
onClick={() => {
|
||||
@@ -412,6 +423,17 @@ const TableList: React.FC = () => {
|
||||
deviceSn={currentRow?.deviceSn || ''}
|
||||
/>
|
||||
)}
|
||||
|
||||
{currentRow && (
|
||||
<DeviceControlPanel
|
||||
visible={controlPanelVisible}
|
||||
onClose={() => {
|
||||
setControlPanelVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
}}
|
||||
deviceSn={currentRow.deviceSn}
|
||||
/>
|
||||
)}
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user