执行恢复任务接口接入 机器人状态显示 完善数据

This commit is contained in:
mmc
2026-06-03 13:25:48 +08:00
parent 24d69db0ec
commit 26f05c97bc
3 changed files with 535 additions and 89 deletions

View File

@@ -425,7 +425,7 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
name: d.deviceAlias || d.deviceName || d.callsign || '未知设备',
type: d.productName || '未知类型',
status: d.onlineStatus === 1 ? '在线' : '离线',
mode: d.status === 4 ? '待命' : '作业中',
mode: d.feStatus == 1 ? '作业中' : d.feStatus == 2 ? '空闲' : d.mode_code == 0 ? '空闲' : d.mode_code == 1 ? '现场调试' : d.mode_code == 2 ? '远程调试' : d.mode_code == 3 ? '固件升级中' : '作业中',
capacity_percent: d.capacity_percent || 100,
position: d.position || '站内',
task: d.status === 4 ? '待命' : '作业中',
@@ -551,19 +551,23 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
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';
title: '模式', dataIndex: 'mode', width: 70, render: (text) => {
let color = 'default';
if (text === '作业中') color = 'processing';
if (text === '空闲') color = 'success';
if (text === '空闲中') color = 'success';
if (text === '现场调试') color = 'warning';
if (text === '远程调试') color = 'warning';
if (text === '固件升级中') color = 'error';
return <Tag color={color} style={{ margin: 0 }}>{text}</Tag>;
}
},
{
title: '电量',
dataIndex: 'lastrunning',
dataIndex: 'lastRunningStatus',
width: 70,
render: (lastrunning) => {
const v = lastrunning?.battery || 0;
render: (lastRunningStatus) => {
const v = lastRunningStatus?.battery || 100;
return <Progress
percent={v}
size="small"
@@ -571,8 +575,8 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
/>;
}
}, { title: '位置', dataIndex: 'position', width: 90 },
{ title: '当前任务', dataIndex: 'task', width: 100 },
{ title: '通讯状态', dataIndex: 'comm', width: 70, render: v => <Badge status={v.includes('-') ? 'warning' : 'success'} text={v} /> },
//{ title: '当前任务', dataIndex: 'task', width: 100 },
{ 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> },
]}
dataSource={dynamicScheduleList}
@@ -822,12 +826,12 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
</Col>
<Col span={8}>
<div style={{ padding: '8px 12px', borderRadius: 8, background: '#f8fafc', textAlign: 'center' }}>
<Statistic title={<span style={{ fontSize: 12, color: '#86909C' }}>本次作业耗时</span>} value={45} suffix="min" valueStyle={{ fontSize: 20, fontWeight: 700, color: '#1D2129' }} />
<Statistic title={<span style={{ fontSize: 12, color: '#86909C' }}>累计作业面积</span>} value={45} suffix="min" valueStyle={{ fontSize: 20, fontWeight: 700, color: '#1D2129' }} />
</div>
</Col>
<Col span={8}>
<div style={{ padding: '8px 12px', borderRadius: 8, background: '#f8fafc', textAlign: 'center' }}>
<Statistic title={<span style={{ fontSize: 12, color: '#86909C' }}>预计剩余时间</span>} value={12} suffix="min" valueStyle={{ fontSize: 20, fontWeight: 700, color: '#1D2129' }} />
<Statistic title={<span style={{ fontSize: 12, color: '#86909C' }}>累计作业时长</span>} value={12} suffix="min" valueStyle={{ fontSize: 20, fontWeight: 700, color: '#1D2129' }} />
</div>
</Col>
</Row>

View File

@@ -9,7 +9,8 @@ import {
import {
PlusOutlined, ImportOutlined, NodeIndexOutlined,
SaveOutlined, PlayCircleOutlined, EyeOutlined,
DeleteOutlined
DeleteOutlined,
CloseOutlined
} from '@ant-design/icons';
import {
Car, Navigation, Wind, Thermometer, Droplets, Satellite,
@@ -22,7 +23,12 @@ import {
getPlaneDeviceListAll, saveDeviceTask, getRobotTaskList,
deleteDeviceTask,
getSiteDevice,
excuetRoute
excuetRoute,
cancelRoute,
pauseRoute,
recoverRoute,
getDeviceTastPool,
getSiteDeviceTaskHistory,
} from '../../api/device';
import dayjs from 'dayjs';
import utils from '../../lib/utils';
@@ -32,7 +38,6 @@ import { useSelector } from 'react-redux';
import { RootState } from '@/src/store';
import envConfig from '../../../env';
import DeviceController from './DeviceController';
import { getSiteByOrgId } from '@/src/api/stationManage';
const { Text, Title } = Typography;
const { RangePicker } = DatePicker;
@@ -94,6 +99,26 @@ export default function RobotTaskPage() {
// 当前执行任务的机器人
const [executingRobot, setExecutingRobot] = useState(null);
// 任务池和历史任务数据
const [taskPoolList, setTaskPoolList] = useState([]);
const [taskHistoryList, setTaskHistoryList] = useState([]);
// 当前激活的Tab
const [activeTab, setActiveTab] = useState('task'); // 'task' for 任务列表, 'pool' for 任务池, 'history' for 历史任务
// 任务池和历史任务筛选表单
const [poolFilterForm, setPoolFilterForm] = useState({
taskStatus: null,
robot: null,
planId: null,
});
const [historyFilterForm, setHistoryFilterForm] = useState({
taskStatus: null,
robot: null,
dateRange: null,
});
// 获取数据
const fetchAllData = async () => {
@@ -264,12 +289,134 @@ export default function RobotTaskPage() {
resetFiltersAndRefresh();
};
// 获取任务池数据
const fetchTaskPoolList = async () => {
if (!stationId) return;
try {
const params = {
userId: userInfo?.userId,
siteId: stationId,
orgId: userInfo?.orgId,
};
if (poolFilterForm.taskStatus) {
params.taskStaus = poolFilterForm.taskStatus;
}
if (poolFilterForm.robot?.serialNumber) {
params.deviceId = poolFilterForm.robot.serialNumber;
}
if (poolFilterForm.planId) {
params.planId = poolFilterForm.planId;
}
const res = await getDeviceTastPool(params);
if (res.code === 200) {
setTaskPoolList(res.rows || []);
}
} catch (err) {
console.error('获取任务池失败:', err);
}
};
// 获取历史任务数据
const fetchTaskHistoryList = async () => {
if (!stationId) return;
try {
const params = {
userId: userInfo?.userId,
siteId: stationId,
orgId: userInfo?.orgId,
};
if (historyFilterForm.taskStatus) {
params.taskStaus = historyFilterForm.taskStatus;
}
if (historyFilterForm.robot?.serialNumber) {
params.deviceId = historyFilterForm.robot.serialNumber;
}
if (historyFilterForm.dateRange && historyFilterForm.dateRange.length === 2) {
params.startTime = historyFilterForm.dateRange[0].format('YYYY-MM-DD HH:mm:ss');
params.endTime = historyFilterForm.dateRange[1].format('YYYY-MM-DD HH:mm:ss');
}
const res = await getSiteDeviceTaskHistory(params);
if (res.code === 200) {
setTaskHistoryList(res.data || []);
}
} catch (err) {
console.error('获取历史任务失败:', err);
}
};
// 取消任务
const handleCancelTask = async (task) => {
try {
const params = {
//id: task.id,
deviceId: task.deviceId,
//siteId: stationId,
};
const res = await cancelRoute(params);
if (res.code === 200) {
utils.message.success('任务已取消');
fetchTaskList();
fetchTaskPoolList();
} else {
utils.message.error(res.msg || '取消失败');
}
} catch (err) {
console.error('取消任务失败:', err);
utils.message.error('取消任务异常');
}
};
// 暂停任务
const handlePauseTask = async (task) => {
try {
const params = {
id: task.id,
deviceId: task.deviceId,
siteId: stationId,
};
const res = await pauseRoute(params);
if (res.code === 200) {
utils.message.success('任务已暂停');
fetchTaskList();
fetchTaskPoolList();
} else {
utils.message.error(res.msg || '暂停失败');
}
} catch (err) {
console.error('暂停任务失败:', err);
utils.message.error('暂停任务异常');
}
};
// 恢复任务
const handleRecoverTask = async (task) => {
try {
const params = {
id: task.id,
deviceId: task.deviceId,
siteId: stationId,
};
const res = await recoverRoute(params);
if (res.code === 200) {
utils.message.success('任务已恢复');
fetchTaskList();
fetchTaskPoolList();
} else {
utils.message.error(res.msg || '恢复失败');
}
} catch (err) {
console.error('恢复任务失败:', err);
utils.message.error('恢复任务异常');
}
};
useEffect(() => {
if (stationId) {
fetchRouteList();
fetchTaskList()
}
}, [stationId]);
@@ -280,6 +427,20 @@ export default function RobotTaskPage() {
}
}, [filterForm, stationId]);
// 监听任务池筛选条件变化
useEffect(() => {
if (stationId) {
fetchTaskPoolList();
}
}, [poolFilterForm, stationId]);
// 监听历史任务筛选条件变化
useEffect(() => {
if (stationId) {
fetchTaskHistoryList();
}
}, [historyFilterForm, stationId]);
const taskColumns = [
{
title: '任务名称',
@@ -371,7 +532,8 @@ export default function RobotTaskPage() {
width: 100,
fixed: 'right',
render: (_, record) => (
<Space>
<Space size="small">
<Popconfirm
title="确定要删除该任务吗?"
onConfirm={() => handleDelete(record.id)}
@@ -387,11 +549,124 @@ export default function RobotTaskPage() {
删除
</Button>
</Popconfirm>
</Space>
)
}
];
// 任务池表格列
const taskPoolColumns = [
{
title: '设备',
dataIndex: 'deviceId',
width: 150,
},
{
title: '状态',
dataIndex: 'taskStaus',
width: 100,
render: (status, record) => {
const statusMap = {
'NEW': { color: 'default', text: '新建' },
'EXECUTING': { color: 'processing', text: '执行中' },
'PAUSE': { color: 'warning', text: '暂停中' },
'FINISH': { color: 'success', text: '执行成功' },
'FAILED': { color: 'error', text: '执行失败' }
};
const item = statusMap[status] || { color: 'default', text: '未知' };
return <Tag color={item.color}>{item.text}</Tag>;
}
},
{
title: '创建时间',
dataIndex: 'createTime',
width: 170,
},
{
title: '操作',
width: 50,
fixed: 'right',
render: (_, record) => (
<Space size="small">
{record.taskStaus === 'NEW' && (
<Popconfirm
title="确定要取消该任务吗?"
onConfirm={() => handleCancelTask(record)}
okText="确定"
cancelText="取消"
>
<Button type="text" size="small" danger icon={<CloseOutlined />} // 这里加了取消图标
>取消</Button>
</Popconfirm>
)}
{record.taskStaus === 'EXECUTING' && (
<Popconfirm
title="确定要暂停该任务吗?"
onConfirm={() => handlePauseTask(record)}
okText="确定"
cancelText="取消"
>
<Button type="text" size="small">暂停</Button>
</Popconfirm>
)}
{record.taskStaus === 'PAUSE' && (
<Popconfirm
title="确定要恢复该任务吗?"
onConfirm={() => handleRecoverTask(record)}
okText="确定"
cancelText="取消"
>
<Button type="text" size="small">恢复</Button>
</Popconfirm>
)}
</Space>
)
}
];
// 历史任务表格列
const taskHistoryColumns = [
{
title: '任务名称',
dataIndex: 'planName',
width: 160,
ellipsis: true,
},
{
title: '设备',
dataIndex: 'deviceId',
width: 150,
},
{
title: '状态',
dataIndex: 'taskStaus',
width: 100,
render: (status, record) => {
const statusMap = {
'FINISH': { color: 'success', text: '执行成功' },
'FAILED': { color: 'error', text: '执行失败' },
'CANCELLED': { color: 'default', text: '已取消' }
};
const item = statusMap[status] || { color: 'default', text: '未知' };
return <Tag color={item.color}>{item.text}</Tag>;
}
},
{
title: '开始时间',
dataIndex: 'startTime',
width: 170,
render: t => t ? dayjs(t).format('YYYY-MM-DD HH:mm:ss') : '-'
},
{
title: '结束时间',
dataIndex: 'finishTime',
width: 170,
render: t => t ? dayjs(t).format('YYYY-MM-DD HH:mm:ss') : '-'
}
];
const handleRowClick = (record) => {
if (record.longitude && record.latitude) {
setFocusLocation({
@@ -526,84 +801,218 @@ export default function RobotTaskPage() {
</div>
</Card>
{/* 机器人任务列表 + 右侧 新建任务加号按钮 */}
{/* 机器人任务模块,带Tab切换 */}
<Card
title={
<div className="flex justify-between w-full items-center">
<span style={{ fontSize: 14, fontWeight: 700 }}>机器人任务列表</span>
<Space size={8}>
<RangePicker
size="small"
format="YYYY-MM-DD"
placeholder={['开始日期', '结束日期']}
value={filterForm.dateRange}
onChange={(dates) => {
setFilterForm(prev => ({ ...prev, dateRange: dates }));
}}
/>
<Select
style={{ width: 150 }}
size="small"
placeholder="状态"
allowClear
options={[
{ label: '新建', value: 'NEW' },
{ label: '执行中', value: 'EXECUTING' },
{ label: '暂停中', value: 'PAUSE' },
{ label: '执行成功', value: 'FINISH' },
{ label: '执行失败', value: 'FAILED' },
]}
value={filterForm.taskStatus}
onChange={(val) => {
setFilterForm(prev => ({ ...prev, taskStatus: val }));
}}
/>
<Select
style={{ width: 150 }}
size="small"
placeholder="全部机器人"
allowClear
options={devices?.map(item => ({
value: item.serialNumber,
label: item.deviceAlias || item.deviceName
}))}
value={filterForm.robot?.serialNumber}
onChange={(val) => {
if (!val) {
setFilterForm(prev => ({ ...prev, robot: null }));
return;
}
const robot = devices.find(i => i.serialNumber === val);
setFilterForm(prev => ({ ...prev, robot: robot }));
}}
/>
{/* 🔥 新建任务按钮(加号) */}
<Tooltip title="创建任务">
<PlusOutlined
style={{ cursor: 'pointer', color: '#165DFF', fontSize: 12, marginLeft: 10 }}
onClick={() => setIsTaskModalOpen(true)}
/>
</Tooltip>
</Space>
</div>
}
size="small"
bordered={false}
bodyStyle={{ padding: 0, display: 'flex', flexDirection: 'column', height: "calc(100% - 40px)", overflow: "auto" }}
style={{ ...cardStyle, maxHeight: "250px", flex: 1, marginBottom: 0 }}
bodyStyle={{ padding: 0, display: 'flex', flexDirection: 'column', height: "calc(100%)", overflow: "auto" }}
style={{ ...cardStyle, maxHeight: "300px", flex: 1, marginBottom: 0 }}
>
<Table
<Tabs
activeKey={activeTab}
onChange={setActiveTab}
size="small"
rowKey="id"
columns={taskColumns}
dataSource={taskList}
pagination={false}
onRow={(record) => ({
onClick: () => handleRowClick(record),
style: { cursor: 'pointer' }
})}
style={{ padding: '0 12px' }}
items={[
{
key: 'task',
label: '任务列表',
},
{
key: 'pool',
label: '任务池',
},
{
key: 'history',
label: '历史任务',
}
]}
tabBarExtraContent={
<Tooltip title="创建任务">
<PlusOutlined
style={{ cursor: 'pointer', color: '#165DFF', fontSize: 14 }}
onClick={() => setIsTaskModalOpen(true)}
/>
</Tooltip>
}
/>
<div style={{ padding: '0 12px 12px', flex: 1, overflow: 'auto' }}>
{/* 任务列表Tab */}
{activeTab === 'task' && (
<>
<div style={{ marginBottom: 8, display: 'flex', gap: 8, alignItems: 'center' }}>
<RangePicker
size="small"
format="YYYY-MM-DD"
placeholder={['开始日期', '结束日期']}
value={filterForm.dateRange}
onChange={(dates) => {
setFilterForm(prev => ({ ...prev, dateRange: dates }));
}}
/>
<Select
style={{ width: 120 }}
size="small"
placeholder="状态"
allowClear
options={[
{ label: '新建', value: 'NEW' },
{ label: '执行中', value: 'EXECUTING' },
{ label: '暂停中', value: 'PAUSE' },
{ label: '执行成功', value: 'FINISH' },
{ label: '执行失败', value: 'FAILED' },
]}
value={filterForm.taskStatus}
onChange={(val) => {
setFilterForm(prev => ({ ...prev, taskStatus: val }));
}}
/>
<Select
style={{ width: 140 }}
size="small"
placeholder="全部机器人"
allowClear
options={devices?.map(item => ({
value: item.serialNumber,
label: item.deviceAlias || item.deviceName
}))}
value={filterForm.robot?.serialNumber}
onChange={(val) => {
if (!val) {
setFilterForm(prev => ({ ...prev, robot: null }));
return;
}
const robot = devices.find(i => i.serialNumber === val);
setFilterForm(prev => ({ ...prev, robot: robot }));
}}
/>
</div>
<Table
size="small"
rowKey="id"
columns={taskColumns}
dataSource={taskList}
pagination={false}
scroll={{ x: 1200 }}
onRow={(record) => ({
onClick: () => handleRowClick(record),
style: { cursor: 'pointer' }
})}
/>
</>
)}
{/* 任务池Tab */}
{activeTab === 'pool' && (
<>
<div style={{ marginBottom: 8, display: 'flex', gap: 8, alignItems: 'center' }}>
<Select
style={{ width: 120 }}
size="small"
placeholder="状态"
allowClear
options={[
{ label: '新建', value: 'NEW' },
{ label: '执行中', value: 'EXECUTING' },
{ label: '暂停中', value: 'PAUSE' },
]}
value={poolFilterForm.taskStatus}
onChange={(val) => {
setPoolFilterForm(prev => ({ ...prev, taskStatus: val }));
}}
/>
<Select
style={{ width: 140 }}
size="small"
placeholder="全部机器人"
allowClear
options={devices?.map(item => ({
value: item.serialNumber,
label: item.deviceAlias || item.deviceName
}))}
value={poolFilterForm.robot?.serialNumber}
onChange={(val) => {
if (!val) {
setPoolFilterForm(prev => ({ ...prev, robot: null }));
return;
}
const robot = devices.find(i => i.serialNumber === val);
setPoolFilterForm(prev => ({ ...prev, robot: robot }));
}}
/>
</div>
<Table
size="small"
rowKey="id"
columns={taskPoolColumns}
dataSource={taskPoolList}
pagination={false}
scroll={{ x: 800, y: 150 }}
/>
</>
)}
{/* 历史任务Tab */}
{activeTab === 'history' && (
<>
<div style={{ marginBottom: 8, display: 'flex', gap: 8, alignItems: 'center' }}>
<RangePicker
size="small"
format="YYYY-MM-DD HH:mm:ss"
placeholder={['开始时间', '结束时间']}
value={historyFilterForm.dateRange}
onChange={(dates) => {
setHistoryFilterForm(prev => ({ ...prev, dateRange: dates }));
}}
showTime
/>
<Select
style={{ width: 120 }}
size="small"
placeholder="状态"
allowClear
options={[
{ label: '执行成功', value: 'FINISH' },
{ label: '执行失败', value: 'FAILED' },
{ label: '已取消', value: 'CANCELLED' },
]}
value={historyFilterForm.taskStatus}
onChange={(val) => {
setHistoryFilterForm(prev => ({ ...prev, taskStatus: val }));
}}
/>
<Select
style={{ width: 140 }}
size="small"
placeholder="全部机器人"
allowClear
options={devices?.map(item => ({
value: item.serialNumber,
label: item.deviceAlias || item.deviceName
}))}
value={historyFilterForm.robot?.serialNumber}
onChange={(val) => {
if (!val) {
setHistoryFilterForm(prev => ({ ...prev, robot: null }));
return;
}
const robot = devices.find(i => i.serialNumber === val);
setHistoryFilterForm(prev => ({ ...prev, robot: robot }));
}}
/>
</div>
<Table
size="small"
rowKey="id"
columns={taskHistoryColumns}
dataSource={taskHistoryList}
pagination={false}
scroll={{ x: 800 }}
/>
</>
)}
</div>
</Card>
</Col>