From 324c6a88f4997823ef1f4c7f10854d0b73b252bb Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Fri, 12 Jun 2026 17:34:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=AB=E5=90=8D=E6=88=90?= =?UTF-8?q?=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/devices/DeviceOverviewPage.tsx | 120 +++++++++++++++++- 1 file changed, 114 insertions(+), 6 deletions(-) diff --git a/src/components/devices/DeviceOverviewPage.tsx b/src/components/devices/DeviceOverviewPage.tsx index b3a98e9..8f0a0ec 100644 --- a/src/components/devices/DeviceOverviewPage.tsx +++ b/src/components/devices/DeviceOverviewPage.tsx @@ -2,7 +2,8 @@ import React, { useState, useEffect, useRef, useMemo } from 'react'; import { Layout, Card, Row, Col, Statistic, Tag, Button, Table, Typography, Space, Progress, Badge, Timeline, message, - Select, Modal, Space as AntSpace + Select, Modal, Space as AntSpace, + Input } from 'antd'; import { EnvironmentOutlined, RobotOutlined, BranchesOutlined, @@ -22,12 +23,13 @@ import AgoraTextTest from '../AgoraRtc.tsx'; import { useWebRTCPlayer } from '../useWebRTCStream.tsx'; import VideoPlayer from '../VideoPlayer.tsx.tsx'; 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 { useMqtt } from '@/hooks/useMqtt'; import { useSelector } from 'react-redux'; import { RootState } from '@/store'; import envConfig from '../../../env'; +import utils from '@/lib/utils.ts'; const { Content } = Layout; const { Text, Title } = Typography; @@ -66,6 +68,12 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS const [taskStats, setTaskStats] = useState({ completed: 12, total: 15 }); 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 () => { 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(() => { fetchAllData(); }, [stationId]); @@ -585,8 +637,23 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS }, { title: '位置', dataIndex: 'position', width: 90 }, //{ title: '当前任务', dataIndex: 'task', width: 100 }, { title: '通讯状态', dataIndex: 'comm', width: 100, render: v => }, - { title: '操作', key: 'action', width: 80, render: () =>