Update useThinkFlow.ts
This commit is contained in:
@@ -103,6 +103,8 @@ export function useThinkFlow({ t, locale }: { t: Translate; locale: Ref<string>
|
|||||||
nodes: flowNodes,
|
nodes: flowNodes,
|
||||||
edges: flowEdges,
|
edges: flowEdges,
|
||||||
updateNode,
|
updateNode,
|
||||||
|
removeNodes,
|
||||||
|
removeEdges,
|
||||||
fitView,
|
fitView,
|
||||||
onNodeDragStart,
|
onNodeDragStart,
|
||||||
onNodeDragStop
|
onNodeDragStop
|
||||||
@@ -176,6 +178,17 @@ export function useThinkFlow({ t, locale }: { t: Translate; locale: Ref<string>
|
|||||||
return ids
|
return ids
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除指定节点的所有后代节点
|
||||||
|
* 用于在重新扩展某个节点时,清空其原有的子树
|
||||||
|
*/
|
||||||
|
const removeDescendants = (nodeId: string) => {
|
||||||
|
const descendantIds = getDescendantIds(nodeId)
|
||||||
|
if (descendantIds.size > 0) {
|
||||||
|
removeNodes(Array.from(descendantIds))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前激活路径(节点集合 + 边集合)
|
* 当前激活路径(节点集合 + 边集合)
|
||||||
* - 向上:从激活节点回溯到根
|
* - 向上:从激活节点回溯到根
|
||||||
@@ -663,6 +676,11 @@ export function useThinkFlow({ t, locale }: { t: Translate; locale: Ref<string>
|
|||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
const result = JSON.parse(data.choices[0].message.content)
|
const result = JSON.parse(data.choices[0].message.content)
|
||||||
|
|
||||||
|
// 如果是重新扩展已有节点,先清空其现有的所有后代节点
|
||||||
|
if (parentNode && currentParentId) {
|
||||||
|
removeDescendants(currentParentId)
|
||||||
|
}
|
||||||
|
|
||||||
const parentNodeObj = flowNodes.value.find(n => n.id === currentParentId)
|
const parentNodeObj = flowNodes.value.find(n => n.id === currentParentId)
|
||||||
const startX = parentNodeObj ? parentNodeObj.position.x : 50
|
const startX = parentNodeObj ? parentNodeObj.position.x : 50
|
||||||
const startY = parentNodeObj ? parentNodeObj.position.y : 300
|
const startY = parentNodeObj ? parentNodeObj.position.y : 300
|
||||||
|
|||||||
Reference in New Issue
Block a user