修复设置延时任务时时间永远为1

This commit is contained in:
2025-09-23 22:08:43 +08:00
parent a1bc980d75
commit e5c2d38559
2 changed files with 14 additions and 19 deletions

View File

@@ -248,10 +248,6 @@ export default {
console.log("PlanDetail: currentTaskForm.type changed to", newType);
if (newType === 'delay_task') {
this.taskFormRules['parameters.delay_duration'] = this.delayDurationRules;
if (this.currentTaskForm.parameters.delay_duration === undefined) {
this.currentTaskForm.parameters.delay_duration = 1;
console.log("PlanDetail: Initialized currentTaskForm.parameters.delay_duration to", this.currentTaskForm.parameters.delay_duration);
}
} else {
if (this.taskFormRules['parameters.delay_duration']) {
delete this.taskFormRules['parameters.delay_duration'];
@@ -433,7 +429,6 @@ export default {
this.currentTaskForm.type = 'delay_task';
this.currentTaskForm.name = '';
this.currentTaskForm.description = '';
this.currentTaskForm.parameters = {}; // Ensure parameters is reset
if (task) {
this.isEditingTask = true;
@@ -448,15 +443,12 @@ export default {
} else {
this.isEditingTask = false;
this.editingTaskOriginalId = null;
// Properties are already reset above for new task mode
// For new tasks, ensure delay_duration is reactive from start
this.currentTaskForm.parameters = { delay_duration: null };
console.log("PlanDetail: Prepared currentTaskForm for adding:", JSON.parse(JSON.stringify(this.currentTaskForm)));
}
// Manually trigger watch for type to ensure rules and default parameters are set
this.updateTaskFormRules();
// Also, ensure delay_duration is initialized if it's a delay_task
if (this.currentTaskForm.type === 'delay_task' && this.currentTaskForm.parameters.delay_duration === undefined) {
this.currentTaskForm.parameters.delay_duration = 1;
}
},
updateTaskFormRules() {
// Clear existing dynamic rules
@@ -478,11 +470,15 @@ export default {
// Find and update the existing task
const index = this.plan.tasks.findIndex(t => t.id === this.editingTaskOriginalId);
if (index !== -1) {
// Update properties of the existing task
this.plan.tasks[index].name = this.currentTaskForm.name;
this.plan.tasks[index].description = this.currentTaskForm.description;
this.plan.tasks[index].type = this.currentTaskForm.type === 'delay_task' ? 'waiting' : this.currentTaskForm.type;
this.plan.tasks[index].parameters = this.currentTaskForm.parameters;
// Create a new task object to ensure reactivity
const updatedTask = {
...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,
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
ElMessage.success(`子任务 "${this.currentTaskForm.name}" 已更新`);
} else {
ElMessage.error('未找到要编辑的任务');
@@ -495,9 +491,9 @@ export default {
type: this.currentTaskForm.type === 'delay_task' ? 'waiting' : this.currentTaskForm.type,
name: this.currentTaskForm.name,
description: this.currentTaskForm.description,
parameters: this.currentTaskForm.parameters,
parameters: { ...this.currentTaskForm.parameters }, // Deep copy parameters to ensure new reference
};
this.plan.tasks.push(newTask);
this.plan.tasks = [...this.plan.tasks, newTask]; // Create a new array reference
ElMessage.success(`子任务 "${newTask.name}" 已添加`);
}
this.updateContentType();

View File

@@ -13,7 +13,6 @@
<el-input-number
:model-value="delayDuration"
@update:model-value="updateDelayDuration"
:min="1"
placeholder="请输入延时时间"
style="width: 100%;"
></el-input-number>
@@ -44,7 +43,7 @@ export default {
emits: ["update:parameters"],
computed: {
delayDuration() { // Renamed from delaySeconds
return this.parameters?.delay_duration || 1;
return this.parameters?.delay_duration;
},
},
methods: {