diff --git a/src/components/devices/WayLinePage.tsx b/src/components/devices/WayLinePage.tsx index 6da4044..757e5ab 100644 --- a/src/components/devices/WayLinePage.tsx +++ b/src/components/devices/WayLinePage.tsx @@ -17,7 +17,7 @@ import { LayoutGrid, Clock, CheckCircle2, AlertCircle, Zap, Waves, Calendar, User, TrendingUp, Maximize2, Play, Square, X, MapPin, RotateCw } from 'lucide-react'; -import { getsinglePlan, getsinglePlanTrack, updateFlightTaskStatus, postFlightCommmand, getWayLine } from '@/api/device'; +import { getsinglePlan, getsinglePlanTrack, updateFlightTaskStatus, postFlightCommmand, getWayLine, createWaylineTask } from '@/api/device'; import dayjs from 'dayjs'; import utils from '@/lib/utils'; import CesiumMap from '../Map'; @@ -59,13 +59,11 @@ export default function WayLinePage({ planedevices }) { const [createTaskModal, setCreateTaskModal] = useState(false); const [waylineUuid, setWaylineUuid] = useState(''); const [waylineList, setWaylineList] = useState([]); // 航线列表 - const [beginTime, setBeginTime] = useState(null); - const [endTime, setEndTime] = useState(null); const [taskForm, setTaskForm] = useState({ name: '', sn: '', landing_dock_sn: '', - rth_altitude: 0, + rth_altitude: 100, rth_mode: 'optimal', wayline_precision_type: 'gps', resumable_status: 'auto', @@ -74,12 +72,15 @@ export default function WayLinePage({ planedevices }) { repeat_type: 'nonrepeating', repeat_option: { interval: 1 }, time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone, + begin_at: null, + end_at: null, + recurring_task_start_time_list: [], }); const fetchWaylineList = async () => { try { const res = await getWayLine(); - if (res?.code == 0) { + if (res?.code == 200 || res?.code == 0) { const _list = res?.data?.list.map(item => { return { ...item, @@ -103,7 +104,7 @@ export default function WayLinePage({ planedevices }) { name: '', sn: listDrone?.gateway_sn || '', landing_dock_sn: '', - rth_altitude: 0, + rth_altitude: 100, rth_mode: 'optimal', wayline_precision_type: 'gps', resumable_status: 'auto', @@ -112,9 +113,10 @@ export default function WayLinePage({ planedevices }) { repeat_type: 'nonrepeating', repeat_option: { interval: 1 }, time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone, + begin_at: null, + end_at: null, + recurring_task_start_time_list: [], }); - setBeginTime(null); - setEndTime(null); }; // 创建任务提交 @@ -125,12 +127,25 @@ export default function WayLinePage({ planedevices }) { } setLoading(true); try { - // 这里替换成你的创建任务接口 - utils.message.success('创建任务成功'); - resetModals(); - getListTask(); // 刷新列表 + const payload = { + ...taskForm, + wayline_uuid: waylineUuid, + // 如果是立即任务,begin_at 为 null 或当前时间戳 + begin_at: taskForm.task_type === 'immediate' ? null : (taskForm.begin_at ? dayjs(taskForm.begin_at).unix() : null), + end_at: taskForm.end_at ? dayjs(taskForm.end_at).unix() : null, + recurring_task_start_time_list: taskForm.recurring_task_start_time_list.map(t => dayjs(t).unix()), + }; + + const res: any = await createWaylineTask(payload); + if (res.code === 200 || res.code === 0) { + utils.message.success('创建任务成功'); + resetModals(); + getListTask(); // 刷新列表 + } else { + utils.message.error(res.msg || '创建失败'); + } } catch (err) { - utils.message.error('创建失败'); + utils.message.error('创建异常'); } finally { setLoading(false); } @@ -1001,12 +1016,85 @@ export default function WayLinePage({ planedevices }) { onChange={(val) => setTaskForm({ ...taskForm, task_type: val })} options={[ { label: '立即任务', value: 'immediate' }, + { label: '单次定时任务', value: 'timed' }, + { label: '重复任务', value: 'recurring' }, + { label: '连续任务', value: 'continuous' }, ]} style={{ width: '100%' }} /> + {/* 根据任务类型显示不同字段 */} + {(taskForm.task_type === 'timed' || taskForm.task_type === 'recurring' || taskForm.task_type === 'continuous') && ( +