| | |
| | | // 重复规则值 |
| | | 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>> { |
| | |
| | | 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, |
| | |
| | | <!-- 执行时间 (重复定时)--> |
| | | <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> |
| | |
| | | <MinusCircleOutlined/> |
| | | </template> |
| | | </a-button> |
| | | </a-form-item> |
| | | </a-form-item> |
| | | </div> |
| | | </div> |
| | | |
| | |
| | | <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"> |
| | |
| | | |
| | | <!-- 任务开始执行的电量--> |
| | | <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> |
| | | |
| | | <!-- 重复频率--> |
| | |
| | | </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' |
| | |
| | | }, |
| | | } |
| | | ], |
| | | 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' |
| | |
| | | } |
| | | |
| | | 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) |
| | | } |
| | | |
| | | // 重复定时添加执行时间 |
| | |
| | | createPlanBody.task_periods = [] |
| | | // 执行时间 |
| | | planBody.executeTimeRepeatArr.forEach(item => { |
| | | console.log(item, '------') |
| | | |
| | | createPlanBody.task_periods.push([moment(item.value).unix()]) |
| | | }) |
| | | |
| | |
| | | } else if (planBody.rep_fre_type === FrequencyType.week) { |
| | | createPlanBody.rep_rule_val = repeatFrequencyValueWeek.value |
| | | } |
| | | console.log(createPlanBody, '*******************') |
| | | |
| | | break |
| | | case TaskType.Continuous: |
| | |
| | | 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) |
| | | }) |
| | |
| | | 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] }, |
| | | ] |
| | | |
| | | // 频率类型 |
| | |
| | | * @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) { |
| | |
| | | case FrequencyType.month: { |
| | | // 先计算这几个月分别是哪个月 |
| | | const monthList = getYearMonth(startDate, endDate, creatPlan.rep_fre_val) |
| | | console.log('月:', monthList) |
| | | |
| | | if (creatPlan.rep_rule_type === RepeatRuleType.day) { |
| | | // 按日期 |
| | |
| | | }) |
| | | }) |
| | | |
| | | console.log('日期时间:', dateList) |
| | | // 过滤掉不在选择日期内的日期 |
| | | finalDateTimeArr = dateList.filter(date => { |
| | | // 如果该日期的时间大于结束时间,则过滤掉 |
| | |
| | | // 获取每n周的日期 |
| | | const weekDate = gainAllDateBetRange(startDate, endDate, creatPlan.rep_fre_val * 7) |
| | | |
| | | console.log('星期时间:', weekDate) |
| | | // 获取星期 |
| | | const dateList = getDateListOfWeek(weekDate, creatPlan.rep_rule_val) |
| | | |
| | |
| | | case FrequencyType.month: { |
| | | // 先计算这几个月分别是哪个月 |
| | | const monthList = getYearMonth(startDate, endDate, creatPlan.rep_fre_val) |
| | | console.log('月:', monthList) |
| | | |
| | | if (creatPlan.rep_rule_type === RepeatRuleType.day) { |
| | | // 按日期 |
| | |
| | | }) |
| | | }) |
| | | |
| | | console.log('日期时间:', dateList) |
| | | // 过滤掉不在选择日期内的日期 |
| | | finalDateTimeArr = dateList.filter(date => { |
| | | // 如果该日期的时间大于结束时间,则过滤掉 |
| | |
| | | // 获取每n周的日期 |
| | | const weekDate = gainAllDateBetRange(startDate, endDate, creatPlan.rep_fre_val * 7) |
| | | |
| | | console.log('星期时间:', weekDate) |
| | | // 获取星期 |
| | | const dateList = getDateListOfWeek(weekDate, creatPlan.rep_rule_val) |
| | | |
| | |
| | | // 拼接执行时间即可 |
| | | 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) |
| | | }) |
| | |
| | | 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对象 |
| | |
| | | dateArr.push(dateFormat(new Date(time), 'yyyy-MM-dd')) // 将格式化后的时间存入结果数组 |
| | | time += numTime // 每次加n天 |
| | | } |
| | | console.log('每', n, '天的日期', dateArr) |
| | | return dateArr |
| | | } |
| | | |
| | |
| | | * @param date |
| | | */ |
| | | function getDateListOfWeek (dateArr: any[], week: number[]) { |
| | | console.log('获取当前日期的星期数的日期:', dateArr, week) |
| | | const list = [] as any |
| | | dateArr.forEach(dateStr => { |
| | | const date = new Date(dateStr) |
| | |
| | | |
| | | const startTime = startDate.getTime() |
| | | const endTime = endDate.getTime() |
| | | console.log('开始时间结束时间时间戳', startTime, endTime) |
| | | let date = startDate |
| | | |
| | | for (let dateTime = startTime; dateTime <= endTime;) { |