feat:修复分支数据动态存储数据库bug
This commit is contained in:
@@ -309,6 +309,21 @@ async function handleSearch() {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// 填充完成后,重新保存分支数据(同步最新的大纲数据)
|
||||
// 只有在没有停止且成功完成时才执行
|
||||
if (isFillingSteps.value && !agentsStore.isStopping && fillTaskTaskID) {
|
||||
try {
|
||||
// 先从主大纲同步最新数据到分支
|
||||
const mainOutlineTasks = agentsStore.agentRawPlan.data?.['Collaboration Process'] || []
|
||||
selectionStore.syncBranchTasksFromMainOutline(mainOutlineTasks)
|
||||
// 再保存到数据库
|
||||
await selectionStore.saveBranchesToDB(fillTaskTaskID)
|
||||
console.log('✅ 步骤填充完成,分支数据已同步更新')
|
||||
} catch (error) {
|
||||
console.error('同步分支数据失败:', error)
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
// 重置状态(确保即使出错也会执行)
|
||||
triggerOnFocus.value = true
|
||||
|
||||
@@ -555,6 +555,26 @@ onMounted(() => {
|
||||
isMounted.value = true
|
||||
initializeFlow()
|
||||
|
||||
// 如果没有选中任何节点,根据当前显示的任务步骤来高亮
|
||||
if (selectedNodeIds.value.size === 0) {
|
||||
const currentTasks = agentsStore.agentRawPlan.data?.['Collaboration Process'] || []
|
||||
|
||||
if (currentTasks.length > 0) {
|
||||
// 找到当前任务对应的节点 ID
|
||||
const currentTaskIds = currentTasks.map((task: any) => task.Id)
|
||||
const nodesToHighlight = nodes.value
|
||||
.filter(node => {
|
||||
const nodeTaskId = node.data?.task?.Id || ''
|
||||
return currentTaskIds.includes(nodeTaskId)
|
||||
})
|
||||
.map(node => node.id)
|
||||
|
||||
if (nodesToHighlight.length > 0) {
|
||||
selectedNodeIds.value = new Set(nodesToHighlight)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 同步 currentTask 数据
|
||||
if (agentsStore.currentTask && agentsStore.currentTask.StepName) {
|
||||
const matchedNodes = nodes.value.filter(node => {
|
||||
@@ -1199,7 +1219,8 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
try {
|
||||
const filledTask = await api.fillStepTask({
|
||||
goal: generalGoal,
|
||||
stepTask: task
|
||||
stepTask: task,
|
||||
TaskID: (window as any).__CURRENT_TASK_ID__ || ''
|
||||
})
|
||||
|
||||
// 更新任务的 AgentSelection 和 TaskProcess
|
||||
@@ -1466,7 +1487,8 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
try {
|
||||
const filledTask = await api.fillStepTask({
|
||||
goal: generalGoal,
|
||||
stepTask: task
|
||||
stepTask: task,
|
||||
TaskID: (window as any).__CURRENT_TASK_ID__ || ''
|
||||
})
|
||||
|
||||
// 更新任务的 AgentSelection 和 TaskProcess
|
||||
|
||||
@@ -71,6 +71,45 @@ export const useSelectionStore = defineStore('selection', () => {
|
||||
return flowBranches.value
|
||||
}
|
||||
|
||||
/**
|
||||
* 从主大纲同步最新的任务数据到分支的 tasks 中
|
||||
* @param mainOutlineTasks 主大纲中的 Collaboration Process 任务列表
|
||||
* @description 遍历所有分支,根据节点 ID 匹配主大纲中的任务,更新 tasks 数组
|
||||
*/
|
||||
function syncBranchTasksFromMainOutline(mainOutlineTasks: any[]): void {
|
||||
if (!mainOutlineTasks || !Array.isArray(mainOutlineTasks)) return
|
||||
|
||||
for (const branch of flowBranches.value) {
|
||||
if (!branch.nodes || !Array.isArray(branch.nodes)) continue
|
||||
|
||||
// 构建节点 ID 到任务详情的映射
|
||||
const nodeIdToTaskMap = new Map<string, any>()
|
||||
for (const node of branch.nodes) {
|
||||
if (node.data?.task) {
|
||||
nodeIdToTaskMap.set(node.id, node.data.task)
|
||||
}
|
||||
}
|
||||
|
||||
// 根据主大纲更新 tasks 数组
|
||||
const updatedTasks: any[] = []
|
||||
for (const node of branch.nodes) {
|
||||
const task = nodeIdToTaskMap.get(node.id)
|
||||
if (task) {
|
||||
// 从主大纲中找到对应 ID 的任务,使用主大纲中的最新数据
|
||||
const mainTask = mainOutlineTasks.find(
|
||||
(t: any) => t.Id === task.Id || t.StepName === task.StepName
|
||||
)
|
||||
if (mainTask) {
|
||||
updatedTasks.push(mainTask)
|
||||
} else {
|
||||
updatedTasks.push(task)
|
||||
}
|
||||
}
|
||||
}
|
||||
branch.tasks = updatedTasks
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父节点 ID 获取流程图分支
|
||||
* @param parentNodeId 父节点 ID
|
||||
@@ -745,6 +784,7 @@ export const useSelectionStore = defineStore('selection', () => {
|
||||
removeFlowBranch,
|
||||
clearFlowBranches,
|
||||
clearFlowBranchesByParent,
|
||||
syncBranchTasksFromMainOutline,
|
||||
|
||||
// ==================== 任务过程分支管理方法 ====================
|
||||
addTaskProcessBranch,
|
||||
|
||||
Reference in New Issue
Block a user