feat:执行过程编排新建分支单节点删除和整个分支节点删除
This commit is contained in:
@@ -134,9 +134,11 @@ export const useSelectionStore = defineStore('selection', () => {
|
||||
nodes: Node[]
|
||||
edges: Edge[]
|
||||
tasks: IRawStepTask[]
|
||||
id?: string // 允许传入自定义 id
|
||||
},
|
||||
): string {
|
||||
const branchId = `task-process-branch-${uuidv4()}`
|
||||
const branchId = data.id || `task-process-branch-${uuidv4()}`
|
||||
console.log('[store.addTaskProcessBranch] 生成的 branchId:', branchId, '传入的 id:', data.id)
|
||||
const agentGroupKey = getAgentGroupKey(agents)
|
||||
|
||||
const newBranch: IBranchData = {
|
||||
@@ -225,6 +227,61 @@ export const useSelectionStore = defineStore('selection', () => {
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 精准删除分支中的单个节点
|
||||
* @param taskStepId 任务步骤 ID
|
||||
* @param agents Agent 列表
|
||||
* @param branchId 分支 ID
|
||||
* @param nodeId 要删除的节点 ID
|
||||
* @param incomingEdges 入边(用于更新 edges)
|
||||
* @param outgoingEdges 出边(用于更新 edges)
|
||||
* @param newEdges 新创建的边(用于重新连接)
|
||||
* @returns 是否删除成功
|
||||
*/
|
||||
function removeNodeFromBranch(
|
||||
taskStepId: string,
|
||||
agents: string[],
|
||||
branchId: string,
|
||||
nodeId: string,
|
||||
incomingEdges: any[] = [],
|
||||
outgoingEdges: any[] = [],
|
||||
newEdges: any[] = [],
|
||||
): boolean {
|
||||
const agentGroupKey = getAgentGroupKey(agents)
|
||||
const branches = taskProcessBranchesMap.value.get(taskStepId)?.get(agentGroupKey)
|
||||
if (!branches) return false
|
||||
|
||||
const branchIndex = branches.findIndex((branch) => branch.id === branchId)
|
||||
if (branchIndex === -1) return false
|
||||
|
||||
const branch = branches[branchIndex]
|
||||
if (!branch || !branch.nodes || !branch.tasks) return false
|
||||
|
||||
// 找到节点在分支中的索引
|
||||
const nodeIndex = branch.nodes.findIndex((n: any) => n.id === nodeId)
|
||||
if (nodeIndex === -1) return false
|
||||
|
||||
// 精准删除:只删除对应索引的节点和任务
|
||||
branch.nodes.splice(nodeIndex, 1)
|
||||
branch.tasks.splice(nodeIndex, 1)
|
||||
|
||||
// 更新 edges:移除相关边,添加新边
|
||||
if (incomingEdges.length > 0 || outgoingEdges.length > 0) {
|
||||
const relatedEdgeIds = [
|
||||
...incomingEdges.map((e: any) => e.id),
|
||||
...outgoingEdges.map((e: any) => e.id),
|
||||
]
|
||||
// 过滤掉相关的旧边
|
||||
branch.edges = (branch.edges || []).filter((e: any) => !relatedEdgeIds.includes(e.id))
|
||||
// 添加新边
|
||||
if (newEdges.length > 0) {
|
||||
branch.edges.push(...newEdges)
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除指定任务步骤和 agent 组合的所有分支
|
||||
* @param taskStepId 任务步骤 ID
|
||||
@@ -330,6 +387,29 @@ export const useSelectionStore = defineStore('selection', () => {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 从数据库删除指定节点
|
||||
* @param TaskID 大任务ID(数据库主键)
|
||||
* @param stepId 小任务ID
|
||||
* @param branchId 分支ID
|
||||
* @param nodeId 要删除的节点ID
|
||||
* @returns Promise<boolean> 是否删除成功
|
||||
*/
|
||||
async function deleteTaskProcessNodeFromDB(
|
||||
TaskID: string,
|
||||
stepId: string,
|
||||
branchId: string,
|
||||
nodeId: string,
|
||||
edges: any[] = [],
|
||||
): Promise<boolean> {
|
||||
// 导入 api(避免循环导入问题)
|
||||
const { default: api } = await import('@/api')
|
||||
|
||||
const result = await api.deleteTaskProcessNode(TaskID, stepId, branchId, nodeId, edges)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 从数据库恢复任务过程分支数据
|
||||
* @param dbBranches 从数据库读取的任务过程分支数据
|
||||
@@ -672,6 +752,7 @@ export const useSelectionStore = defineStore('selection', () => {
|
||||
getAllTaskProcessBranches,
|
||||
getTaskProcessBranchesByParent,
|
||||
removeTaskProcessBranch,
|
||||
removeNodeFromBranch,
|
||||
clearTaskProcessBranches,
|
||||
|
||||
// ==================== 任务过程分支生效状态管理方法 ====================
|
||||
@@ -697,6 +778,7 @@ export const useSelectionStore = defineStore('selection', () => {
|
||||
restoreAgentCombinationsFromDB,
|
||||
saveTaskProcessBranchesToDB,
|
||||
deleteTaskProcessBranchFromDB,
|
||||
deleteTaskProcessNodeFromDB,
|
||||
restoreTaskProcessBranchesFromDB,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user