From 45bb6c748c3734469e5e80648d9d48c7e83fc8a4 Mon Sep 17 00:00:00 2001
From: husq <931347610@qq.com>
Date: Thu, 12 Oct 2023 11:51:59 +0800
Subject: [PATCH] Merge branch 'demo' of http://s16s652780.51mypc.cn:49896/r/yskj/iot_drone_web into demo
---
src/components/task/CreatePlan.vue | 191 ++++++++++++++++++++++++++++++++++-------------
1 files changed, 139 insertions(+), 52 deletions(-)
diff --git a/src/components/task/CreatePlan.vue b/src/components/task/CreatePlan.vue
index b53d588..ea8424d 100644
--- a/src/components/task/CreatePlan.vue
+++ b/src/components/task/CreatePlan.vue
@@ -105,41 +105,26 @@
<a-form-item label="执行日期"
v-if="planBody.task_type === TaskType.Repeat || planBody.task_type === TaskType.Continuous"
name="time_range" :labelCol="{ span: 23 }">
- <a-range-picker v-model:value="planBody.time_range" format="YYYY-MM-DD" placeholder="请选择日期"/>
+ <a-range-picker v-model:value="planBody.time_range" format="YYYY-MM-DD"
+ :placeholder="['开始时间','结束时间']"/>
</a-form-item>
<!-- 执行时间 (重复定时)-->
- <a-form-item label="执行时间" v-if="planBody.task_type === TaskType.Repeat" name="execute_time_arr"
- :labelCol="{ span: 23 }">
- <div class="execute-time-arr-item" v-for="(item,index) in executeTimeRepeatArr" :key="index">
- <a-time-picker v-model:value="item.value" format="HH:mm"/>
- <a-button @click="addTime" type="default" shape="circle" :size="componentOptions.size">
- <template #icon>
- <PlusCircleOutlined/>
- </template>
- </a-button>
-
- <a-button @click="deleteTime(item)" type="default" shape="circle" :size="componentOptions.size">
- <template #icon>
- <MinusCircleOutlined/>
- </template>
- </a-button>
- </div>
- </a-form-item>
-
- <!-- 执行时间 (连续执行)-->
- <a-form-item label="执行时间" v-if="planBody.task_type === TaskType.Continuous" :labelCol="{ span: 23 }">
- <div class="execute-time-arr-continuous-item" v-for="(item,index) in executeTimeContinuousArr" :key="index">
- <div class="time-select">
- <div class="time-item">
- <a-time-picker style="width: 100px;" v-model:value="item.value[0]" 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]" format="HH:mm"/>
- </div>
- </div>
- <div class="btn-group">
+ <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="[{
+ 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>
<PlusCircleOutlined/>
@@ -150,11 +135,52 @@
<MinusCircleOutlined/>
</template>
</a-button>
- </div>
+ </a-form-item>
</div>
- </a-form-item>
+ </div>
- <!-- 重复频率-->
+ <!-- 执行时间 (连续执行)-->
+ <div v-if="planBody.task_type === TaskType.Continuous">
+ <a-form-item
+ v-for="(item, index) in planBody.executeTimeContinuousArr"
+ :key="item.index"
+ :label="index === 0 ? '执行时间' : ''"
+ :name="item.index+'conValue'"
+ :labelCol="{ span: 23 }"
+ :rules="{
+ required: true,
+ trigger: ['change', 'blur'],
+ validator: validateContinuousExecuteTime
+ }"
+ >
+
+ <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"/>
+ </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"/>
+ </div>
+ </div>
+ <div class="btn-group">
+ <a-button @click="addTime" type="default" shape="circle" :size="componentOptions.size">
+ <template #icon>
+ <PlusCircleOutlined/>
+ </template>
+ </a-button>
+ <a-button @click="deleteTime(item)" type="default" shape="circle" :size="componentOptions.size">
+ <template #icon>
+ <MinusCircleOutlined/>
+ </template>
+ </a-button>
+ </div>
+ </div>
+ </a-form-item>
+ </div>
+
+ <!-- 任务开始执行的电量-->
<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"/>
@@ -163,6 +189,7 @@
<!-- 重复频率-->
<a-form-item label="重复频率"
v-if="planBody.task_type === TaskType.Repeat || planBody.task_type === TaskType.Continuous"
+ name="rep_fre_val"
:labelCol="{ span: 23 }">
<div class="rep-fre-item">
<div>每</div>
@@ -186,7 +213,7 @@
</a-button>
</a-form-item>
- <!-- 重复频率-->
+ <!-- 重复规则-->
<a-form-item label="重复规则"
v-if="(planBody.task_type === TaskType.Repeat || planBody.task_type === TaskType.Continuous) && planBody.rep_fre_type === FrequencyType.month"
:labelCol="{ span: 23 }">
@@ -318,14 +345,35 @@
rep_fre_val: 1,
rep_fre_type: 3,
rep_rule_type: 1,
+
+ executeTimeContinuousArr: [{ index: 1, value: [] }],
+ executeTimeRepeatArr: [{ index: 1, value: '' }]
})
-const executeTimeRepeatArr = ref([
- { index: 1, value: '' }
-])
-const executeTimeContinuousArr = ref([
- { index: 1, value: [] }
-])
+watch(
+ planBody.executeTimeRepeatArr,
+ (newVal) => {
+ if (newVal.length) {
+ newVal.forEach(item => {
+ planBody[`${item.index}repValue`] = item.value
+ })
+ }
+ },
+ { deep: true, immediate: true }
+)
+
+watch(
+ planBody.executeTimeContinuousArr,
+ (newVal) => {
+ if (newVal.length) {
+ newVal.forEach(item => {
+ planBody[`${item.index}conValue`] = item.value
+ })
+ }
+ },
+ { deep: true, immediate: true }
+)
+
// 重复规则为按星期时
const repeatRuleValueWeek = ref([1, 1])
// 重复规则为按日期时
@@ -401,19 +449,58 @@
}
],
out_of_control_action: [{ required: true, message: '请选择航线飞行中失联' }],
+ rep_fre_val: [
+ {
+ validator: async (rule: RuleObject, value: string) => {
+ if (!/^[0-9]{1,}$/.test(value)) {
+ planBody.rep_fre_val = ''
+ throw new Error('重复频率不能为空')
+ }
+ },
+ trigger: ['blur', 'change']
+ }
+ ]
+}
+
+function validateContinuousExecuteTime (rule: RuleObject, value: Moment[]) {
+ if (!value[0]) {
+ return Promise.reject(new Error('请选择执行时间'))
+ } else if (value.length < 2) {
+ return Promise.reject(new Error('请选择执行结束时间'))
+ } else if (value[1].isBefore(value[0])) {
+ return Promise.reject(new Error('执行结束时间不能小于执行开始时间'))
+ } else {
+ return Promise.resolve()
+ }
+}
+
+function validateRepeatExecuteTime (rule: RuleObject, value: any) {
+ console.log('验证值', rule)
+ if (!value) {
+ return Promise.reject(new Error('请选择执行时间'))
+ }
+}
+
+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)
}
// 重复定时添加执行时间
function addTime () {
if (planBody.task_type === TaskType.Repeat) {
- const index = executeTimeRepeatArr.value[executeTimeRepeatArr.value.length - 1].index
- executeTimeRepeatArr.value.push({
+ const index = planBody.executeTimeRepeatArr[planBody.executeTimeRepeatArr.length - 1].index
+ planBody.executeTimeRepeatArr.push({
index: index + 1,
value: ''
})
} else if (planBody.task_type === TaskType.Continuous) {
- const index = executeTimeContinuousArr.value[executeTimeContinuousArr.value.length - 1].index
- executeTimeContinuousArr.value.push({
+ const index = planBody.executeTimeContinuousArr[planBody.executeTimeContinuousArr.length - 1].index
+ planBody.executeTimeContinuousArr.push({
index: index + 1,
value: []
})
@@ -423,9 +510,9 @@
// 删除执行时间
function deleteTime (item: any) {
if (planBody.task_type === TaskType.Repeat) {
- executeTimeRepeatArr.value = executeTimeRepeatArr.value.filter(e => e.index !== item.index)
+ planBody.executeTimeRepeatArr = planBody.executeTimeRepeatArr.filter(e => e.index !== item.index)
} else if (planBody.task_type === TaskType.Continuous) {
- executeTimeContinuousArr.value = executeTimeContinuousArr.value.filter(e => e.index !== item.index)
+ planBody.executeTimeContinuousArr = planBody.executeTimeContinuousArr.filter(e => e.index !== item.index)
}
}
@@ -448,7 +535,7 @@
createPlanBody.task_days = [moment(planBody.time_range[0]).unix(), moment(planBody.time_range[1]).unix()]
createPlanBody.task_periods = []
// 执行时间
- executeTimeRepeatArr.value.forEach(item => {
+ planBody.executeTimeRepeatArr.forEach(item => {
console.log(item, '------')
createPlanBody.task_periods.push([moment(item.value).unix()])
@@ -470,7 +557,7 @@
break
case TaskType.Continuous:
- createPlanBody.task_type = 2
+ // createPlanBody.task_type = 2
createPlanBody.task_days = [moment(planBody.time_range[0]).unix(), moment(planBody.time_range[1]).unix()]
if (planBody.rep_fre_type === FrequencyType.month) {
@@ -487,7 +574,7 @@
}
createPlanBody.task_periods = []
// 执行时间
- executeTimeContinuousArr.value.forEach(item => {
+ planBody.executeTimeContinuousArr.forEach(item => {
createPlanBody.task_periods.push([moment(item.value[0]).unix(), moment(item.value[1]).unix()])
})
@@ -500,7 +587,7 @@
}
// getFlyTimeList(createPlanBody)
-
+ disabled.value = false
createPlan(workspaceId, createPlanBody)
.then(res => {
disabled.value = false
--
Gitblit v1.9.3