|
@@ -67,6 +67,7 @@
|
|
|
@dragover="onDragOver"
|
|
@dragover="onDragOver"
|
|
|
@dragleave="onDragLeave"
|
|
@dragleave="onDragLeave"
|
|
|
@create:connection:cancelled="onConnectionOpenNodeLibary"
|
|
@create:connection:cancelled="onConnectionOpenNodeLibary"
|
|
|
|
|
+ @click:connection:add="handleClickConectionAdd"
|
|
|
class="bg-#f5f5f5"
|
|
class="bg-#f5f5f5"
|
|
|
>
|
|
>
|
|
|
<Toolbar
|
|
<Toolbar
|
|
@@ -146,10 +147,12 @@ const workflowWrapperRef = ref<HTMLElement>()
|
|
|
const showNodeLibary = ref(false)
|
|
const showNodeLibary = ref(false)
|
|
|
const libaryRefferenceRef = ref<HTMLElement>()
|
|
const libaryRefferenceRef = ref<HTMLElement>()
|
|
|
const peddingHandlePayload = ref<{
|
|
const peddingHandlePayload = ref<{
|
|
|
- handle: ConnectStartEvent
|
|
|
|
|
|
|
+ by?: 'node' | 'edge'
|
|
|
|
|
+ handle?: ConnectStartEvent
|
|
|
position: XYPosition
|
|
position: XYPosition
|
|
|
event?: MouseEvent
|
|
event?: MouseEvent
|
|
|
parentId?: string
|
|
parentId?: string
|
|
|
|
|
+ connection?: Connection
|
|
|
}>()
|
|
}>()
|
|
|
|
|
|
|
|
const projectMap = JSON.parse(localStorage.getItem(`workflow-map`) || '{}') as Record<
|
|
const projectMap = JSON.parse(localStorage.getItem(`workflow-map`) || '{}') as Record<
|
|
@@ -630,6 +633,7 @@ const handleRunNode = async (id: string) => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
const handleNodeCreate = (value: { type: string; position?: XYPosition } | string) => {
|
|
const handleNodeCreate = (value: { type: string; position?: XYPosition } | string) => {
|
|
|
|
|
+ // TODO: 处理注释节点
|
|
|
if (typeof value === 'string') {
|
|
if (typeof value === 'string') {
|
|
|
if (value === 'stickyNote') {
|
|
if (value === 'stickyNote') {
|
|
|
workflow.value?.nodes.push({
|
|
workflow.value?.nodes.push({
|
|
@@ -663,7 +667,7 @@ const handleNodeCreate = (value: { type: string; position?: XYPosition } | strin
|
|
|
|
|
|
|
|
// 如果存在对应节点则添加
|
|
// 如果存在对应节点则添加
|
|
|
if (nodeToAdd) {
|
|
if (nodeToAdd) {
|
|
|
- const newNodeParam = {
|
|
|
|
|
|
|
+ const newNodeParam: any = {
|
|
|
...nodeToAdd,
|
|
...nodeToAdd,
|
|
|
appAgentId: workflow.value?.id || '',
|
|
appAgentId: workflow.value?.id || '',
|
|
|
position: value.position
|
|
position: value.position
|
|
@@ -683,20 +687,34 @@ const handleNodeCreate = (value: { type: string; position?: XYPosition } | strin
|
|
|
const { position, handle, parentId } = peddingHandlePayload.value
|
|
const { position, handle, parentId } = peddingHandlePayload.value
|
|
|
|
|
|
|
|
newNodeParam.position = position
|
|
newNodeParam.position = position
|
|
|
- newNodeParam.prevNodeId = handle.nodeId
|
|
|
|
|
|
|
+ newNodeParam.prevNodeId = handle?.nodeId
|
|
|
newNodeParam.parentId = parentId
|
|
newNodeParam.parentId = parentId
|
|
|
- if (handle.handleId?.includes('_')) {
|
|
|
|
|
- newNodeParam.nodeHandleId = handle.handleId
|
|
|
|
|
|
|
+ // 条件句柄
|
|
|
|
|
+ if (handle?.handleId?.includes('_')) {
|
|
|
|
|
+ newNodeParam.nodeHandleId = handle?.handleId
|
|
|
}
|
|
}
|
|
|
- // if (handle.handleId?.endsWith('-else')) {
|
|
|
|
|
- // newNodeParam.nodeHandleId = handle.nodeId
|
|
|
|
|
- // }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!newNodeParam.position) {
|
|
if (!newNodeParam.position) {
|
|
|
newNodeParam.position = nodeToAdd.position
|
|
newNodeParam.position = nodeToAdd.position
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 根据连线添加节点
|
|
|
|
|
+ if (peddingHandlePayload.value?.by === 'edge' && peddingHandlePayload.value?.connection) {
|
|
|
|
|
+ const { connection } = peddingHandlePayload.value
|
|
|
|
|
+ const params = {
|
|
|
|
|
+ edgeId: connection.id,
|
|
|
|
|
+ newNode: newNodeParam
|
|
|
|
|
+ }
|
|
|
|
|
+ agent.postAgentDoNewAgentNodeWithEdge(params).then(async (response) => {
|
|
|
|
|
+ if (handleApiResult(response, '节点已添加', '新增节点失败')) {
|
|
|
|
|
+ await loadAgentWorkflow(workflow.value.id)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ onHideNodeLibary()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
onHideNodeLibary()
|
|
onHideNodeLibary()
|
|
|
|
|
|
|
|
agent
|
|
agent
|
|
@@ -963,6 +981,30 @@ const onHideNodeLibary = () => {
|
|
|
showNodeLibary.value = false
|
|
showNodeLibary.value = false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 连线添加按钮触发
|
|
|
|
|
+ */
|
|
|
|
|
+const handleClickConectionAdd = (connection: Connection) => {
|
|
|
|
|
+ const el = document.querySelector(`[edge-add-btn="${connection.id}"]`) as HTMLElement
|
|
|
|
|
+ const screenToFlowCoordinate = workflowRef.value?.getVueFlow()?.screenToFlowCoordinate
|
|
|
|
|
+
|
|
|
|
|
+ if (el && screenToFlowCoordinate) {
|
|
|
|
|
+ const rect = el.getBoundingClientRect()
|
|
|
|
|
+ const position = screenToFlowCoordinate({
|
|
|
|
|
+ x: rect.left,
|
|
|
|
|
+ y: rect.top
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ libaryRefferenceRef.value = el
|
|
|
|
|
+ showNodeLibary.value = true
|
|
|
|
|
+ peddingHandlePayload.value = {
|
|
|
|
|
+ by: 'edge',
|
|
|
|
|
+ position,
|
|
|
|
|
+ connection
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
onBeforeUnmount(() => {
|
|
onBeforeUnmount(() => {
|
|
|
if (saveAgentTimer.value) window.clearTimeout(saveAgentTimer.value)
|
|
if (saveAgentTimer.value) window.clearTimeout(saveAgentTimer.value)
|
|
|
if (saveVarsTimer.value) window.clearTimeout(saveVarsTimer.value)
|
|
if (saveVarsTimer.value) window.clearTimeout(saveVarsTimer.value)
|