From f0f0d5bdcdda420fde293372f4c20c2cecd70dd6 Mon Sep 17 00:00:00 2001 From: liailing1026 <1815388873@qq.com> Date: Sun, 1 Mar 2026 22:41:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=B8=93=E5=AE=B6=E6=99=BA=E8=83=BD?= =?UTF-8?q?=E4=BD=93=E8=AF=84=E9=80=89=E5=88=86=E7=BB=84=E5=92=8C=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/server.py | 9 +- .../components/DeleteConfirmDialog/index.vue | 4 + .../components/AgentAllocation.vue | 99 +++++++++++++++++-- frontend/src/stores/modules/agents.ts | 10 ++ frontend/src/stores/modules/selection.ts | 11 +++ 5 files changed, 122 insertions(+), 11 deletions(-) diff --git a/backend/server.py b/backend/server.py index fc868cf..970193e 100644 --- a/backend/server.py +++ b/backend/server.py @@ -2508,9 +2508,16 @@ def handle_update_assigned_agents(data): # 更新 confirmed_groups(确认的组合列表) if confirmed_groups: existing_assigned[step_id]["confirmed_groups"] = confirmed_groups + # 清理已删除分组的 agent_combinations 数据 + existing_combinations = existing_assigned[step_id].get("agent_combinations", {}) + new_combinations_keys = {json.dumps(list(group), sort_keys=True) for group in confirmed_groups} + keys_to_remove = [k for k in existing_combinations.keys() if k not in new_combinations_keys] + for key in keys_to_remove: + del existing_combinations[key] + existing_assigned[step_id]["agent_combinations"] = existing_combinations # 更新 agent_combinations(保存 TaskProcess 数据) - if agent_combinations: + elif agent_combinations: # 合并新旧数据 existing_combinations = existing_assigned[step_id].get("agent_combinations", {}) for key, value in agent_combinations.items(): diff --git a/frontend/src/components/DeleteConfirmDialog/index.vue b/frontend/src/components/DeleteConfirmDialog/index.vue index e06eec1..6d8954c 100644 --- a/frontend/src/components/DeleteConfirmDialog/index.vue +++ b/frontend/src/components/DeleteConfirmDialog/index.vue @@ -73,6 +73,10 @@ watch( // 监听对话框显示状态变化 watch(dialogVisible, val => { emit('update:modelValue', val) + // 当对话框关闭时,重置 loading 状态 + if (!val) { + loading.value = false + } }) // 确认删除 diff --git a/frontend/src/layout/components/Main/TaskTemplate/TaskSyllabus/components/AgentAllocation.vue b/frontend/src/layout/components/Main/TaskTemplate/TaskSyllabus/components/AgentAllocation.vue index 0d1643a..e274335 100644 --- a/frontend/src/layout/components/Main/TaskTemplate/TaskSyllabus/components/AgentAllocation.vue +++ b/frontend/src/layout/components/Main/TaskTemplate/TaskSyllabus/components/AgentAllocation.vue @@ -54,6 +54,17 @@ const taskOutlineList = computed(() => { // 选中的任务大纲项 const selectedTaskOutline = ref('') +// 监听 currentTask 变化,自动选中当前步骤 +watch( + () => currentTask.value?.StepName, + (newStepName) => { + if (newStepName) { + selectedTaskOutline.value = newStepName + } + }, + { immediate: true } +) + // 判断任务大纲项是否被选中 const isTaskOutlineSelected = (task: { StepName?: string }) => { return selectedTaskOutline.value === task.StepName @@ -713,6 +724,9 @@ const getHeatmapColor = (score: number) => { const deleteDialogVisible = ref(false) const dimensionToDelete = ref(null) +// 删除分组弹窗相关状态 +const groupToDelete = ref<{ index: number; agents: string[] } | null>(null) + // 删除维度(显示确认对话框) const handleDeleteDimension = (dimension: string, event: Event) => { event.stopPropagation() // 阻止冒泡,避免触发维度选择 @@ -720,6 +734,13 @@ const handleDeleteDimension = (dimension: string, event: Event) => { deleteDialogVisible.value = true } +// 删除分组(显示确认对话框) +const handleDeleteGroup = (groupIndex: number, agents: string[], event: Event) => { + event.stopPropagation() // 阻止冒泡,避免触发分组选择 + groupToDelete.value = { index: groupIndex, agents } + deleteDialogVisible.value = true +} + // 确认删除维度 const confirmDeleteDimension = async () => { if (!dimensionToDelete.value) return @@ -729,8 +750,7 @@ const confirmDeleteDimension = async () => { // 先获取要删除的维度索引(在修改数据之前) const dimensionIndex = scoreDimensions.value.indexOf(dimension) if (dimensionIndex === -1) { - deleteDialogVisible.value = false - dimensionToDelete.value = null + // 维度不存在,不需要删除 return } @@ -794,11 +814,69 @@ const confirmDeleteDimension = async () => { console.error('同步删除数据库维度失败:', error) } } + } - // 关闭对话框并清理状态 - deleteDialogVisible.value = false - dimensionToDelete.value = null -} + // 确认删除分组 + const confirmDeleteGroup = async () => { + if (!groupToDelete.value || !currentTask.value?.Id) return + + const { index, agents: deletedAgents } = groupToDelete.value + const taskId = currentTask.value.Id + + // 从 store 中删除分组 + agentsStore.removeConfirmedAgentGroup(taskId, index) + + // 从 selectionStore 中删除对应的 TaskProcess 数据 + selectionStore.removeAgentTaskProcess(taskId, deletedAgents) + + // 同步到数据库 + const dbTaskId = (window as any).__CURRENT_TASK_ID__ + if (dbTaskId && taskId) { + try { + const updatedGroups = agentsStore.getConfirmedAgentGroups(taskId) + // 获取更新后的所有组合的 TaskProcess 数据 + const agentCombinations: Record = {} + updatedGroups.forEach(group => { + const processData = selectionStore.getAgentTaskProcess(taskId, group) + if (processData) { + const groupKey = selectionStore.getAgentGroupKey(group) + agentCombinations[groupKey] = { + process: processData.process || [], + brief: processData.brief || {} + } + } + }) + await api.updateAssignedAgents({ + task_id: dbTaskId, + step_id: taskId, + agents: [], + confirmed_groups: updatedGroups, + agent_combinations: agentCombinations + }) + } catch (error) { + console.error('❌ 保存删除后的 confirmed_groups 失败:', error) + } + } + + // 如果删除的分组是当前选中的分组,清除选中状态 + if (isAgentGroupSelected(groupToDelete.value.agents)) { + selectedAssignmentGroup.value = [] + selectedAgents.value = new Set() + } + } + + // 统一确认删除处理 + const handleConfirmDelete = async () => { + if (dimensionToDelete.value) { + await confirmDeleteDimension() + } else if (groupToDelete.value) { + await confirmDeleteGroup() + } + // 关闭对话框并清理状态 + deleteDialogVisible.value = false + dimensionToDelete.value = null + groupToDelete.value = null + } diff --git a/frontend/src/stores/modules/agents.ts b/frontend/src/stores/modules/agents.ts index 2aa361c..5616e95 100644 --- a/frontend/src/stores/modules/agents.ts +++ b/frontend/src/stores/modules/agents.ts @@ -292,6 +292,15 @@ export const useAgentsStore = defineStore('agents', () => { confirmedAgentGroupsMap.value.set(taskId, groups) } + // 删除指定任务的某个agent组合 + function removeConfirmedAgentGroup(taskId: string, groupIndex: number) { + const groups = confirmedAgentGroupsMap.value.get(taskId) || [] + if (groupIndex >= 0 && groupIndex < groups.length) { + groups.splice(groupIndex, 1) + confirmedAgentGroupsMap.value.set(taskId, groups) + } + } + const planModificationWindow = ref(false) const planTaskWindow = ref(false) const agentAllocationDialog = ref(false) @@ -645,6 +654,7 @@ export const useAgentsStore = defineStore('agents', () => { clearConfirmedAgentGroups, clearAllConfirmedAgentGroups, setConfirmedAgentGroups, + removeConfirmedAgentGroup, // 停止填充状态 hasStoppedFilling, setHasStoppedFilling, diff --git a/frontend/src/stores/modules/selection.ts b/frontend/src/stores/modules/selection.ts index 33d7e82..7627d62 100644 --- a/frontend/src/stores/modules/selection.ts +++ b/frontend/src/stores/modules/selection.ts @@ -424,6 +424,16 @@ export const useSelectionStore = defineStore('selection', () => { return agentTaskProcessMap.value.get(taskId)?.has(groupKey) || false } + /** + * 删除指定任务的某个 agent 组合的 TaskProcess 数据 + * @param taskId 任务 ID + * @param agents Agent 列表 + */ + function removeAgentTaskProcess(taskId: string, agents: string[]) { + const groupKey = getAgentGroupKey(agents) + agentTaskProcessMap.value.get(taskId)?.delete(groupKey) + } + /** * 清除指定任务的所有 agent 组合 TaskProcess 数据 * @param taskId 任务 ID @@ -656,6 +666,7 @@ export const useSelectionStore = defineStore('selection', () => { setAgentTaskProcess, getAgentTaskProcess, hasAgentTaskProcess, + removeAgentTaskProcess, clearAgentTaskProcess, getAgentCombinations, clearAllAgentTaskProcess,