修改别名成功
This commit is contained in:
@@ -2,7 +2,8 @@ import React, { useState, useEffect, useRef, useMemo } from 'react';
|
|||||||
import {
|
import {
|
||||||
Layout, Card, Row, Col, Statistic, Tag, Button, Table,
|
Layout, Card, Row, Col, Statistic, Tag, Button, Table,
|
||||||
Typography, Space, Progress, Badge, Timeline, message,
|
Typography, Space, Progress, Badge, Timeline, message,
|
||||||
Select, Modal, Space as AntSpace
|
Select, Modal, Space as AntSpace,
|
||||||
|
Input
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import {
|
import {
|
||||||
EnvironmentOutlined, RobotOutlined, BranchesOutlined,
|
EnvironmentOutlined, RobotOutlined, BranchesOutlined,
|
||||||
@@ -22,12 +23,13 @@ import AgoraTextTest from '../AgoraRtc.tsx';
|
|||||||
import { useWebRTCPlayer } from '../useWebRTCStream.tsx';
|
import { useWebRTCPlayer } from '../useWebRTCStream.tsx';
|
||||||
import VideoPlayer from '../VideoPlayer.tsx.tsx';
|
import VideoPlayer from '../VideoPlayer.tsx.tsx';
|
||||||
import CesiumMap from '../Map.jsx';
|
import CesiumMap from '../Map.jsx';
|
||||||
import { getUAVState, getSiteDevice, getSiteUAVList, getsinglePlan, getRobotTaskList, getDeviceTotalData } from '@/api/device.ts';
|
import { getUAVState, getSiteDevice, getSiteUAVList, getsinglePlan, getRobotTaskList, getDeviceTotalData, updateDeviceAliasApi } from '@/api/device.ts';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { useMqtt } from '@/hooks/useMqtt';
|
import { useMqtt } from '@/hooks/useMqtt';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
import { RootState } from '@/store';
|
import { RootState } from '@/store';
|
||||||
import envConfig from '../../../env';
|
import envConfig from '../../../env';
|
||||||
|
import utils from '@/lib/utils.ts';
|
||||||
|
|
||||||
const { Content } = Layout;
|
const { Content } = Layout;
|
||||||
const { Text, Title } = Typography;
|
const { Text, Title } = Typography;
|
||||||
@@ -66,6 +68,12 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
|
|||||||
const [taskStats, setTaskStats] = useState({ completed: 12, total: 15 });
|
const [taskStats, setTaskStats] = useState({ completed: 12, total: 15 });
|
||||||
const [deviceStatistics, setDeviceStatistics] = useState(null);
|
const [deviceStatistics, setDeviceStatistics] = useState(null);
|
||||||
|
|
||||||
|
// 编辑机器人弹窗相关
|
||||||
|
const [editRobotModalOpen, setEditRobotModalOpen] = useState(false);
|
||||||
|
const [currentEditRobot, setCurrentEditRobot] = useState(null);
|
||||||
|
const [editAliasInput, setEditAliasInput] = useState('');
|
||||||
|
const [editLoading, setEditLoading] = useState(false);
|
||||||
|
|
||||||
// 获取数据
|
// 获取数据
|
||||||
const fetchAllData = async () => {
|
const fetchAllData = async () => {
|
||||||
if (!stationId) return;
|
if (!stationId) return;
|
||||||
@@ -108,6 +116,50 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// 打开编辑弹窗
|
||||||
|
const openEditRobotModal = (record) => {
|
||||||
|
// 仅机器人允许编辑,无人机直接提示
|
||||||
|
const isRobot = !record.gateway_sn && !record.drone_callsign;
|
||||||
|
if (!isRobot) {
|
||||||
|
message.info('仅支持编辑机器人设备别名');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setCurrentEditRobot(record);
|
||||||
|
setEditAliasInput(record.deviceAlias || record.deviceName || '');
|
||||||
|
setEditRobotModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 确认保存别名
|
||||||
|
const handleSaveRobotAlias = async () => {
|
||||||
|
if (!currentEditRobot || !editAliasInput.trim()) {
|
||||||
|
utils.message.warning('设备别名不能为空');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setEditLoading(true);
|
||||||
|
try {
|
||||||
|
const data = {
|
||||||
|
deviceId: currentEditRobot.serialNumber,
|
||||||
|
deviceAlias: editAliasInput.trim()
|
||||||
|
}
|
||||||
|
const sn = currentEditRobot.device_sn || currentEditRobot.serialNumber;
|
||||||
|
const res = await updateDeviceAliasApi(data);
|
||||||
|
if (res.code === 200 && res.data == true) {
|
||||||
|
fetchAllData();
|
||||||
|
utils.message.success('别名修改成功');
|
||||||
|
|
||||||
|
setEditRobotModalOpen(false);
|
||||||
|
} else {
|
||||||
|
utils.message.error('修改失败,请重试');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('修改别名报错', err);
|
||||||
|
utils.message.error('接口异常,修改失败');
|
||||||
|
} finally {
|
||||||
|
setEditLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchAllData();
|
fetchAllData();
|
||||||
}, [stationId]);
|
}, [stationId]);
|
||||||
@@ -585,8 +637,23 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
|
|||||||
}, { title: '位置', dataIndex: 'position', width: 90 },
|
}, { title: '位置', dataIndex: 'position', width: 90 },
|
||||||
//{ title: '当前任务', dataIndex: 'task', width: 100 },
|
//{ title: '当前任务', dataIndex: 'task', width: 100 },
|
||||||
{ title: '通讯状态', dataIndex: 'comm', width: 100, render: v => <Badge status={v.includes('-') ? 'warning' : 'success'} text={v} /> },
|
{ title: '通讯状态', dataIndex: 'comm', width: 100, render: v => <Badge status={v.includes('-') ? 'warning' : 'success'} text={v} /> },
|
||||||
{ title: '操作', key: 'action', width: 80, render: () => <Space size={4}><Button size="small" type="text" icon={<EditOutlined />} /><Button size="small" type="text" icon={<SettingOutlined />} /></Space> },
|
{
|
||||||
]}
|
title: '操作',
|
||||||
|
key: 'action',
|
||||||
|
width: 80,
|
||||||
|
render: (_, record) => (
|
||||||
|
<Space size={4}>
|
||||||
|
{/* 编辑按钮绑定弹窗 */}
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
type="text"
|
||||||
|
icon={<EditOutlined />}
|
||||||
|
onClick={() => openEditRobotModal(record)}
|
||||||
|
/>
|
||||||
|
<Button size="small" type="text" icon={<SettingOutlined />} />
|
||||||
|
</Space>
|
||||||
|
)
|
||||||
|
},]}
|
||||||
dataSource={dynamicScheduleList}
|
dataSource={dynamicScheduleList}
|
||||||
scroll={{ x: 'max-content', y: 280 }}
|
scroll={{ x: 'max-content', y: 280 }}
|
||||||
/>
|
/>
|
||||||
@@ -902,9 +969,50 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
<Modal title="视频预览" open={!!zoomedVideo} onCancel={() => setZoomedVideo(null)} footer={null} width={1000} centered bodyStyle={{ padding: 0, height: 600, background: '#000' }} destroyOnClose>
|
{/* 机器人编辑别名弹窗 */}
|
||||||
{zoomedVideo && <DroneLivePlayer streamData={zoomedVideo} videoMode="LARGE" />}
|
<Modal
|
||||||
|
title="编辑机器人设备信息"
|
||||||
|
open={editRobotModalOpen}
|
||||||
|
onCancel={() => setEditRobotModalOpen(false)}
|
||||||
|
confirmLoading={editLoading}
|
||||||
|
onOk={handleSaveRobotAlias}
|
||||||
|
maskClosable={false}
|
||||||
|
>
|
||||||
|
{currentEditRobot && (
|
||||||
|
<div style={{ padding: '8px 0' }}>
|
||||||
|
<div style={{ marginBottom: 16 }}>
|
||||||
|
<Typography.Text strong>设备SN:</Typography.Text>
|
||||||
|
<Typography.Text copyable>
|
||||||
|
{currentEditRobot.device_sn || currentEditRobot.serialNumber}
|
||||||
|
</Typography.Text>
|
||||||
|
</div>
|
||||||
|
<div style={{ marginBottom: 16 }}>
|
||||||
|
<Typography.Text strong>设备类型:</Typography.Text>
|
||||||
|
<Typography.Text>{currentEditRobot.productName || '未知'}</Typography.Text>
|
||||||
|
</div>
|
||||||
|
<div style={{ marginBottom: 8 }}>
|
||||||
|
<Typography.Text strong>设备别名 <span style={{ color: 'red' }}>*</span></Typography.Text>
|
||||||
|
</div>
|
||||||
|
<Input
|
||||||
|
value={editAliasInput}
|
||||||
|
onChange={e => setEditAliasInput(e.target.value)}
|
||||||
|
placeholder="请输入自定义设备别名"
|
||||||
|
maxLength={30}
|
||||||
|
allowClear
|
||||||
|
/>
|
||||||
|
<div style={{ marginTop: 8, fontSize: 12, color: '#999' }}>
|
||||||
|
别名用于设备列表、控制面板展示,便于快速区分设备
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
{/*原有视频放大弹窗*/}
|
||||||
|
{/*<Modal title="视频预览" open={!!zoomedVideo} onCancel={() => setZoomedVideo(null)} footer={null} width={1000} centered bodyStyle={{ padding: 0, height: 600, background: '#000' }} destroyOnClose>
|
||||||
|
{zoomedVideo && <DroneLivePlayer streamData={zoomedVideo} videoMode="LARGE" />}
|
||||||
|
</Modal>*/}
|
||||||
|
|
||||||
|
|
||||||
</Content>
|
</Content>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user