卡片样式
This commit is contained in:
@@ -22,11 +22,12 @@ 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 } from '@/api/device.ts';
|
||||
import { getUAVState, getSiteDevice, getSiteUAVList, getsinglePlan, getRobotTaskList } from '@/api/device.ts';
|
||||
import dayjs from 'dayjs';
|
||||
import { useMqtt } from '@/hooks/useMqtt';
|
||||
import envConfig from '../../../env';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { RootState } from '@/store';
|
||||
import envConfig from '../../../env';
|
||||
|
||||
const { Content } = Layout;
|
||||
const { Text, Title } = Typography;
|
||||
@@ -62,6 +63,7 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
|
||||
const [devices, setDevices] = useState([]);
|
||||
const [planedevices, setPlaneDevices] = useState([]);
|
||||
const [devicesAll, setDevicesAll] = useState([]);
|
||||
const [taskStats, setTaskStats] = useState({ completed: 12, total: 15 });
|
||||
|
||||
// 获取数据
|
||||
const fetchAllData = async () => {
|
||||
@@ -107,6 +109,72 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
|
||||
useEffect(() => {
|
||||
fetchAllData();
|
||||
}, [userInfo, stationId]);
|
||||
useEffect(() => {
|
||||
fetchTaskStats();
|
||||
}, [devicesAll.length]);
|
||||
|
||||
// 获取今日任务统计
|
||||
const fetchTaskStats = async () => {
|
||||
if (!stationId) return;
|
||||
|
||||
try {
|
||||
const todayStart = dayjs().startOf('day').unix();
|
||||
const todayEnd = dayjs().endOf('day').unix();
|
||||
|
||||
let completedCount = 0;
|
||||
let totalCount = 0;
|
||||
|
||||
// 1. 获取无人机今日任务
|
||||
if (planedevices?.length > 0) {
|
||||
try {
|
||||
const sns = planedevices.map(item => item.gateway_sn);
|
||||
const droneRes = await getsinglePlan({ sns, beginAt: todayStart, endAt: todayEnd });
|
||||
if (droneRes?.code === 200 && droneRes.data) {
|
||||
let droneTasks = [];
|
||||
Object.values(droneRes.data).forEach((item: any) => {
|
||||
if (item.list) droneTasks = droneTasks.concat(item.list);
|
||||
});
|
||||
totalCount += droneTasks.length;
|
||||
// 计算无人机完成的任务
|
||||
completedCount += droneTasks.filter(t =>
|
||||
['success', 'completed', 'executed', 'FINISH', 'COMPLETED'].includes(t.status)
|
||||
).length;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取无人机任务统计失败', err);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 获取机器人今日任务
|
||||
try {
|
||||
const robotRes = await getRobotTaskList({ siteId: String(stationId) });
|
||||
if (robotRes?.code == 200 && robotRes.data) {
|
||||
const todayRobotTasks = robotRes.data.filter((t: any) => {
|
||||
// 简单判断是今日的任务
|
||||
if (t.createTime) {
|
||||
const taskTime = dayjs(t.createTime);
|
||||
return taskTime.isAfter(dayjs().startOf('day')) && taskTime.isBefore(dayjs().endOf('day'));
|
||||
}
|
||||
return true; // 默认都算
|
||||
});
|
||||
totalCount += todayRobotTasks.length;
|
||||
// 计算机器人完成的任务
|
||||
completedCount += todayRobotTasks.filter((t: any) =>
|
||||
['FINISH', 'FINISHED', 'COMPLETED', 'completed'].includes(t.taskStaus)
|
||||
).length;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取机器人任务统计失败', err);
|
||||
}
|
||||
|
||||
|
||||
setTaskStats({ completed: completedCount, total: totalCount });
|
||||
|
||||
} catch (err) {
|
||||
console.error('获取任务统计失败', err);
|
||||
setTaskStats({ completed: 12, total: 15 });
|
||||
}
|
||||
};
|
||||
|
||||
// 当前选中设备(切换时才变)
|
||||
const selectedDevice = useMemo(() => {
|
||||
@@ -278,14 +346,21 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
|
||||
const totalMowers = devicesAll?.filter(d => d.productName?.includes('割草机')).length || 0;
|
||||
const activeMowers = devicesAll?.filter(d => d.productName?.includes('割草机') && d.onlineStatus === 1).length || 0;
|
||||
const washDroneStandby = planedevices?.filter(d => d.productName?.includes('清洗') && d.onlineStatus === 1).length || 0;
|
||||
|
||||
|
||||
|
||||
// 今日任务执行统计
|
||||
const completedTasks = taskStats.completed;
|
||||
const totalTasks = taskStats.total;
|
||||
const completionRate = totalTasks > 0 ? Math.round((completedTasks / totalTasks) * 100) : 0;
|
||||
|
||||
return [
|
||||
{ title: '无人机机场状态', icon: <EnvironmentOutlined />, value: `${onlineDrones} / ${totalDrones}`, sub: `可调度 ${onlineDrones} 架`, color: '#1890ff' },
|
||||
{ title: '机器人', icon: <BranchesOutlined />, value: `${totalMowers} 台`, sub: `作业中 ${activeMowers}`, color: '#13c2c2' },
|
||||
{ title: '无人机', icon: <CloudOutlined />, value: `${totalDrones} 架`, sub: `待命 ${washDroneStandby}`, color: '#eb2f96' },
|
||||
{ title: '设备平均电量', icon: <ThunderboltOutlined />, value: '86%', sub: '', color: '#52c41a' },
|
||||
{ title: '今日任务执行', icon: <CheckCircleOutlined />, value: '12 / 15', sub: '完成率 80%', color: '#2f54eb' },
|
||||
{ title: '今日任务执行', icon: <CheckCircleOutlined />, value: `${completedTasks} / ${totalTasks}`, sub: `完成率 ${completionRate}%`, color: '#2f54eb' },
|
||||
];
|
||||
}, [devicesAll, planedevices]);
|
||||
}, [devicesAll, planedevices, persistentDroneData, uavState, taskStats]);
|
||||
|
||||
// 设备调度列表
|
||||
const dynamicScheduleList = useMemo(() => {
|
||||
@@ -343,7 +418,7 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
|
||||
<Content style={{ margin: '0 8', }}>
|
||||
<Row gutter={[8, 8]} style={{ marginBottom: 12, flexWrap: 'wrap' }}>
|
||||
{dynamicTopCards.map((card, idx) => (
|
||||
<Col key={idx} style={{ minWidth: '160px', flex: '1 0 auto' }}>
|
||||
<Col key={idx} style={{ minWidth: '360px', flex: '0 0 auto' }}>
|
||||
<Card bordered={false} style={{ borderRadius: 8, boxShadow: '0 2px 8px rgba(0,0,0,0.05)', height: 90 }} bodyStyle={{ padding: '12px', height: '100%' }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 10, height: '100%' }}>
|
||||
<div style={{ width: 40, height: 40, borderRadius: 8, background: `${card.color}15`, color: card.color, display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 'clamp(14px, 1.2vw, 18px)', flexShrink: 0 }}>
|
||||
|
||||
@@ -532,7 +532,6 @@ export default function WayLinePage({ onRefresh }) {
|
||||
if (item.list) combinedList = combinedList.concat(item.list);
|
||||
});
|
||||
}
|
||||
console.log('看板任务列表:', combinedList);
|
||||
setBoardTaskList(combinedList);
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user