修复设置延时任务时时间永远为1
This commit is contained in:
@@ -248,10 +248,6 @@ export default {
|
|||||||
console.log("PlanDetail: currentTaskForm.type changed to", newType);
|
console.log("PlanDetail: currentTaskForm.type changed to", newType);
|
||||||
if (newType === 'delay_task') {
|
if (newType === 'delay_task') {
|
||||||
this.taskFormRules['parameters.delay_duration'] = this.delayDurationRules;
|
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 {
|
} else {
|
||||||
if (this.taskFormRules['parameters.delay_duration']) {
|
if (this.taskFormRules['parameters.delay_duration']) {
|
||||||
delete this.taskFormRules['parameters.delay_duration'];
|
delete this.taskFormRules['parameters.delay_duration'];
|
||||||
@@ -433,7 +429,6 @@ export default {
|
|||||||
this.currentTaskForm.type = 'delay_task';
|
this.currentTaskForm.type = 'delay_task';
|
||||||
this.currentTaskForm.name = '';
|
this.currentTaskForm.name = '';
|
||||||
this.currentTaskForm.description = '';
|
this.currentTaskForm.description = '';
|
||||||
this.currentTaskForm.parameters = {}; // Ensure parameters is reset
|
|
||||||
|
|
||||||
if (task) {
|
if (task) {
|
||||||
this.isEditingTask = true;
|
this.isEditingTask = true;
|
||||||
@@ -448,15 +443,12 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
this.isEditingTask = false;
|
this.isEditingTask = false;
|
||||||
this.editingTaskOriginalId = null;
|
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)));
|
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
|
// Manually trigger watch for type to ensure rules and default parameters are set
|
||||||
this.updateTaskFormRules();
|
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() {
|
updateTaskFormRules() {
|
||||||
// Clear existing dynamic rules
|
// Clear existing dynamic rules
|
||||||
@@ -478,11 +470,15 @@ export default {
|
|||||||
// Find and update the existing task
|
// Find and update the existing task
|
||||||
const index = this.plan.tasks.findIndex(t => t.id === this.editingTaskOriginalId);
|
const index = this.plan.tasks.findIndex(t => t.id === this.editingTaskOriginalId);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
// Update properties of the existing task
|
// Create a new task object to ensure reactivity
|
||||||
this.plan.tasks[index].name = this.currentTaskForm.name;
|
const updatedTask = {
|
||||||
this.plan.tasks[index].description = this.currentTaskForm.description;
|
...this.plan.tasks[index], // Keep existing properties
|
||||||
this.plan.tasks[index].type = this.currentTaskForm.type === 'delay_task' ? 'waiting' : this.currentTaskForm.type;
|
name: this.currentTaskForm.name,
|
||||||
this.plan.tasks[index].parameters = this.currentTaskForm.parameters;
|
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}" 已更新`);
|
ElMessage.success(`子任务 "${this.currentTaskForm.name}" 已更新`);
|
||||||
} else {
|
} else {
|
||||||
ElMessage.error('未找到要编辑的任务');
|
ElMessage.error('未找到要编辑的任务');
|
||||||
@@ -495,9 +491,9 @@ export default {
|
|||||||
type: this.currentTaskForm.type === 'delay_task' ? 'waiting' : this.currentTaskForm.type,
|
type: this.currentTaskForm.type === 'delay_task' ? 'waiting' : this.currentTaskForm.type,
|
||||||
name: this.currentTaskForm.name,
|
name: this.currentTaskForm.name,
|
||||||
description: this.currentTaskForm.description,
|
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}" 已添加`);
|
ElMessage.success(`子任务 "${newTask.name}" 已添加`);
|
||||||
}
|
}
|
||||||
this.updateContentType();
|
this.updateContentType();
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
<el-input-number
|
<el-input-number
|
||||||
:model-value="delayDuration"
|
:model-value="delayDuration"
|
||||||
@update:model-value="updateDelayDuration"
|
@update:model-value="updateDelayDuration"
|
||||||
:min="1"
|
|
||||||
placeholder="请输入延时时间"
|
placeholder="请输入延时时间"
|
||||||
style="width: 100%;"
|
style="width: 100%;"
|
||||||
></el-input-number>
|
></el-input-number>
|
||||||
@@ -44,7 +43,7 @@ export default {
|
|||||||
emits: ["update:parameters"],
|
emits: ["update:parameters"],
|
||||||
computed: {
|
computed: {
|
||||||
delayDuration() { // Renamed from delaySeconds
|
delayDuration() { // Renamed from delaySeconds
|
||||||
return this.parameters?.delay_duration || 1;
|
return this.parameters?.delay_duration;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|||||||
Reference in New Issue
Block a user