|
@@ -3,13 +3,19 @@ import {merge} from "lodash";
|
|
|
import {lineStyle, portStyle} from "@/views/workflow/config";
|
|
|
import { v4 } from "uuid";
|
|
|
|
|
|
-export const handleNode = (data, graph) => {
|
|
|
+export const handleNode = (no, graph) => {
|
|
|
const id = v4()
|
|
|
- if (!data.id) {
|
|
|
- data.id = id
|
|
|
+ if (!no.id) {
|
|
|
+ no.id = id
|
|
|
}
|
|
|
const node: any = {
|
|
|
- ...data,
|
|
|
+ id: no.id,
|
|
|
+ x: no.x,
|
|
|
+ y: no.y,
|
|
|
+ data: {
|
|
|
+ ...no.data,
|
|
|
+ id: no.id
|
|
|
+ },
|
|
|
shape: 'workflow-node',
|
|
|
portMarkup: [Markup.getForeignObjectMarkup()],
|
|
|
ports: {
|
|
@@ -24,56 +30,67 @@ export const handleNode = (data, graph) => {
|
|
|
{
|
|
|
name: 'contextmenu',
|
|
|
args: {
|
|
|
- data,
|
|
|
+ data: no,
|
|
|
graph,
|
|
|
}
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
- node.data.id = data.id
|
|
|
- if (data.data.type !== 'root') {
|
|
|
+ if (node.data.type !== 'root') {
|
|
|
node.ports.items.push({
|
|
|
- id: `${data.id}_start`,
|
|
|
+ id: `${node.id}_start`,
|
|
|
group: 'start',
|
|
|
args: {
|
|
|
type: 'start',
|
|
|
- nodeId: data.id,
|
|
|
+ nodeId: node.id,
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
- if (data.data.ports?.length > 0) {
|
|
|
- data.data.ports.forEach((p, pI) => {
|
|
|
+ if (node.data.ports?.length > 0) {
|
|
|
+ node.data.ports.forEach((p, pI) => {
|
|
|
node.ports.items.push({
|
|
|
id: p.id,
|
|
|
group: 'more',
|
|
|
args: {
|
|
|
type: 'more',
|
|
|
portId: p.id,
|
|
|
- nodeId: data.id,
|
|
|
+ nodeId: node.id,
|
|
|
dy: 0
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
} else {
|
|
|
node.ports.items.push({
|
|
|
- id: `${data.id}_end`,
|
|
|
+ id: `${node.id}_end`,
|
|
|
group: 'end',
|
|
|
args: {
|
|
|
type: 'end',
|
|
|
- nodeId: data.id,
|
|
|
+ nodeId: node.id,
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
return node
|
|
|
}
|
|
|
|
|
|
-export const handleEdge = (data, graph) => {
|
|
|
+export const handleEdge = (ed, graph) => {
|
|
|
const id = v4()
|
|
|
- if (!data.id) {
|
|
|
- data.id = id
|
|
|
+ if (!ed.id) {
|
|
|
+ ed.id = id
|
|
|
}
|
|
|
const edge = {
|
|
|
- ...data,
|
|
|
+ id: ed.id,
|
|
|
+ source: {
|
|
|
+ cell: ed.source,
|
|
|
+ port: ed.port || `${ed.source}_end`
|
|
|
+ },
|
|
|
+ target: {
|
|
|
+ cell: ed.target,
|
|
|
+ port: `${ed.target}_start`
|
|
|
+ },
|
|
|
+ data: {
|
|
|
+ ...ed.data,
|
|
|
+ id: ed.id
|
|
|
+ },
|
|
|
shape: 'edge',
|
|
|
attrs: lineStyle,
|
|
|
router: {
|
|
@@ -87,20 +104,11 @@ export const handleEdge = (data, graph) => {
|
|
|
{
|
|
|
name: 'contextmenu',
|
|
|
args: {
|
|
|
- data,
|
|
|
+ data: ed,
|
|
|
graph,
|
|
|
}
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
- edge.id = data.id
|
|
|
- edge.source = {
|
|
|
- cell: data.source,
|
|
|
- port: data.port || `${data.source}_end`
|
|
|
- }
|
|
|
- edge.target = {
|
|
|
- cell: data.target,
|
|
|
- port: `${data.target}_start`
|
|
|
- }
|
|
|
return edge
|
|
|
}
|