执行恢复任务接口接入 机器人状态显示 完善数据
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user