From 1fb5145e1c794ed1a3c6e3fdee01d391263451df Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Sat, 14 Oct 2023 17:34:17 +0800
Subject: [PATCH] 重复定时、连续执行

---
 src/components/task/CreatePlan.vue |  110 +++++++++++++++++++++++++++++++-----------------------
 1 files changed, 63 insertions(+), 47 deletions(-)

diff --git a/src/components/task/CreatePlan.vue b/src/components/task/CreatePlan.vue
index ea8424d..2e97739 100644
--- a/src/components/task/CreatePlan.vue
+++ b/src/components/task/CreatePlan.vue
@@ -112,18 +112,18 @@
         <!-- 执行时间 (重复定时)-->
         <div v-if="planBody.task_type === TaskType.Repeat">
           <div class="execute-time-arr-item">
-          <a-form-item
-              v-for="(item, index) in planBody.executeTimeRepeatArr"
-              :key="item.index"
-              :label="index === 0 ? '执行时间' : ''"
-              :name="item.index+'repValue'"
-              :labelCol="{ span: 23 }"
-              :rules="[{
+            <a-form-item
+                v-for="(item, index) in planBody.executeTimeRepeatArr"
+                :key="item.index"
+                :label="index === 0 ? '执行时间' : ''"
+                :name="item.index+'repValue'"
+                :labelCol="{ span: 23 }"
+                :rules="[{
                 required: true,
                 trigger: ['change','blur'],
                 validator: validateRepeatExecuteTime
               }]"
-          >
+            >
               <a-time-picker v-model:value="item.value" @change="onRepeatChange(item)" format="HH:mm"/>
               <a-button @click="addTime" type="default" shape="circle" :size="componentOptions.size">
                 <template #icon>
@@ -135,7 +135,7 @@
                   <MinusCircleOutlined/>
                 </template>
               </a-button>
-          </a-form-item>
+            </a-form-item>
           </div>
         </div>
 
@@ -157,11 +157,13 @@
             <div class="execute-time-arr-continuous-item">
               <div class="time-select">
                 <div class="time-item">
-                  <a-time-picker style="width: 100px;" v-model:value="item.value[0]" @change="onContinuousChange(item)" format="HH:mm"/>
+                  <a-time-picker style="width: 100px;" v-model:value="item.value[0]" @change="onContinuousChange(item)"
+                                 format="HH:mm"/>
                 </div>
                 <div style="color: white">-</div>
                 <div class="time-item">
-                  <a-time-picker style="width: 100px;" v-model:value="item.value[1]" @change="onContinuousChange(item)" format="HH:mm"/>
+                  <a-time-picker style="width: 100px;" v-model:value="item.value[1]" @change="onContinuousChange(item)"
+                                 format="HH:mm"/>
                 </div>
               </div>
               <div class="btn-group">
@@ -182,8 +184,8 @@
 
         <!-- 任务开始执行的电量-->
         <a-form-item label="任务开始执行的电量" v-if=" planBody.task_type === TaskType.Continuous"
-                     name="battery_capacity" :labelCol="{ span: 23 }">
-          <a-input style="background: black;" v-model:value="planBody.battery_capacity"/>
+                     name="min_battery_capacity" :labelCol="{ span: 23 }">
+          <a-input style="background: black;" v-model:value="planBody.min_battery_capacity"/>
         </a-form-item>
 
         <!-- 重复频率-->
@@ -281,32 +283,32 @@
 </template>
 
 <script lang="ts" setup>
-import { computed, onMounted, onUnmounted, reactive, ref, toRaw, UnwrapRef } from 'vue'
+import { computed, reactive, ref } from 'vue'
 import {
-  CloseOutlined,
-  RocketOutlined,
   CameraFilled,
-  UserOutlined,
+  CloseOutlined,
+  MinusCircleOutlined,
   PlusCircleOutlined,
-  MinusCircleOutlined
+  RocketOutlined,
+  UserOutlined
 } from '@ant-design/icons-vue'
 import { ELocalStorageKey, ERouterName } from '/@/types'
 import { useMyStore } from '/@/store'
-import { WaylineType, WaylineFile } from '/@/types/wayline'
+import { WaylineFile } from '/@/types/wayline'
 import { Device, EDeviceType } from '/@/types/device'
-import { createPlan, CreatePlan } from '/@/api/wayline'
+import { createPlan, CreatePlan, createPlanCondition } from '/@/api/wayline'
 import { getRoot } from '/@/root'
 import {
-  TaskType,
-  OutOfControlActionOptions,
-  OutOfControlAction,
-  TaskTypeOptions,
-  FrequencyTypeOptions,
   FrequencyType,
-  RepeatRuleTypeOptions,
+  FrequencyTypeOptions,
+  OutOfControlAction,
+  OutOfControlActionOptions,
   RepeatRuleType,
-  WhichWeekOptions,
-  WhichDayOptions
+  RepeatRuleTypeOptions,
+  TaskType,
+  TaskTypeOptions,
+  WhichDayOptions,
+  WhichWeekOptions
 } from '/@/types/task'
 import moment, { Moment } from 'moment'
 import { RuleObject } from 'ant-design-vue/es/form/interface'
@@ -433,16 +435,16 @@
       },
     }
   ],
-  battery_capacity: [
+  min_battery_capacity: [
     {
       validator: async (rule: RuleObject, value: string) => {
         if (!/^[0-9]{1,}$/.test(value)) {
-          planBody.battery_capacity = ''
+          planBody.min_battery_capacity = ''
           throw new Error('最小执行电量不能为空')
         } else if (value < 50) {
-          planBody.battery_capacity = 50
-        } else if (value > 100) {
-          planBody.battery_capacity = 100
+          planBody.min_battery_capacity = 50
+        } else if (value > 90) {
+          planBody.min_battery_capacity = 90
         }
       },
       trigger: 'blur'
@@ -475,19 +477,19 @@
 }
 
 function validateRepeatExecuteTime (rule: RuleObject, value: any) {
-  console.log('验证值', rule)
   if (!value) {
     return Promise.reject(new Error('请选择执行时间'))
+  } else {
+    return Promise.resolve()
   }
 }
 
 function onRepeatChange (item: any) {
   planBody[`${item.index}repValue`] = item.value
-  console.log('表单:', planBody)
 }
+
 function onContinuousChange (item: any) {
   planBody[`${item.index}conValue`] = item.value
-  console.log('表单:', planBody)
 }
 
 // 重复定时添加执行时间
@@ -536,8 +538,6 @@
         createPlanBody.task_periods = []
         // 执行时间
         planBody.executeTimeRepeatArr.forEach(item => {
-          console.log(item, '------')
-
           createPlanBody.task_periods.push([moment(item.value).unix()])
         })
 
@@ -553,7 +553,6 @@
         } else if (planBody.rep_fre_type === FrequencyType.week) {
           createPlanBody.rep_rule_val = repeatFrequencyValueWeek.value
         }
-        console.log(createPlanBody, '*******************')
 
         break
       case TaskType.Continuous:
@@ -586,14 +585,31 @@
       createPlanBody.wayline_type = wayline.value.template_types[0]
     }
 
-    // getFlyTimeList(createPlanBody)
-    disabled.value = false
-    createPlan(workspaceId, createPlanBody)
-      .then(res => {
-        disabled.value = false
-      }).finally(() => {
-        closePlan()
-      })
+    createPlanBody.execute_start_time_arr = getFlyTimeList(createPlanBody)
+
+    console.log('createPlanBody', createPlanBody)
+
+    if (planBody.task_type === TaskType.Immediate || planBody.task_type === TaskType.Timed) {
+      createPlan(workspaceId, createPlanBody)
+        .then(res => {
+          disabled.value = false
+        }).finally(() => {
+          closePlan()
+        })
+    } else {
+      if (planBody.task_type === TaskType.Repeat) {
+        createPlanBody.task_type = 1
+      } else if (planBody.task_type === TaskType.Continuous) {
+        createPlanBody.task_type = 2
+      }
+
+      createPlanCondition(workspaceId, createPlanBody)
+        .then(res => {
+          disabled.value = false
+        }).finally(() => {
+          closePlan()
+        })
+    }
   }).catch((e: any) => {
     console.log('validate err', e)
   })

--
Gitblit v1.9.3