|
@@ -1,8 +1,9 @@
|
|
|
-import {Graph, Addon, FunctionExt, Shape} from '@antv/x6'
|
|
|
+import {Graph, Addon, FunctionExt, Shape,Dom} from '@antv/x6'
|
|
|
import './shape'
|
|
|
import { customPorts ,basicPorts} from './ports'
|
|
|
// import { getImg } from '../../../utils'
|
|
|
import graphData from './data/data'
|
|
|
+import { translate } from '@antv/x6/lib/util/dom/transform'
|
|
|
const insertCss = require('insert-css')
|
|
|
|
|
|
insertCss(`
|
|
@@ -25,7 +26,7 @@ export default class FlowGraph {
|
|
|
* @param {*} flag 默认为true,传入false只实例化画板
|
|
|
* @returns
|
|
|
*/
|
|
|
- static init(dom, width = 1200, height = 900, flag = true) {
|
|
|
+ static init(dom, width = 800, height = 800, flag = true) {
|
|
|
// 初始化 流程图画板
|
|
|
this.graph = new Graph({
|
|
|
background: {
|
|
@@ -217,15 +218,19 @@ export default class FlowGraph {
|
|
|
this.stencil = new Addon.Stencil({
|
|
|
target: this.graph,
|
|
|
stencilGraphWidth: 280,
|
|
|
- search: { rect: true },
|
|
|
+ search: { rect: true ,ellipse:true,polygon:true,},
|
|
|
collapsable: true,
|
|
|
groups: [
|
|
|
{
|
|
|
name: 'basic',
|
|
|
title: '基础节点',
|
|
|
graphHeight: 280,
|
|
|
+ layoutOptions: {
|
|
|
+ columns: 1,
|
|
|
+ marginX: 8,
|
|
|
+ },
|
|
|
},
|
|
|
- // {
|
|
|
+ // {
|
|
|
// name: 'custom-image',
|
|
|
// title: '系统设计图',
|
|
|
// graphHeight: 600
|
|
@@ -258,23 +263,38 @@ export default class FlowGraph {
|
|
|
const { graph } = this
|
|
|
// 基础节点
|
|
|
const r1 = graph.createNode({
|
|
|
+
|
|
|
shape: 'flow-chart-rect',
|
|
|
+ width:60,
|
|
|
+ height:40,
|
|
|
attrs: {
|
|
|
body: {
|
|
|
rx: 24,
|
|
|
ry: 24,
|
|
|
+ stroke: '#07448a',
|
|
|
+
|
|
|
},
|
|
|
text: {
|
|
|
- text: '起始节点',
|
|
|
+ text: '开始',
|
|
|
+
|
|
|
},
|
|
|
-
|
|
|
+
|
|
|
},
|
|
|
})
|
|
|
const r2 = graph.createNode({
|
|
|
shape: 'flow-chart-rect',
|
|
|
+ width:58,
|
|
|
+ height:38,
|
|
|
attrs: {
|
|
|
text: {
|
|
|
- text: '流程节点',
|
|
|
+ text: '流程',
|
|
|
+ // refX: -100,
|
|
|
+ // refY: 40,
|
|
|
+ },
|
|
|
+ body: {
|
|
|
+ stroke: '#07448a', // 边框颜色
|
|
|
+ // x: -140,
|
|
|
+ // y: 40,
|
|
|
},
|
|
|
},
|
|
|
})
|
|
@@ -284,13 +304,17 @@ export default class FlowGraph {
|
|
|
height: 52,
|
|
|
angle: 45,
|
|
|
attrs: {
|
|
|
+ body: {
|
|
|
+ stroke: '#07448a', // 边框颜色
|
|
|
+ },
|
|
|
+
|
|
|
'edit-text': {
|
|
|
style: {
|
|
|
transform: 'rotate(-45deg)',
|
|
|
},
|
|
|
},
|
|
|
text: {
|
|
|
- text: '判断节点',
|
|
|
+ text: '判断',
|
|
|
transform: 'rotate(-45deg)',
|
|
|
},
|
|
|
},
|
|
@@ -333,46 +357,398 @@ export default class FlowGraph {
|
|
|
})
|
|
|
const r4 = graph.createNode({
|
|
|
shape: 'flow-chart-rect',
|
|
|
- width: 70,
|
|
|
- height: 70,
|
|
|
+ width: 56,
|
|
|
+ height:56,
|
|
|
attrs: {
|
|
|
body: {
|
|
|
rx: 35,
|
|
|
ry: 35,
|
|
|
+ stroke: '#07448a',
|
|
|
},
|
|
|
text: {
|
|
|
- text: '联系节点',
|
|
|
+ text: '联系',
|
|
|
},
|
|
|
},
|
|
|
})
|
|
|
const r5 = graph.createNode({
|
|
|
- shape: 'flow-chart-rect',
|
|
|
- width:60,
|
|
|
- height:60,
|
|
|
+ shape: 'polygon',
|
|
|
+ width:57,
|
|
|
+ height:47,
|
|
|
+
|
|
|
attrs: {
|
|
|
+ // style: {
|
|
|
+ // visibility: 'hidden',
|
|
|
+ // },
|
|
|
body: {
|
|
|
refPoints: '10,0 40,0 30,20 0,20',
|
|
|
- stroke: 'rgba(95,149,255)', // 边框颜色
|
|
|
+ stroke: '#07448a', // 边框颜色
|
|
|
+ strokeWidth: 1,
|
|
|
+ width:50,
|
|
|
+ height:40,
|
|
|
+ fill: '#fff', // 填充颜色
|
|
|
+ transform:'skewX(-30deg)',
|
|
|
+ refX: 15,
|
|
|
+
|
|
|
+ },
|
|
|
+ fo: {
|
|
|
+ refWidth: '100%',
|
|
|
+ refHeight: '100%',
|
|
|
+ stroke: '#07448a', // 边框颜色
|
|
|
strokeWidth: 1,
|
|
|
},
|
|
|
+ foBody: {
|
|
|
+ xmlns: Dom.ns.xhtml,
|
|
|
+ style: {
|
|
|
+ width: '100%',
|
|
|
+ height: '100%',
|
|
|
+ display: 'flex',
|
|
|
+ justifyContent: 'center',
|
|
|
+ alignItems: 'center',
|
|
|
+ stroke: '#07448a', // 边框颜色
|
|
|
+ strokeWidth: 1,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ text: {
|
|
|
+ text: '数据',
|
|
|
+ },
|
|
|
+ 'edit-text': {
|
|
|
+ contenteditable: 'true',
|
|
|
+ class: 'x6-edit-text',
|
|
|
+ style: {
|
|
|
+ width: '100%',
|
|
|
+ textAlign: 'center',
|
|
|
+ fontSize: 12,
|
|
|
+ color: 'rgba(0,0,0,0.85)',
|
|
|
+ },
|
|
|
+ },
|
|
|
},
|
|
|
- label: '数据节点',
|
|
|
-
|
|
|
+ ports: {
|
|
|
+ groups: {
|
|
|
+ // 输入链接桩群组定义
|
|
|
+ in: {
|
|
|
+ position: 'top',
|
|
|
+ attrs: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ circle: {
|
|
|
+ r: 4,
|
|
|
+ magnet: true,
|
|
|
+ stroke: '#5F95FF',
|
|
|
+ strokeWidth: 1,
|
|
|
+ fill: '#fff',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ // 输出链接桩群组定义
|
|
|
+ out: {
|
|
|
+ position: 'bottom',
|
|
|
+ attrs: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ circle: {
|
|
|
+ r: 4,
|
|
|
+ magnet: true,
|
|
|
+ stroke: '#5F95FF',
|
|
|
+ strokeWidth: 1,
|
|
|
+ fill: '#fff',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ on: {
|
|
|
+ position: 'left',
|
|
|
+ attrs: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ circle: {
|
|
|
+ r:4,
|
|
|
+ magnet: true,
|
|
|
+ stroke: '#5F95FF',
|
|
|
+ strokeWidth: 1,
|
|
|
+ fill: '#fff',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ un: {
|
|
|
+ position: 'right',
|
|
|
+ attrs: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ circle: {
|
|
|
+ r: 4,
|
|
|
+ magnet: true,
|
|
|
+ stroke: '#5F95FF',
|
|
|
+ strokeWidth: 1,
|
|
|
+ fill: '#fff',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ items: [
|
|
|
+ {
|
|
|
+ id: 'port1',
|
|
|
+ group: 'in',
|
|
|
+ attrs: {
|
|
|
+ circle: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 'port2',
|
|
|
+ group: 'un',
|
|
|
+ attrs: {
|
|
|
+ circle: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 'port3',
|
|
|
+ group: 'on',
|
|
|
+ attrs: {
|
|
|
+ circle: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 'port4',
|
|
|
+ group: 'out',
|
|
|
+ attrs: {
|
|
|
+ circle: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ markup: [
|
|
|
+ {
|
|
|
+ tagName: 'rect',
|
|
|
+ selector: 'body',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: 'text',
|
|
|
+ selector: 'text',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: 'foreignObject',
|
|
|
+ selector: 'fo',
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ ns: Dom.ns.xhtml,
|
|
|
+ tagName: 'body',
|
|
|
+ selector: 'foBody',
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ tagName: 'div',
|
|
|
+ selector: 'edit-text',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ],
|
|
|
})
|
|
|
const r6 = graph.createNode({
|
|
|
- shape: 'flow-chart-rect',
|
|
|
- width: 80,
|
|
|
- height: 50,
|
|
|
+ shape: 'ellipse',
|
|
|
+ width: 70,
|
|
|
+ height: 40,
|
|
|
attrs: {
|
|
|
+ // style: {
|
|
|
+ // visibility: 'hidden',
|
|
|
+ // },
|
|
|
body: {
|
|
|
rx: 10, // 圆角矩形
|
|
|
ry: 10,
|
|
|
strokeWidth: 1,
|
|
|
- stroke: 'rgba(95,149,255)',
|
|
|
+ stroke: '#07448a',
|
|
|
},
|
|
|
-
|
|
|
+ text: {
|
|
|
+ text: '可选',
|
|
|
+ },
|
|
|
+ fo: {
|
|
|
+ refWidth: '100%',
|
|
|
+ refHeight: '100%',
|
|
|
+ stroke: '#07448a', // 边框颜色
|
|
|
+ strokeWidth: 1,
|
|
|
+ },
|
|
|
+ foBody: {
|
|
|
+ xmlns: Dom.ns.xhtml,
|
|
|
+ style: {
|
|
|
+ width: '100%',
|
|
|
+ height: '100%',
|
|
|
+ display: 'flex',
|
|
|
+ justifyContent: 'center',
|
|
|
+ alignItems: 'center',
|
|
|
+ stroke: '#07448a', // 边框颜色
|
|
|
+ strokeWidth: 1,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'edit-text': {
|
|
|
+ contenteditable: 'true',
|
|
|
+ class: 'x6-edit-text',
|
|
|
+ style: {
|
|
|
+ width: '100%',
|
|
|
+ textAlign: 'center',
|
|
|
+ fontSize: 12,
|
|
|
+ color: 'rgba(0,0,0,0.85)',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ports: {
|
|
|
+ groups: {
|
|
|
+ // 输入链接桩群组定义
|
|
|
+ in: {
|
|
|
+ position: 'top',
|
|
|
+
|
|
|
+ attrs: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ circle: {
|
|
|
+ r: 4,
|
|
|
+ magnet: true,
|
|
|
+ stroke: '#5F95FF',
|
|
|
+ strokeWidth: 1,
|
|
|
+ fill: '#fff',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ // 输出链接桩群组定义
|
|
|
+ out: {
|
|
|
+ position: 'bottom',
|
|
|
+ attrs: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ circle: {
|
|
|
+ r: 4,
|
|
|
+ magnet: true,
|
|
|
+ stroke: '#5F95FF',
|
|
|
+ strokeWidth: 1,
|
|
|
+ fill: '#fff',
|
|
|
+ },
|
|
|
+ },
|
|
|
+
|
|
|
+ },
|
|
|
+ on: {
|
|
|
+ position: 'left',
|
|
|
+ attrs: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ circle: {
|
|
|
+ r:4,
|
|
|
+ magnet: true,
|
|
|
+ stroke: '#5F95FF',
|
|
|
+ strokeWidth: 1,
|
|
|
+ fill: '#fff',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ un: {
|
|
|
+ position: 'right',
|
|
|
+ attrs: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ circle: {
|
|
|
+ r: 4,
|
|
|
+ magnet: true,
|
|
|
+ stroke: '#5F95FF',
|
|
|
+ strokeWidth: 1,
|
|
|
+ fill: '#fff',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ items: [
|
|
|
+ {
|
|
|
+ id: 'port1',
|
|
|
+ group: 'in',
|
|
|
+ attrs: {
|
|
|
+ circle: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 'port2',
|
|
|
+ group: 'un',
|
|
|
+ attrs: {
|
|
|
+ circle: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 'port3',
|
|
|
+ group: 'on',
|
|
|
+ attrs: {
|
|
|
+ circle: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 'port4',
|
|
|
+ group: 'out',
|
|
|
+ attrs: {
|
|
|
+ circle: {
|
|
|
+ style: {
|
|
|
+ visibility: 'hidden',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
},
|
|
|
- label: '连接节点',
|
|
|
+ markup: [
|
|
|
+ {
|
|
|
+ tagName: 'rect',
|
|
|
+ selector: 'body',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: 'text',
|
|
|
+ selector: 'text',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: 'foreignObject',
|
|
|
+ selector: 'fo',
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ ns: Dom.ns.xhtml,
|
|
|
+ tagName: 'body',
|
|
|
+ selector: 'foBody',
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ tagName: 'div',
|
|
|
+ selector: 'edit-text',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ],
|
|
|
})
|
|
|
// 这里创新新的节点+++++++++++++
|
|
|
|
|
@@ -464,7 +840,7 @@ export default class FlowGraph {
|
|
|
// ports: { ...customPorts }
|
|
|
// })
|
|
|
// })
|
|
|
- this.stencil.load([r1, r2, r3, r4,r5,r6], 'basic')
|
|
|
+ this.stencil.load([r1, r2, r3, r4,r5,], 'basic')
|
|
|
// 这里需要注入新增节点,+++++++++++++++++
|
|
|
|
|
|
|
|
@@ -485,6 +861,7 @@ export default class FlowGraph {
|
|
|
ports[i].style.visibility = show ? 'visible' : 'hidden'
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
|
|
|
// 事件相关
|
|
|
static initEvent() {
|
|
@@ -492,7 +869,7 @@ export default class FlowGraph {
|
|
|
const container = document.getElementById('container')
|
|
|
// 右键编辑文本
|
|
|
graph.on('node:contextmenu', ({ cell, view }) => {
|
|
|
- console.log(view.container)
|
|
|
+ // console.log(view.container)
|
|
|
const oldText = cell.attr('text/text')
|
|
|
cell.attr('text/style/display', 'none')
|
|
|
const elem = view.container.querySelector('.x6-edit-text')
|
|
@@ -502,7 +879,7 @@ export default class FlowGraph {
|
|
|
}
|
|
|
const onBlur = () => {
|
|
|
cell.attr('text/text', elem.innerText)
|
|
|
- cell.attr('text/style/display', 'inline-block')
|
|
|
+ // cell.attr('text/style/display', 'inline-block')
|
|
|
}
|
|
|
if(elem){
|
|
|
elem.addEventListener('blur', () => {
|