123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- import {Markup} from "@antv/x6";
- import {merge} from "lodash";
- import {lineStyle, portStyle} from "@/views/workflow/config";
- import { v4 } from "uuid";
- import {useWorkflowStore} from "@/stores";
- import {GraphHistoryStep, NodeType} from "@/views/workflow/types";
- const WorkflowStore = useWorkflowStore()
- export const handleNode = (no) => {
- const id = v4()
- if (!no.id) {
- no.id = id
- }
- const node: any = {
- id: no.id,
- x: no.x,
- y: no.y,
- data: {
- workflowData: {
- ...no.data,
- id: no.id
- }
- },
- shape: 'workflow-node',
- portMarkup: [Markup.getForeignObjectMarkup()],
- ports: {
- groups: {
- start: merge(JSON.parse(JSON.stringify(portStyle)), {position: {name: 'start'}}),
- end: merge(JSON.parse(JSON.stringify(portStyle)), {position: {name: 'end'}}),
- more: merge(JSON.parse(JSON.stringify(portStyle)), {position: {name: 'more'}}),
- },
- items: []
- },
- tools: [
- {
- name: 'contextmenu',
- args: {
- delFlag: GraphHistoryStep.NodeDel,
- data: no,
- }
- }
- ]
- }
- if (node.data.workflowData.type === NodeType.Root) {
- node.data.sysVars = [
- ...WorkflowStore.systemVars
- ]
- } else {
- node.ports.items.push({
- id: `${node.id}_start`,
- group: 'start',
- args: {
- type: 'start',
- nodeId: node.id,
- }
- })
- }
- if (node.data.workflowData.ports?.length > 0) {
- node.data.workflowData.ports.forEach((p, pI) => {
- node.ports.items.push({
- id: p.id,
- group: 'more',
- args: {
- type: 'more',
- portId: p.id,
- nodeId: node.id,
- dy: 0
- }
- })
- })
- } else if (node.data.workflowData.type !== NodeType.Answer) {
- node.ports.items.push({
- id: `${node.id}_end`,
- group: 'end',
- args: {
- type: 'end',
- nodeId: node.id,
- }
- })
- }
- return node
- }
- export const handleEdge = (ed) => {
- const id = v4()
- if (!ed.id) {
- ed.id = id
- }
- const edge = {
- id: ed.id,
- source: {
- cell: ed.source,
- port: ed.port || `${ed.source}_end`
- },
- target: {
- cell: ed.target,
- port: `${ed.target}_start`
- },
- data: {
- workflowData: {
- ...ed.data,
- id: ed.id
- }
- },
- shape: 'edge',
- attrs: lineStyle,
- zIndex: -1,
- // router: {
- // name: 'manhattan',
- // args: {
- // startDirections: ['right'],
- // endDirections: ['left'],
- // },
- // },
- tools: [
- {
- name: 'contextmenu',
- args: {
- delFlag: GraphHistoryStep.EdgeDel,
- data: ed,
- }
- }
- ]
- }
- return edge
- }
|