在线面板数据优化 创建并执行成功

This commit is contained in:
mmc
2026-06-03 11:06:44 +08:00
parent 1a87d659f4
commit 24d69db0ec
5 changed files with 73 additions and 24 deletions

View File

@@ -8,6 +8,7 @@ export function getDeviceListApi(data) {
}); });
} }
export function getPlaneDeviceList(params) { export function getPlaneDeviceList(params) {
return request({ return request({
url: '/iot/UAV/getUAVList', url: '/iot/UAV/getUAVList',
@@ -16,6 +17,9 @@ export function getPlaneDeviceList(params) {
}) })
} }
//modeStatistics{"0":"空闲中","1":"现场调试","2":"远程调试","3":"固件升级中","4":"作业中"}
export function getSiteUAVList(siteId) { export function getSiteUAVList(siteId) {
return request({ return request({
url: '/iot/UAV/getSiteUAVList', url: '/iot/UAV/getSiteUAVList',

View File

@@ -70,9 +70,10 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
if (!stationId) return; if (!stationId) return;
try { try {
console.log('开始请求设备数据,stationId:', userInfo);
// 1. 同时发请求 // 1. 同时发请求
const [deviceRes, planeRes] = await Promise.all([ const [deviceRes, planeRes] = await Promise.all([
getSiteDevice({ siteId: stationId, pageSize: 9999, pageNum: 1 }), getSiteDevice({ siteId: stationId, pageSize: 9999, pageNum: 1, orgId: userInfo.orgId }),
getSiteUAVList(stationId), getSiteUAVList(stationId),
]); ]);
@@ -343,14 +344,19 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
); );
// 顶部统计卡片 // 顶部统计卡片
//feStatus; 1任务中 / 2空闲
const dynamicTopCards = useMemo(() => { const dynamicTopCards = useMemo(() => {
const totalDrones = planedevices?.length || 0; const totalDrones = planedevices?.length || 0;
const onlineDrones = planedevices?.filter(d => d.onlineStatus === 1).length || 0; const onlineDrones = planedevices?.filter(d => d.onlineStatus === 1).length || 0;
const totalRobots = devicesAll?.filter(d => d.productName?.includes('巡检')).length || 0; const totalRobots = devicesAll?.filter(d => d.productName?.includes('巡检')).length || 0;
const activeRobots = devicesAll?.filter(d => d.productName?.includes('巡检') && d.onlineStatus === 1).length || 0;
//key 0 有任务 1 无任务
const activeRobots = 0;
const totalMowers = devicesAll?.filter(d => d.productName?.includes('割草机')).length || 0; const totalMowers = devicesAll?.filter(d => d.productName?.includes('割草机')).length || 0;
const activeMowers = devicesAll?.filter(d => d.productName?.includes('割草机') && d.onlineStatus === 1).length || 0; const activeMowers = devices?.filter(d => d.feStatus == 1).length || 0; // 作业中状态数量
const washDroneStandby = planedevices?.filter(d => d.productName?.includes('清洗') && d.onlineStatus === 1).length || 0; const washDroneStandby = planedevices?.[0]?.modeStatistics?.["0"] || 0;
//key 设备状态:{"0":"空闲中","1":"现场调试","2":"远程调试","3":"固件升级中","4":"作业中"}
@@ -380,7 +386,7 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
title: '除草机器人', title: '除草机器人',
icon: <CarOutlined style={{ color: '#722ED1', fontSize: 24 }} />, icon: <CarOutlined style={{ color: '#722ED1', fontSize: 24 }} />,
value: `${totalMowers} 台`, value: `${totalMowers} 台`,
sub: `作业中 ${activeMowers}`, sub: `任务中 ${activeMowers}`,
color: '#722ED1', color: '#722ED1',
iconBg: '#F9F0FF' iconBg: '#F9F0FF'
}, },
@@ -414,6 +420,7 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
// 设备调度列表 // 设备调度列表
const dynamicScheduleList = useMemo(() => { const dynamicScheduleList = useMemo(() => {
return devicesAll?.map((d, index) => ({ return devicesAll?.map((d, index) => ({
...d,
id: d.deviceId || index, id: d.deviceId || index,
name: d.deviceAlias || d.deviceName || d.callsign || '未知设备', name: d.deviceAlias || d.deviceName || d.callsign || '未知设备',
type: d.productName || '未知类型', type: d.productName || '未知类型',
@@ -422,7 +429,8 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
capacity_percent: d.capacity_percent || 100, capacity_percent: d.capacity_percent || 100,
position: d.position || '站内', position: d.position || '站内',
task: d.status === 4 ? '待命' : '作业中', task: d.status === 4 ? '待命' : '作业中',
comm: d.rssi ? `${d.rssi}dBm` : '良好' comm: d.rssi ? `${d.rssi}dBm` : '良好',
})) || []; })) || [];
}, [devicesAll]); }, [devicesAll]);
@@ -533,10 +541,36 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
columns={[ columns={[
{ title: '装备名称', dataIndex: 'name', width: 140 }, { title: '装备名称', dataIndex: 'name', width: 140 },
{ title: '类型', dataIndex: 'type', width: 90 }, { title: '类型', dataIndex: 'type', width: 90 },
{ title: '当前状态', dataIndex: 'status', width: 70, render: s => <Tag color={s === '作业中' || s === '在线' ? 'success' : 'default'} style={{ margin: 0 }}>{s}</Tag> }, {
{ title: '模式', dataIndex: 'mode', width: 70 }, title: '当前状态',
{ title: '电量', dataIndex: 'capacity_percent', width: 70, render: v => <Progress percent={v} size="small" status={v < 40 ? 'exception' : 'active'} /> }, dataIndex: 'onlineStatus',
{ title: '位置', dataIndex: 'position', width: 90 }, width: 70,
render: (s) => {
const text = s === 1 ? '在线' : '离线';
const color = s === 1 ? 'success' : 'default';
return <Tag color={color} style={{ margin: 0 }}>{text}</Tag>;
}
}, {
title: '模式', dataIndex: 'feStatus', width: 70, render: (feStatus) => {
console.log('feStatus:', feStatus);
const text = feStatus == 1 ? '任务中' : feStatus == 2 ? '空闲' : '离线';
const color = feStatus === 1 ? 'processing' : feStatus === 2 ? 'success' : 'default';
return <Tag color={color} style={{ margin: 0 }}>{text}</Tag>;
}
},
{
title: '电量',
dataIndex: 'lastrunning',
width: 70,
render: (lastrunning) => {
const v = lastrunning?.battery || 0;
return <Progress
percent={v}
size="small"
status={v < 40 ? 'exception' : 'active'}
/>;
}
}, { title: '位置', dataIndex: 'position', width: 90 },
{ title: '当前任务', dataIndex: 'task', width: 100 }, { title: '当前任务', dataIndex: 'task', width: 100 },
{ title: '通讯状态', dataIndex: 'comm', width: 70, render: v => <Badge status={v.includes('-') ? 'warning' : 'success'} text={v} /> }, { title: '通讯状态', dataIndex: 'comm', width: 70, 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: () => <Space size={4}><Button size="small" type="text" icon={<EditOutlined />} /><Button size="small" type="text" icon={<SettingOutlined />} /></Space> },

View File

@@ -77,7 +77,7 @@ export default function DeviceStatusPage({
try { try {
// 1. 同时发请求 // 1. 同时发请求
const [deviceRes, planeRes] = await Promise.all([ const [deviceRes, planeRes] = await Promise.all([
getSiteDevice({ siteId: stationId, pageSize: 9999, pageNum: 1 }), getSiteDevice({ siteId: stationId, pageSize: 9999, pageNum: 1, orgId: userInfo.orgId }),
getSiteUAVList(stationId), getSiteUAVList(stationId),
]); ]);

View File

@@ -32,6 +32,7 @@ import { useSelector } from 'react-redux';
import { RootState } from '@/src/store'; import { RootState } from '@/src/store';
import envConfig from '../../../env'; import envConfig from '../../../env';
import DeviceController from './DeviceController'; import DeviceController from './DeviceController';
import { getSiteByOrgId } from '@/src/api/stationManage';
const { Text, Title } = Typography; const { Text, Title } = Typography;
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
@@ -39,6 +40,7 @@ const { RangePicker } = DatePicker;
export default function RobotTaskPage() { export default function RobotTaskPage() {
const { userInfo } = useSelector((state: RootState) => state.user); const { userInfo } = useSelector((state: RootState) => state.user);
const { stationId } = useSelector((state: RootState) => state.station); const { stationId } = useSelector((state: RootState) => state.station);
const [excuteStatus, setExcuteStatus] = useState("stop"); //"stop" "running" "pause"
const fontSmall = 'clamp(10px, 0.7vw, 11px)'; const fontSmall = 'clamp(10px, 0.7vw, 11px)';
const fontNormal = 'clamp(12px, 0.75vw, 13px)'; const fontNormal = 'clamp(12px, 0.75vw, 13px)';
@@ -62,10 +64,11 @@ export default function RobotTaskPage() {
const controller = new DeviceController(userInfo, messageApi); const controller = new DeviceController(userInfo, messageApi);
controllerRef.current = controller; controllerRef.current = controller;
return () => { return () => {
controllerRef.current?.destroy(); if (controllerRef.current) {
controllerRef.current.destroy?.();
}
controllerRef.current = null; controllerRef.current = null;
};
}
}, []) }, [])
@@ -97,7 +100,7 @@ export default function RobotTaskPage() {
if (!stationId) return; if (!stationId) return;
try { try {
const deviceRes = await getSiteDevice({ siteId: stationId, pageSize: 9999, pageNum: 1 }); const deviceRes = await getSiteDevice({ siteId: stationId, pageSize: 9999, pageNum: 1, orgId: userInfo.orgId });
const devData = deviceRes?.code === 200 ? (deviceRes.rows || []) : []; const devData = deviceRes?.code === 200 ? (deviceRes.rows || []) : [];
setDevices(devData); setDevices(devData);
} catch (err) { } catch (err) {
@@ -144,7 +147,6 @@ export default function RobotTaskPage() {
} }
}; };
useEffect(() => { useEffect(() => {
console.log('selectedPathWork changed:', selectedPathWork);
try { try {
// 1. 没有数据直接清空 // 1. 没有数据直接清空
@@ -154,7 +156,7 @@ export default function RobotTaskPage() {
} }
// 2. 安全解析 JSON // 2. 安全解析 JSON
const data = JSON.parse(selectedPathWork?.jsonData); const data = selectedPathWork?.jsonData;
const path = data?.path || []; const path = data?.path || [];
// 3. 空路径提示 // 3. 空路径提示
@@ -208,7 +210,7 @@ export default function RobotTaskPage() {
let hasPathPoints = false; let hasPathPoints = false;
try { try {
if (route.jsonData) { if (route.jsonData) {
const data = JSON.parse(route.jsonData); const data = route.jsonData;
hasPathPoints = data.path && data.path.length > 0; hasPathPoints = data.path && data.path.length > 0;
} }
} catch (err) { } catch (err) {
@@ -236,7 +238,8 @@ export default function RobotTaskPage() {
const params = { const params = {
deviceId: selectedRobotForExecute.serialNumber, deviceId: selectedRobotForExecute.serialNumber,
routeId: selectedRouteForExecute.id, routeId: selectedRouteForExecute.id,
siteId: stationId siteId: stationId,
...(userInfo?.orgId ? { orgId: userInfo.orgId } : {}),
}; };
console.log('执行任务参数:', params); console.log('执行任务参数:', params);
@@ -246,8 +249,8 @@ export default function RobotTaskPage() {
utils.message.success('任务执行成功'); utils.message.success('任务执行成功');
setExecuteModalVisible(false); setExecuteModalVisible(false);
setExecutingRobot(selectedRobotForExecute); setExecutingRobot(selectedRobotForExecute);
fetchTaskList(); // 刷新任务列表 //fetchTaskList(); // 刷新任务列表
controllerRef.current?.connect(selectedRobotForExecute); controllerRef.current?.connectDevice(selectedRobotForExecute);
} else { } else {
utils.message.error(res.msg || '任务执行失败'); utils.message.error(res.msg || '任务执行失败');
} }
@@ -414,8 +417,14 @@ export default function RobotTaskPage() {
{ title: '累计作业里程', value: '12.5', unit: 'km', trend: '较昨日 +1.2', trendColor: '#00B42A', icon: <TrendingUp size={22} />, color: '#722ED1' }, { title: '累计作业里程', value: '12.5', unit: 'km', trend: '较昨日 +1.2', trendColor: '#00B42A', icon: <TrendingUp size={22} />, color: '#722ED1' },
{ title: '任务完成率', value: taskList.length ? Math.round((finishList.length / taskList.length) * 100) : 0, unit: '%', trend: '较昨日 +5%', trendColor: '#00B42A', icon: <CheckCircle2 size={22} />, color: '#00B42A' }, { title: '任务完成率', value: taskList.length ? Math.round((finishList.length / taskList.length) * 100) : 0, unit: '%', trend: '较昨日 +5%', trendColor: '#00B42A', icon: <CheckCircle2 size={22} />, color: '#00B42A' },
{ title: '异常告警', value: '2', unit: '次', trend: '较昨日 -1', trendColor: '#00B42A', icon: <AlertCircle size={22} />, color: '#F53F3F' }, { title: '异常告警', value: '2', unit: '次', trend: '较昨日 -1', trendColor: '#00B42A', icon: <AlertCircle size={22} />, color: '#F53F3F' },
{ title: '在线率', value: '98', unit: '%', desc: '良好', icon: <Satellite size={22} />, color: '#165DFF' }, {
]; title: '在线率',
value: `${devices?.length ? Math.round((devices.filter(d => d.onlineStatus == 1).length / devices.length) * 100) : 0}`,
unit: '%',
desc: '良好',
icon: <Satellite size={22} />,
color: '#165DFF'
}];
return ( return (
<div className="normal-spacing" style={{ background: '#f5f7fa', minHeight: '100vh', padding: '0px', paddingTop: 0 }}> <div className="normal-spacing" style={{ background: '#f5f7fa', minHeight: '100vh', padding: '0px', paddingTop: 0 }}>

View File

@@ -20,6 +20,8 @@ export default function DeviceIndexPage() {
const [devices, setDevices] = useState([]); const [devices, setDevices] = useState([]);
const [planedevices, setPlaneDevices] = useState([]); const [planedevices, setPlaneDevices] = useState([]);
const [devicesAll, setDevicesAll] = useState([]); const [devicesAll, setDevicesAll] = useState([]);
const { userInfo } = useSelector((state: RootState) => state.user);
const tabs = [ const tabs = [
{ key: 'overview', label: '装备总览', icon: <AppstoreOutlined /> }, { key: 'overview', label: '装备总览', icon: <AppstoreOutlined /> },
@@ -34,7 +36,7 @@ export default function DeviceIndexPage() {
try { try {
const [deviceRes, planeRes] = await Promise.all([ const [deviceRes, planeRes] = await Promise.all([
getSiteDevice({ siteId: stationId, pageSize: 9999, pageNum: 1 }), getSiteDevice({ siteId: stationId, pageSize: 9999, pageNum: 1, orgId: userInfo.orgId }),
getSiteUAVList(stationId), getSiteUAVList(stationId),
]); ]);