forked from drone/command-center-dashboard

chenyao
2025-04-15 828f2f412b36e03384d62874d3283f05afa7d4ea
src/views/TaskManage/TaskIntermediateContent/AddTask.vue
@@ -17,14 +17,15 @@
                     v-model="taskData"
                     format="YYYY-MM-DD"
                     value-format="YYYY-MM-DD"
                     :disabled-date="disabledDate"
                  />
               </div>
               <div class="item">任务时间:
                  <!-- <el-time-picker
                     v-model="searchForm.execute_time_arr"
                  <el-time-picker
                     v-model="timeSlot"
                     placeholder="选择时间"
                     format="HH:mm"
                     value-format="HH:mm"/> -->
                     value-format="HH:mm"/>
               </div>
               <div class="item">选择航线:
                  <el-select
@@ -97,6 +98,7 @@
// 添加子组件引用
const taskTableRef = ref(null);
const taskData = ref('');
const timeSlot = ref('');
const searchForm = reactive({
   name: '',
   ai_types: [],
@@ -112,6 +114,11 @@
   polygon: [],
});
const isShowAddTask = defineModel('show');
// 禁用当天之前的日期
const disabledDate = (time) => {
  return time.getTime() < Date.now() - 8.64e7; // 86400000 = 24 * 60 * 60 * 1000
};
// 获取航线列表数据
const routeOptions = ref([]);
@@ -191,14 +198,43 @@
    });
    return;
  }
   // 检查任务时间
  if (timeSlot.value) {
    const now = new Date();
    const today = now.toDateString();
    const selectedDate = new Date(taskData.value).toDateString();
    if (today === selectedDate) {
      const [hours, minutes] = timeSlot.value.split(':');
      const selectedTime = new Date();
      selectedTime.setHours(parseInt(hours), parseInt(minutes));
      if (selectedTime < now) {
        ElMessage({
          message: '任务时间不能小于当前时间',
          type: 'warning'
        });
        return;
      }
    }
  }
   if (searchForm.dock_sns.length === 0) {
      ElMessage({
         message: '请选择机场',
         type: 'warning'
      });
      return;
   }
   searchForm.begin_time = `${taskData.value} 00:00:00`;
  searchForm.end_time = `${taskData.value} 23:59:59`;
   searchForm.execute_time_arr = timeSlot.value ? [timeSlot.value] : [];
   createTask(searchForm).then((res) => {
      if (res.data.code === 0) {
         ElMessage.success('任务创建成功');
         // 关闭当前窗口,刷新任务管理列表
         isShowAddTask.value = false;
         // 清除数据
         cancel();
         emit('refresh');
      }
   });
@@ -211,12 +247,13 @@
  searchForm.file_id = '';
  searchForm.begin_time = '';
  searchForm.end_time = '';
  searchForm.execute_time_arr = '';
  timeSlot.value = '';
  searchForm.remark = '';
  searchForm.dock_sns = [];
  rangDate.value = [];
  waylineId.value = '';
  wayLineFile.value = '';
   taskData.value = '';
};
onMounted(() => {