|
@@ -56,7 +56,13 @@
|
|
|
width="360px"
|
|
width="360px"
|
|
|
virtual-triggering
|
|
virtual-triggering
|
|
|
>
|
|
>
|
|
|
- <NodeLibary @add-node="handleNodeCreate" @mouseleave="onHideNodeLibary" />
|
|
|
|
|
|
|
+ <NodeLibary
|
|
|
|
|
+ @add-node="handleNodeCreate"
|
|
|
|
|
+ @mouseleave="onHideNodeLibary"
|
|
|
|
|
+ :parent-node-type="nodeLibaryParentType"
|
|
|
|
|
+ hide-start
|
|
|
|
|
+ ignore-drag
|
|
|
|
|
+ />
|
|
|
</el-popover>
|
|
</el-popover>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
@@ -140,17 +146,17 @@ const removeNodeLibaryPopoverAnchor = () => {
|
|
|
nodeLibaryPopoverAnchorRef.value = undefined
|
|
nodeLibaryPopoverAnchorRef.value = undefined
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const createNodeLibaryPopoverAnchor = (event?: MouseEvent) => {
|
|
|
|
|
|
|
+const createNodeLibaryPopoverAnchor = (position?: { x: number; y: number }) => {
|
|
|
removeNodeLibaryPopoverAnchor()
|
|
removeNodeLibaryPopoverAnchor()
|
|
|
|
|
|
|
|
- if (!event) {
|
|
|
|
|
|
|
+ if (!position) {
|
|
|
return undefined
|
|
return undefined
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const anchor = document.createElement('div')
|
|
const anchor = document.createElement('div')
|
|
|
anchor.style.position = 'fixed'
|
|
anchor.style.position = 'fixed'
|
|
|
- anchor.style.left = `${event.clientX}px`
|
|
|
|
|
- anchor.style.top = `${event.clientY}px`
|
|
|
|
|
|
|
+ anchor.style.left = `${position.x}px`
|
|
|
|
|
+ anchor.style.top = `${position.y}px`
|
|
|
anchor.style.width = '1px'
|
|
anchor.style.width = '1px'
|
|
|
anchor.style.height = '1px'
|
|
anchor.style.height = '1px'
|
|
|
anchor.style.pointerEvents = 'none'
|
|
anchor.style.pointerEvents = 'none'
|
|
@@ -269,6 +275,17 @@ const workflowWithExecutionState = computed(() => {
|
|
|
} as IWorkflow
|
|
} as IWorkflow
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+const getNodeTypeById = (id?: string) => {
|
|
|
|
|
+ if (!id) {
|
|
|
|
|
+ return ''
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const node = props.workflow?.nodes?.find((item) => item.id === id)
|
|
|
|
|
+ return (node as any)?.nodeType || (node as any)?.data?.nodeType || ''
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const nodeLibaryParentType = computed(() => getNodeTypeById(peddingHandlePayload.value?.parentId))
|
|
|
|
|
+
|
|
|
const toolbarRunNodes = computed(() => {
|
|
const toolbarRunNodes = computed(() => {
|
|
|
return (props.workflow?.nodes || [])
|
|
return (props.workflow?.nodes || [])
|
|
|
.filter((node) => {
|
|
.filter((node) => {
|
|
@@ -540,15 +557,30 @@ const handleNodeCreate = (value: { type: string; position?: XYPosition } | strin
|
|
|
|
|
|
|
|
const nodeToAdd = nodeMap[value.type]?.schema
|
|
const nodeToAdd = nodeMap[value.type]?.schema
|
|
|
const viewport = workflowRef.value?.getVueFlow()?.viewport
|
|
const viewport = workflowRef.value?.getVueFlow()?.viewport
|
|
|
|
|
+ const parentNodeType = getNodeTypeById(peddingHandlePayload.value?.parentId)
|
|
|
|
|
+ const isLoopContainer = ['loop', 'iteration'].includes(parentNodeType)
|
|
|
|
|
+
|
|
|
|
|
+ if (value.type === 'loop-end' && !isLoopContainer) {
|
|
|
|
|
+ ElMessage.warning('退出循环节点只能在循环或迭代节点内部添加')
|
|
|
|
|
+ onHideNodeLibary()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (isLoopContainer && ['loop', 'iteration'].includes(value.type)) {
|
|
|
|
|
+ ElMessage.warning('循环或迭代节点内部不允许再添加循环或迭代节点')
|
|
|
|
|
+ onHideNodeLibary()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (nodeToAdd) {
|
|
if (nodeToAdd) {
|
|
|
|
|
+ const hasExplicitPosition = !!value.position
|
|
|
const newNodeParam: any = {
|
|
const newNodeParam: any = {
|
|
|
...nodeToAdd,
|
|
...nodeToAdd,
|
|
|
appAgentId: props.workflow?.id || '',
|
|
appAgentId: props.workflow?.id || '',
|
|
|
position: value.position
|
|
position: value.position
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (newNodeParam.position && viewport) {
|
|
|
|
|
|
|
+ if (!hasExplicitPosition && !peddingHandlePayload.value && viewport) {
|
|
|
newNodeParam.position = {
|
|
newNodeParam.position = {
|
|
|
x: (-viewport.value.x + window.innerWidth / 2) / viewport.value.zoom,
|
|
x: (-viewport.value.x + window.innerWidth / 2) / viewport.value.zoom,
|
|
|
y: (-viewport.value.y + window.innerHeight / 2) / viewport.value.zoom
|
|
y: (-viewport.value.y + window.innerHeight / 2) / viewport.value.zoom
|
|
@@ -800,7 +832,10 @@ const onConnectionOpenNodeLibary = async (payload: {
|
|
|
parentId?: string
|
|
parentId?: string
|
|
|
}) => {
|
|
}) => {
|
|
|
await nextTick()
|
|
await nextTick()
|
|
|
- libaryRefferenceRef.value = createNodeLibaryPopoverAnchor(payload.event)
|
|
|
|
|
|
|
+ libaryRefferenceRef.value = createNodeLibaryPopoverAnchor({
|
|
|
|
|
+ x: payload.event.clientX,
|
|
|
|
|
+ y: payload.event.clientY
|
|
|
|
|
+ })
|
|
|
showNodeLibary.value = true
|
|
showNodeLibary.value = true
|
|
|
peddingHandlePayload.value = payload
|
|
peddingHandlePayload.value = payload
|
|
|
}
|
|
}
|
|
@@ -828,7 +863,10 @@ const handleClickConectionAdd = (connection: Connection & { id: string }, parent
|
|
|
y: rect.top
|
|
y: rect.top
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- libaryRefferenceRef.value = el
|
|
|
|
|
|
|
+ libaryRefferenceRef.value = createNodeLibaryPopoverAnchor({
|
|
|
|
|
+ x: rect.left,
|
|
|
|
|
+ y: rect.top
|
|
|
|
|
+ })
|
|
|
showNodeLibary.value = true
|
|
showNodeLibary.value = true
|
|
|
peddingHandlePayload.value = {
|
|
peddingHandlePayload.value = {
|
|
|
by: 'edge',
|
|
by: 'edge',
|