From e5c2d385596f285b98871826c7e07d8026df14d5 Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Tue, 23 Sep 2025 22:08:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E7=BD=AE=E5=BB=B6?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=E6=97=B6=E6=97=B6=E9=97=B4=E6=B0=B8?= =?UTF-8?q?=E8=BF=9C=E4=B8=BA1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/PlanDetail.vue | 30 +++++++++++++----------------- src/components/tasks/DelayTask.vue | 3 +-- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/components/PlanDetail.vue b/src/components/PlanDetail.vue index 0ac2d60f..d02e94c3 100644 --- a/src/components/PlanDetail.vue +++ b/src/components/PlanDetail.vue @@ -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(); diff --git a/src/components/tasks/DelayTask.vue b/src/components/tasks/DelayTask.vue index c075020e..b0a56a55 100644 --- a/src/components/tasks/DelayTask.vue +++ b/src/components/tasks/DelayTask.vue @@ -13,7 +13,6 @@ @@ -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: {