From 1fb5145e1c794ed1a3c6e3fdee01d391263451df Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Sat, 14 Oct 2023 17:34:17 +0800
Subject: [PATCH] 重复定时、连续执行
---
src/types/task.ts | 4
src/components/task/CreatePlan.vue | 110 +++++++++++++++++++++---------------
src/api/wayline.ts | 12 ++++
src/utils/jobTime.ts | 45 ++++++--------
4 files changed, 96 insertions(+), 75 deletions(-)
diff --git a/src/api/wayline.ts b/src/api/wayline.ts
index b6170f4..e4f7e25 100644
--- a/src/api/wayline.ts
+++ b/src/api/wayline.ts
@@ -84,6 +84,10 @@
// 重复规则值
rep_rule_val?:[]
rep_rule_type?:number
+
+ min_battery_capacity?:number
+ //执行开始时间
+ execute_start_time_arr:number[][]
}
// 新增计划
export const createPlan = async function (workspaceId: string, plan: CreatePlan): Promise<IWorkspaceResponse<any>> {
@@ -92,6 +96,14 @@
return result.data
}
+//新增计划,重复定时和连续执行走这个逻辑
+export const createPlanCondition = async function (workspaceId: string, plan: CreatePlan): Promise<IWorkspaceResponse<any>> {
+ const url = `${HTTP_PREFIX}/workspaces/${workspaceId}/flight-tasks-condition`
+ const result = await request.post(url, plan)
+ return result.data
+}
+
+
export interface Task {
job_id: string,
job_name: string,
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)
})
diff --git a/src/types/task.ts b/src/types/task.ts
index fd0ff1a..4639db0 100644
--- a/src/types/task.ts
+++ b/src/types/task.ts
@@ -18,8 +18,8 @@
export const TaskTypeOptions = [
{ value: TaskType.Immediate, label: TaskTypeMap[TaskType.Immediate] },
{ value: TaskType.Timed, label: TaskTypeMap[TaskType.Timed] },
- // { value: TaskType.Repeat, label: TaskTypeMap[TaskType.Repeat] },
- // { value: TaskType.Continuous, label: TaskTypeMap[TaskType.Continuous] },
+ { value: TaskType.Repeat, label: TaskTypeMap[TaskType.Repeat] },
+ { value: TaskType.Continuous, label: TaskTypeMap[TaskType.Continuous] },
]
// 频率类型
diff --git a/src/utils/jobTime.ts b/src/utils/jobTime.ts
index 0d58eed..4387d5d 100644
--- a/src/utils/jobTime.ts
+++ b/src/utils/jobTime.ts
@@ -8,11 +8,9 @@
* @param creatPlan
*/
export function getFlyTimeList (creatPlan: CreatePlan) {
- console.log('表单', creatPlan)
const startDate = moment.unix(creatPlan.task_days[0]).toDate()
const endDate = moment.unix(creatPlan.task_days[1]).toDate()
- console.log('开始时间:', startDate, '结束时间:', endDate)
let finalDateTimeArr = [] as any
if (creatPlan.task_type === TaskType.Repeat) {
@@ -24,7 +22,6 @@
case FrequencyType.month: {
// 先计算这几个月分别是哪个月
const monthList = getYearMonth(startDate, endDate, creatPlan.rep_fre_val)
- console.log('月:', monthList)
if (creatPlan.rep_rule_type === RepeatRuleType.day) {
// 按日期
@@ -46,7 +43,6 @@
})
})
- console.log('日期时间:', dateList)
// 过滤掉不在选择日期内的日期
finalDateTimeArr = dateList.filter(date => {
// 如果该日期的时间大于结束时间,则过滤掉
@@ -93,7 +89,6 @@
// 获取每n周的日期
const weekDate = gainAllDateBetRange(startDate, endDate, creatPlan.rep_fre_val * 7)
- console.log('星期时间:', weekDate)
// 获取星期
const dateList = getDateListOfWeek(weekDate, creatPlan.rep_rule_val)
@@ -127,7 +122,6 @@
case FrequencyType.month: {
// 先计算这几个月分别是哪个月
const monthList = getYearMonth(startDate, endDate, creatPlan.rep_fre_val)
- console.log('月:', monthList)
if (creatPlan.rep_rule_type === RepeatRuleType.day) {
// 按日期
@@ -152,7 +146,6 @@
})
})
- console.log('日期时间:', dateList)
// 过滤掉不在选择日期内的日期
finalDateTimeArr = dateList.filter(date => {
// 如果该日期的时间大于结束时间,则过滤掉
@@ -202,7 +195,6 @@
// 获取每n周的日期
const weekDate = gainAllDateBetRange(startDate, endDate, creatPlan.rep_fre_val * 7)
- console.log('星期时间:', weekDate)
// 获取星期
const dateList = getDateListOfWeek(weekDate, creatPlan.rep_rule_val)
@@ -226,11 +218,8 @@
// 拼接执行时间即可
dateList.forEach(date => {
creatPlan.task_periods?.forEach(timearr => {
- console.log(timearr,"***************************")
timearr.forEach(time=>{
- console.log("time:",time)
const timeStr = moment.unix(time).format('HH:mm')
- console.log("timeStr:",timeStr)
finalDateTimeArr.push(date + ' ' + timeStr)
})
@@ -246,25 +235,32 @@
var tempDateTimeArr = []
if (creatPlan.task_type === TaskType.Repeat) {
tempDateTimeArr = finalDateTimeArr.map(dateTime=>[dateTime])
-
}else if (creatPlan.task_type === TaskType.Continuous){
-
+ for (let i = 0; i < finalDateTimeArr.length; i=i+2) {
+ tempDateTimeArr.push([finalDateTimeArr[i],finalDateTimeArr[i+1]])
+ }
}
-
-
-
-
-
-
- // 对finalDateTimeArr进行时间过滤,筛选掉过去时间和无效时间
- const futureDateTimeArr = finalDateTimeArr.filter(dateStr => {
- return new Date(dateStr).getTime() >= new Date().getTime()
+ // 对tempDateTimeArr进行时间过滤,筛选掉过去时间和无效时间
+ const futureDateTimeArr = tempDateTimeArr.filter(dateArr => {
+ return new Date(dateArr[0]).getTime() >= new Date().getTime()
})
+
console.log('未来时间:', futureDateTimeArr)
- return futureDateTimeArr
+ const futureDateTimeUnixArr = [] as any
+ futureDateTimeArr.forEach(dateArr=>{
+ const list = [] as any
+
+ dateArr.forEach(dateTimeStr=>{
+ const timestamp = moment(dateTimeStr).unix()
+ list.push(timestamp)
+ })
+ futureDateTimeUnixArr.push(list)
+ })
+ console.log('未来时间unix:', futureDateTimeUnixArr)
+ return futureDateTimeUnixArr
}
// 获取一个日期范围内的每n天的日期,入参为Date对象
@@ -278,7 +274,6 @@
dateArr.push(dateFormat(new Date(time), 'yyyy-MM-dd')) // 将格式化后的时间存入结果数组
time += numTime // 每次加n天
}
- console.log('每', n, '天的日期', dateArr)
return dateArr
}
@@ -287,7 +282,6 @@
* @param date
*/
function getDateListOfWeek (dateArr: any[], week: number[]) {
- console.log('获取当前日期的星期数的日期:', dateArr, week)
const list = [] as any
dateArr.forEach(dateStr => {
const date = new Date(dateStr)
@@ -315,7 +309,6 @@
const startTime = startDate.getTime()
const endTime = endDate.getTime()
- console.log('开始时间结束时间时间戳', startTime, endTime)
let date = startDate
for (let dateTime = startTime; dateTime <= endTime;) {
--
Gitblit v1.9.3