diff --git a/src/components/PlanDetail.vue b/src/components/PlanDetail.vue
index b65298e6..0ac2d60f 100644
--- a/src/components/PlanDetail.vue
+++ b/src/components/PlanDetail.vue
@@ -21,7 +21,7 @@
保存
- 取消
+ 取消
编辑内容
@@ -37,7 +37,7 @@
v-if="plan.content_type === 'tasks' || !plan.content_type"
type="primary"
size="small"
- @click="showAddTaskDialog"
+ @click="showTaskEditorDialog()"
>增加子任务
@@ -126,31 +126,31 @@
-
+
-
+
-
+
-
+
-
+
-
+
newTaskForm.parameters = val"
+ :parameters="currentTaskForm.parameters"
+ @update:parameters="val => currentTaskForm.parameters = val"
prop-path="parameters.delay_duration"
:is-editing="true"
/>
@@ -159,8 +159,8 @@
@@ -207,26 +207,26 @@ export default {
loading: false,
error: null,
isEditingContent: false,
- originalPlanState: null,
// Add Sub-plan dialog
addSubPlanDialogVisible: false,
selectedSubPlanId: null,
availablePlans: [],
- // Add Task dialog
- addTaskDialogVisible: false,
- newTaskForm: {
+ // Task Editor dialog (for Add and Edit)
+ taskEditorDialogVisible: false,
+ isEditingTask: false,
+ editingTaskOriginalId: null,
+ currentTaskForm: {
type: 'delay_task',
name: '',
description: '',
- parameters: { delay_duration: 1 }, // Initialize with delay_duration
+ parameters: {},
},
- newTaskRules: {
+ taskFormRules: {
type: [{ required: true, message: '请选择任务类型', trigger: 'change' }],
name: [{ required: true, message: '请输入任务名称', trigger: 'blur' }],
- // Add rule for delay_duration directly here, as it's the default type
- 'parameters.delay_duration': [{ required: true, message: '请输入延时时间', trigger: 'blur' }],
+ // Rule for delay_duration will be added/removed dynamically
},
};
},
@@ -244,20 +244,22 @@ export default {
}
},
},
- 'newTaskForm.type'(newType) {
- // This watch is less critical now since delay_task is the only option
- // but kept for extensibility.
+ 'currentTaskForm.type'(newType) {
+ console.log("PlanDetail: currentTaskForm.type changed to", newType);
if (newType === 'delay_task') {
- this.newTaskRules['parameters.delay_duration'] = this.delayDurationRules;
- if (!this.newTaskForm.parameters.delay_duration) {
- this.newTaskForm.parameters.delay_duration = 1;
+ 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.newTaskRules['parameters.delay_duration']) {
- delete this.newTaskRules['parameters.delay_duration'];
+ if (this.taskFormRules['parameters.delay_duration']) {
+ delete this.taskFormRules['parameters.delay_duration'];
+ console.log("PlanDetail: Removed delay_duration rule.");
}
- if (this.newTaskForm.parameters.delay_duration) {
- delete this.newTaskForm.parameters.delay_duration;
+ if (this.currentTaskForm.parameters.delay_duration !== undefined) {
+ delete this.currentTaskForm.parameters.delay_duration;
+ console.log("PlanDetail: Removed delay_duration parameter.");
}
}
},
@@ -292,7 +294,7 @@ export default {
},
enterEditMode() {
this.isEditingContent = true;
- this.originalPlanState = JSON.parse(JSON.stringify(this.plan));
+ console.log("PlanDetail: Entered edit mode.");
},
async savePlanContent() {
this.updateContentType();
@@ -304,7 +306,6 @@ export default {
execution_type: this.plan.execution_type,
execute_num: this.plan.execute_num,
cron_expression: this.plan.cron_expression,
- content_type: this.plan.content_type,
sub_plan_ids: this.plan.content_type === 'sub_plans'
? this.plan.sub_plans.map(sp => sp.child_plan_id)
: [],
@@ -312,8 +313,7 @@ export default {
? this.plan.tasks.map((task, index) => ({
name: task.name,
description: task.description,
- // Set type to 'waiting' for delay_task
- type: task.type === 'delay_task' ? 'waiting' : task.type,
+ type: task.type,
execution_order: index + 1,
parameters: task.parameters || {},
}))
@@ -323,20 +323,20 @@ export default {
delete submitData.execute_count;
delete submitData.status;
+ console.log("PlanDetail: Submitting data", submitData);
await apiClient.plans.update(this.planId, submitData);
ElMessage.success('计划内容已保存');
this.isEditingContent = false;
- this.originalPlanState = null;
this.fetchPlan();
} catch (error) {
ElMessage.error('保存计划内容失败: ' + (error.message || '未知错误'));
console.error('保存计划内容失败:', error);
}
},
- cancelEdit() {
- this.plan = JSON.parse(JSON.stringify(this.originalPlanState));
+ async cancelEdit() {
+ console.log("PlanDetail: Cancelled edit, re-fetching plan.");
+ await this.fetchPlan();
this.isEditingContent = false;
- this.originalPlanState = null;
ElMessage.info('已取消编辑');
},
@@ -409,54 +409,119 @@ export default {
},
// --- Task related methods ---
- async showAddTaskDialog() {
- if (this.plan.sub_plans.length > 0) {
- try {
- await ElMessageBox.confirm('当前计划包含子计划,添加任务将清空现有子计划。是否继续?', '警告', {
+ showTaskEditorDialog(task = null) {
+ console.log("PlanDetail: Showing task editor dialog.");
+ if (this.plan.sub_plans.length > 0 && !task) {
+ ElMessageBox.confirm('当前计划包含子计划,添加任务将清空现有子计划。是否继续?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
+ }).then(() => {
+ this.plan.sub_plans = [];
+ this.taskEditorDialogVisible = true;
+ this.prepareTaskForm(task);
+ }).catch(() => {
+ // User cancelled
});
- this.plan.sub_plans = [];
- } catch (e) {
return;
- }
}
- this.addTaskDialogVisible = true;
+ this.taskEditorDialogVisible = true;
+ this.prepareTaskForm(task);
},
- confirmAddTask() {
- this.$refs.newTaskFormRef.validate(async (valid) => {
- if (valid) {
- const newTask = {
- id: Date.now(),
- execution_order: this.plan.tasks.length + 1,
- // Map 'delay_task' UI type to 'waiting' backend type
- type: this.newTaskForm.type === 'delay_task' ? 'waiting' : this.newTaskForm.type,
- name: this.newTaskForm.name,
- description: this.newTaskForm.description,
- parameters: this.newTaskForm.parameters,
- };
+ prepareTaskForm(task = null) {
+ // Reset properties of the existing reactive object
+ this.currentTaskForm.type = 'delay_task';
+ this.currentTaskForm.name = '';
+ this.currentTaskForm.description = '';
+ this.currentTaskForm.parameters = {}; // Ensure parameters is reset
- this.plan.tasks.push(newTask);
+ if (task) {
+ 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.name = task.name;
+ this.currentTaskForm.description = task.description;
+ // Deep copy parameters to ensure reactivity for nested changes
+ this.currentTaskForm.parameters = JSON.parse(JSON.stringify(task.parameters || {}));
+ console.log("PlanDetail: Prepared currentTaskForm for editing:", JSON.parse(JSON.stringify(this.currentTaskForm)));
+ } else {
+ this.isEditingTask = false;
+ this.editingTaskOriginalId = null;
+ // Properties are already reset above for new task mode
+ 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
+ if (this.taskFormRules['parameters.delay_duration']) {
+ delete this.taskFormRules['parameters.delay_duration'];
+ }
+ // Apply rules based on current type
+ if (this.currentTaskForm.type === 'delay_task') {
+ this.taskFormRules['parameters.delay_duration'] = this.delayDurationRules;
+ }
+ console.log("PlanDetail: Updated taskFormRules:", JSON.parse(JSON.stringify(this.taskFormRules)));
+ },
+ confirmTaskEdit() {
+ console.log("PlanDetail: confirmTaskEdit called. currentTaskForm before validation:", JSON.parse(JSON.stringify(this.currentTaskForm)));
+ this.$refs.taskFormRef.validate(async (valid) => {
+ console.log("PlanDetail: Form validation result:", valid);
+ if (valid) {
+ if (this.isEditingTask) {
+ // 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;
+ ElMessage.success(`子任务 "${this.currentTaskForm.name}" 已更新`);
+ } else {
+ ElMessage.error('未找到要编辑的任务');
+ }
+ } else {
+ // Add a new task
+ const newTask = {
+ id: Date.now(),
+ execution_order: this.plan.tasks.length + 1,
+ type: this.currentTaskForm.type === 'delay_task' ? 'waiting' : this.currentTaskForm.type,
+ name: this.currentTaskForm.name,
+ description: this.currentTaskForm.description,
+ parameters: this.currentTaskForm.parameters,
+ };
+ this.plan.tasks.push(newTask);
+ ElMessage.success(`子任务 "${newTask.name}" 已添加`);
+ }
this.updateContentType();
- ElMessage.success(`子任务 "${newTask.name}" 已添加`);
- this.addTaskDialogVisible = false;
- this.resetAddTaskDialog();
+ this.taskEditorDialogVisible = false;
+ this.resetTaskEditorDialog();
}
});
},
- resetAddTaskDialog() {
- this.$refs.newTaskFormRef.resetFields();
- this.newTaskForm = {
- type: 'delay_task',
- name: '',
- description: '',
- parameters: { delay_duration: 1 }, // Reset with default delay_duration
- };
+ resetTaskEditorDialog() {
+ console.log("PlanDetail: Resetting task editor dialog.");
+ this.$refs.taskFormRef.resetFields();
+ this.isEditingTask = false;
+ this.editingTaskOriginalId = null;
+ // Manually reset properties to ensure clean state for next use
+ this.currentTaskForm.type = 'delay_task';
+ this.currentTaskForm.name = '';
+ this.currentTaskForm.description = '';
+ this.currentTaskForm.parameters = {};
+ console.log("PlanDetail: currentTaskForm after full reset:", JSON.parse(JSON.stringify(this.currentTaskForm)));
+ this.updateTaskFormRules();
},
- editTask(task) {
- ElMessage.info('编辑任务功能正在开发中');
- console.log('编辑任务:', task);
+ editTask(task) {
+ console.log('PlanDetail: Calling showTaskEditorDialog for editing task:', task);
+ this.showTaskEditorDialog(task);
},
deleteTask(taskToDelete) {
ElMessageBox.confirm(`确认删除任务 "${taskToDelete.name}" 吗?`, '提示', {