修改枚举
This commit is contained in:
@@ -65,9 +65,9 @@
|
||||
placement="top"
|
||||
>
|
||||
<el-card>
|
||||
<h5>{{ task.name }} ({{ task.type === 'waiting' ? '延时任务' : '未知任务' }})</h5>
|
||||
<h5>{{ task.name }} ({{ task.type === TaskType.WAITING ? '延时任务' : '未知任务' }})</h5>
|
||||
<p>{{ task.description }}</p>
|
||||
<p v-if="task.type === 'waiting' && task.parameters?.delay_duration">
|
||||
<p v-if="task.type === TaskType.WAITING && task.parameters?.delay_duration">
|
||||
延时: {{ task.parameters.delay_duration }} 秒
|
||||
</p>
|
||||
<el-button-group v-if="isEditingContent">
|
||||
@@ -155,7 +155,7 @@
|
||||
<el-select v-model="currentTaskForm.type" placeholder="请选择任务类型" style="width: 100%;"
|
||||
:disabled="isEditingTask || plan.plan_type === '系统任务'">
|
||||
<!-- Only Delay Task for now -->
|
||||
<el-option label="延时任务" value="delay_task"></el-option>
|
||||
<el-option label="延时任务" :value="TaskType.WAITING"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="任务名称" prop="name">
|
||||
@@ -167,7 +167,7 @@
|
||||
:disabled="plan.plan_type === '系统任务'"></el-input>
|
||||
</el-form-item>
|
||||
<!-- Dynamic task component for specific parameters -->
|
||||
<template v-if="currentTaskForm.type === 'delay_task'">
|
||||
<template v-if="currentTaskForm.type === TaskType.WAITING">
|
||||
<DelayTaskEditor
|
||||
:parameters="currentTaskForm.parameters"
|
||||
@update:parameters="val => currentTaskForm.parameters = val"
|
||||
@@ -193,6 +193,7 @@ import apiClient from '../api/index.js';
|
||||
import {ElMessage, ElMessageBox} from 'element-plus';
|
||||
import {ArrowDown} from '@element-plus/icons-vue';
|
||||
import DelayTaskEditor from './tasks/DelayTask.vue';
|
||||
import { PlanTypeFilter, TaskType } from '../enums.js';
|
||||
|
||||
export default {
|
||||
name: 'PlanDetail',
|
||||
@@ -239,7 +240,7 @@ export default {
|
||||
isEditingTask: false,
|
||||
editingTaskOriginalId: null,
|
||||
currentTaskForm: {
|
||||
type: 'delay_task',
|
||||
type: TaskType.WAITING,
|
||||
name: '',
|
||||
description: '',
|
||||
parameters: {},
|
||||
@@ -249,6 +250,7 @@ export default {
|
||||
name: [{required: true, message: '请输入任务名称', trigger: 'blur'}],
|
||||
// Rule for delay_duration will be added/removed dynamically
|
||||
},
|
||||
TaskType,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -267,7 +269,7 @@ export default {
|
||||
},
|
||||
'currentTaskForm.type'(newType) {
|
||||
console.log("PlanDetail: currentTaskForm.type changed to", newType);
|
||||
if (newType === 'delay_task') {
|
||||
if (newType === TaskType.WAITING) {
|
||||
this.taskFormRules['parameters.delay_duration'] = this.delayDurationRules;
|
||||
} else {
|
||||
if (this.taskFormRules['parameters.delay_duration']) {
|
||||
@@ -376,7 +378,7 @@ export default {
|
||||
},
|
||||
async fetchAvailablePlans() {
|
||||
try {
|
||||
const response = await apiClient.plans.getPlans({plan_type: '自定义任务', page: 1, page_size: 1000});
|
||||
const response = await apiClient.plans.getPlans({plan_type: PlanTypeFilter.CUSTOM, page: 1, page_size: 1000});
|
||||
this.availablePlans = response.data.plans.filter(p =>
|
||||
p.id !== this.planId
|
||||
);
|
||||
@@ -447,7 +449,7 @@ export default {
|
||||
},
|
||||
prepareTaskForm(task = null) {
|
||||
// Reset properties of the existing reactive object
|
||||
this.currentTaskForm.type = 'delay_task';
|
||||
this.currentTaskForm.type = TaskType.WAITING;
|
||||
this.currentTaskForm.name = '';
|
||||
this.currentTaskForm.description = '';
|
||||
|
||||
@@ -455,7 +457,7 @@ export default {
|
||||
this.isEditingTask = true;
|
||||
this.editingTaskOriginalId = task.id;
|
||||
// Update properties of the existing reactive object
|
||||
this.currentTaskForm.type = task.type === 'waiting' ? 'delay_task' : task.type; // Convert backend type to UI type
|
||||
this.currentTaskForm.type = task.type === TaskType.WAITING ? TaskType.WAITING : task.type; // Convert backend type to UI type
|
||||
this.currentTaskForm.name = task.name;
|
||||
this.currentTaskForm.description = task.description;
|
||||
// Deep copy parameters to ensure reactivity for nested changes
|
||||
@@ -477,7 +479,7 @@ export default {
|
||||
delete this.taskFormRules['parameters.delay_duration'];
|
||||
}
|
||||
// Apply rules based on current type
|
||||
if (this.currentTaskForm.type === 'delay_task') {
|
||||
if (this.currentTaskForm.type === TaskType.WAITING) {
|
||||
this.taskFormRules['parameters.delay_duration'] = this.delayDurationRules;
|
||||
}
|
||||
console.log("PlanDetail: Updated taskFormRules:", JSON.parse(JSON.stringify(this.taskFormRules)));
|
||||
@@ -496,7 +498,7 @@ export default {
|
||||
...this.plan.tasks[index], // Keep existing properties
|
||||
name: this.currentTaskForm.name,
|
||||
description: this.currentTaskForm.description,
|
||||
type: this.currentTaskForm.type === 'delay_task' ? 'waiting' : this.currentTaskForm.type,
|
||||
type: this.currentTaskForm.type,
|
||||
parameters: {...this.currentTaskForm.parameters}, // Deep copy parameters to ensure new reference
|
||||
};
|
||||
this.plan.tasks.splice(index, 1, updatedTask); // Replace the old task with the new one
|
||||
@@ -509,7 +511,7 @@ export default {
|
||||
const newTask = {
|
||||
id: Date.now(),
|
||||
execution_order: this.plan.tasks.length + 1,
|
||||
type: this.currentTaskForm.type === 'delay_task' ? 'waiting' : this.currentTaskForm.type,
|
||||
type: this.currentTaskForm.type,
|
||||
name: this.currentTaskForm.name,
|
||||
description: this.currentTaskForm.description,
|
||||
parameters: {...this.currentTaskForm.parameters}, // Deep copy parameters to ensure new reference
|
||||
@@ -529,7 +531,7 @@ export default {
|
||||
this.isEditingTask = false;
|
||||
this.editingTaskOriginalId = null;
|
||||
// Manually reset properties to ensure clean state for next use
|
||||
this.currentTaskForm.type = 'delay_task';
|
||||
this.currentTaskForm.type = TaskType.WAITING;
|
||||
this.currentTaskForm.name = '';
|
||||
this.currentTaskForm.description = '';
|
||||
this.currentTaskForm.parameters = {};
|
||||
|
||||
Reference in New Issue
Block a user