|
|
@@ -28,930 +28,41 @@
|
|
|
</Layout>
|
|
|
</Layout>
|
|
|
<!-- 节点弹窗 -->
|
|
|
- <NodeModal :nodeData="{}"/>
|
|
|
+ <NodeModal/>
|
|
|
+ <!-- 连线弹窗 -->
|
|
|
+ <EdgeModal/>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
-import { Graph, Shape,FunctionExt } from '@antv/x6'
|
|
|
-import { Stencil } from '@antv/x6-plugin-stencil'
|
|
|
-import { Transform } from '@antv/x6-plugin-transform'
|
|
|
-import { Selection } from '@antv/x6-plugin-selection'
|
|
|
-import { Snapline } from '@antv/x6-plugin-snapline'
|
|
|
-import { Keyboard } from '@antv/x6-plugin-keyboard'
|
|
|
-import { Clipboard } from '@antv/x6-plugin-clipboard'
|
|
|
-import { History } from '@antv/x6-plugin-history'
|
|
|
-import { Export } from "@antv/x6-plugin-export";
|
|
|
-import { getImg } from '../../libs/base/x6-utils'
|
|
|
import {mapState, mapMutations} from 'vuex'
|
|
|
import NodeModal from '_c/business/process/node-modal/node-modal'
|
|
|
+import EdgeModal from '_c/business/process/edge-modal/edge-modal'
|
|
|
const insertCss = require('insert-css')
|
|
|
const zt1 = require('./zt1.json')
|
|
|
-import './NodeGroup'
|
|
|
-
|
|
|
+import Process from './index'
|
|
|
|
|
|
|
|
|
export default {
|
|
|
- components: { NodeModal },
|
|
|
+ components: { NodeModal,EdgeModal },
|
|
|
data() {
|
|
|
return {
|
|
|
graph: null,//图形对象
|
|
|
exportData: undefined,
|
|
|
importValue:undefined,
|
|
|
- ctrlPressed : false,//ctrl键是是否按下
|
|
|
- embedPadding : 30//群组padding
|
|
|
+ currentNode:{},
|
|
|
}
|
|
|
},
|
|
|
created() {},
|
|
|
mounted() {
|
|
|
- this.init()
|
|
|
+ //创建流程图对象
|
|
|
+ this.graph=Process.init(this.$refs.container)
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState(['process']),
|
|
|
},
|
|
|
methods: {
|
|
|
- ...mapMutations(['setProcessNodeModalDisplay']),
|
|
|
- /**
|
|
|
- * @desc : 初始化工艺流程图
|
|
|
- * @author : 张潇木
|
|
|
- * @date : 2023/1/3 11:46
|
|
|
- */
|
|
|
- init() {
|
|
|
-
|
|
|
- //region 插入动画样式
|
|
|
- insertCss(`
|
|
|
- @keyframes ant-line {
|
|
|
- to {
|
|
|
- stroke-dashoffset: -1000
|
|
|
- }
|
|
|
- }
|
|
|
- `)
|
|
|
- //endregion 不通过insertCss的方式,只写样式,动画无效
|
|
|
-
|
|
|
- // region 画布配置
|
|
|
- this.graph = new Graph({
|
|
|
- container: this.$refs.container,//获取节点
|
|
|
- background: {color: '#F2F7FA',},//画布背景色
|
|
|
- autoResize:true,//自动设置宽高
|
|
|
- panning: {//开启拖拽画布
|
|
|
- enabled: true,
|
|
|
- eventTypes: 'rightMouseDown',//触发画布平移的交互方式为“右键按下”
|
|
|
- },
|
|
|
- grid: {//设置网格
|
|
|
- size: 10,
|
|
|
- visible: true,
|
|
|
- type: "doubleMesh",
|
|
|
- args: [
|
|
|
- {
|
|
|
- color: "#eee", // 主网格线颜色
|
|
|
- thickness: 1, // 主网格线宽度
|
|
|
- },
|
|
|
- {
|
|
|
- color: "#ddd", // 次网格线颜色
|
|
|
- thickness: 1, // 次网格线宽度
|
|
|
- factor: 4, // 主次网格线间隔
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- mousewheel: {//鼠标滚轮缩放画布
|
|
|
- enabled: true,
|
|
|
- zoomAtMousePosition: true,
|
|
|
- modifiers: 'ctrl',
|
|
|
- minScale: 0.5,
|
|
|
- maxScale: 3,
|
|
|
- factor: 1.1,//滚动缩放因子。默认为 1.2
|
|
|
- },
|
|
|
- connecting: {
|
|
|
- line: {
|
|
|
- stroke: '#A2B1C3',
|
|
|
- strokeWidth: 3,
|
|
|
- strokeDasharray: 5,
|
|
|
- style: {
|
|
|
- animation: 'ant-line 30s infinite linear',
|
|
|
- },
|
|
|
- },
|
|
|
- router: {
|
|
|
- name: 'metro',
|
|
|
- },
|
|
|
- connector: {
|
|
|
- name: 'jumpover',
|
|
|
- args: {
|
|
|
- radius: 8,
|
|
|
- size:12,
|
|
|
- },
|
|
|
- },
|
|
|
- anchor: 'center',
|
|
|
- connectionPoint: 'anchor',
|
|
|
- allowBlank: false,
|
|
|
- snap: {
|
|
|
- radius: 20,
|
|
|
- },
|
|
|
- createEdge() {
|
|
|
- return new Shape.Edge({
|
|
|
- attrs: {
|
|
|
- line: {
|
|
|
- stroke: '#A2B1C3',
|
|
|
- strokeWidth: 3,
|
|
|
- strokeDasharray: 6,
|
|
|
- style: {
|
|
|
- animation: 'ant-line 30s infinite linear',
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- zIndex: 0,
|
|
|
- router: {
|
|
|
- name: 'metro',
|
|
|
- },
|
|
|
- connector: {
|
|
|
- name: 'jumpover',
|
|
|
- args: {
|
|
|
- radius: 8,
|
|
|
- size:12,
|
|
|
- },
|
|
|
- },
|
|
|
- })
|
|
|
- },
|
|
|
- validateConnection({ targetMagnet }) {
|
|
|
- return !!targetMagnet
|
|
|
- },
|
|
|
- },
|
|
|
- highlighting: {//高亮
|
|
|
- magnetAdsorbed: {//连线过程中,自动吸附到连接桩时被使用
|
|
|
- name: 'stroke',
|
|
|
- args: {
|
|
|
- attrs: {
|
|
|
- "stroke-width": 2,
|
|
|
- fill: '#5F95FF',
|
|
|
- stroke: 'white',
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- embedding: {//是否开启嵌套节点
|
|
|
- enabled: true,
|
|
|
- findParent({ node }) {
|
|
|
- const bbox = node.getBBox()
|
|
|
- return this.getNodes().filter((n) => {
|
|
|
- // 如果拖拽的节点本身就是一个节点组,则不允许进入另一个节点组中
|
|
|
- if(node.data&&node.data.parent){
|
|
|
- return false
|
|
|
- }
|
|
|
- // 只有 data.parent 为 true 的节点才是父节点
|
|
|
- const data = n.getData()
|
|
|
- if (data && data.parent) {
|
|
|
- const targetBBox = n.getBBox()
|
|
|
- return bbox.isIntersectWithRect(targetBBox)
|
|
|
- }
|
|
|
- return false
|
|
|
- })
|
|
|
- },
|
|
|
- },
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 注册插件
|
|
|
- this.graph.use(new Transform({
|
|
|
- resizing: true,
|
|
|
- rotating: true,
|
|
|
- }))
|
|
|
- .use(new Selection({
|
|
|
- enabled: true,
|
|
|
- multiple: true,//是否启用点击多选,启用后按住 ctrl 或 command 键点击节点实现多选
|
|
|
- rubberband: true,//是否启用多选节点功能
|
|
|
- showNodeSelectionBox: true,//是否显示节点的选择框
|
|
|
- }))
|
|
|
- .use(new Snapline({
|
|
|
- enabled: true,
|
|
|
- }))
|
|
|
- .use(new Keyboard({
|
|
|
- enabled: true,
|
|
|
- }))
|
|
|
- .use(new Clipboard({
|
|
|
- enabled: true,
|
|
|
- }))
|
|
|
- .use(new History({
|
|
|
- enabled: true,
|
|
|
- }))
|
|
|
- .use(new Export({
|
|
|
- enabled:true
|
|
|
- }
|
|
|
- ));
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 左侧工具栏配置
|
|
|
- const stencil = new Stencil({
|
|
|
- title: '工艺模型',
|
|
|
- target: this.graph,
|
|
|
- stencilGraphWidth: 200,
|
|
|
- stencilGraphHeight: 180,
|
|
|
- collapsable: true,
|
|
|
- groups: [
|
|
|
- {
|
|
|
- title: '节点组',
|
|
|
- name: 'group',
|
|
|
- graphHeight: 80,
|
|
|
- layoutOptions: {
|
|
|
- columns: 1,
|
|
|
- marginX: 35,
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- title: '特殊模型',
|
|
|
- name: 'c4',
|
|
|
- graphHeight: 450,
|
|
|
- layoutOptions: {
|
|
|
- rowHeight: 70,
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- title: '计件模型',
|
|
|
- name: 'c1',
|
|
|
- },
|
|
|
- {
|
|
|
- title: '检验模型',
|
|
|
- name: 'c2',
|
|
|
- },
|
|
|
- {
|
|
|
- title: '报损模型',
|
|
|
- name: 'c3',
|
|
|
- },
|
|
|
- ],
|
|
|
- layoutOptions: {
|
|
|
- columns: 2,
|
|
|
- columnWidth: 80,
|
|
|
- rowHeight: 55,
|
|
|
- },
|
|
|
- placeholder:'搜索...',
|
|
|
- notFoundText:'未搜索到结果',
|
|
|
- //搜索方法
|
|
|
- search: (cell, keyword, groupName, stencil) => {
|
|
|
- if (keyword) {
|
|
|
- return cell.attr("text/text").includes(keyword);
|
|
|
- }
|
|
|
- return true;
|
|
|
- },
|
|
|
- // getDropNode(node) {
|
|
|
- // console.log(node.prop())
|
|
|
- // }
|
|
|
- })
|
|
|
- document.getElementById('stencil').appendChild(stencil.container)
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 注册快捷键与事件
|
|
|
-
|
|
|
- // region 复制
|
|
|
- this.graph.bindKey(['meta+c', 'ctrl+c'], () => {
|
|
|
- const cells = this.graph.getSelectedCells()
|
|
|
- if (cells.length) {
|
|
|
- this.graph.copy(cells)
|
|
|
- }
|
|
|
- return false
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 剪切
|
|
|
- this.graph.bindKey(['meta+x', 'ctrl+x'], () => {
|
|
|
- const cells = this.graph.getSelectedCells()
|
|
|
- if (cells.length) {
|
|
|
- this.graph.cut(cells)
|
|
|
- }
|
|
|
- return false
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 粘贴
|
|
|
- this.graph.bindKey(['meta+v', 'ctrl+v'], () => {
|
|
|
- if (!this.graph.isClipboardEmpty()) {
|
|
|
- const cells = this.graph.paste({ offset: 32 })
|
|
|
- this.graph.cleanSelection()
|
|
|
- this.graph.select(cells)
|
|
|
- }
|
|
|
- return false
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 撤销
|
|
|
- this.graph.bindKey(['meta+z', 'ctrl+z'], () => {
|
|
|
- if (this.graph.canUndo()) {
|
|
|
- this.graph.undo()
|
|
|
- }
|
|
|
- return false
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 撤回撤销
|
|
|
- this.graph.bindKey(['meta+shift+z', 'ctrl+shift+z'], () => {
|
|
|
- if (this.graph.canRedo()) {
|
|
|
- this.graph.redo()
|
|
|
- }
|
|
|
- return false
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 全选
|
|
|
- this.graph.bindKey(['meta+alt+a', 'ctrl+alt+a'], () => {
|
|
|
- const nodes = this.graph.getNodes()
|
|
|
- if (nodes) {
|
|
|
- this.graph.select(nodes)
|
|
|
- }
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 删除
|
|
|
- this.graph.bindKey(['backspace','del'], () => {
|
|
|
- const cells = this.graph.getSelectedCells()
|
|
|
- if (cells.length) {
|
|
|
- this.graph.removeCells(cells)
|
|
|
- }
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 调整大小
|
|
|
- this.graph.bindKey(['ctrl+alt++', 'meta++'], () => {
|
|
|
- const zoom = this.graph.zoom()
|
|
|
- if (zoom < 1.5) {
|
|
|
- this.graph.zoom(0.1)
|
|
|
- }
|
|
|
- })
|
|
|
- this.graph.bindKey(['ctrl+alt+-', 'meta+-'], () => {
|
|
|
- const zoom = this.graph.zoom()
|
|
|
- if (zoom > 0.5) {
|
|
|
- this.graph.zoom(-0.1)
|
|
|
- }
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 向上移动
|
|
|
- this.graph.bindKey(['up'], () => {
|
|
|
- const cells = this.graph.getSelectedCells()
|
|
|
- if (cells.length) {
|
|
|
- cells.forEach(cell=>{
|
|
|
- const y = cell.prop().position.y
|
|
|
- const x = cell.prop().position.x
|
|
|
- cell.prop("position", { x: x, y: y-5 });
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 向下移动
|
|
|
- this.graph.bindKey(['down'], () => {
|
|
|
- const cells = this.graph.getSelectedCells()
|
|
|
- if (cells.length) {
|
|
|
- cells.forEach(cell=>{
|
|
|
- const y = cell.prop().position.y
|
|
|
- const x = cell.prop().position.x
|
|
|
- cell.prop("position", { x: x, y: y+5 });
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 向左移动
|
|
|
- this.graph.bindKey(['left'], () => {
|
|
|
- const cells = this.graph.getSelectedCells()
|
|
|
- if (cells.length) {
|
|
|
- cells.forEach(cell=>{
|
|
|
- const y = cell.prop().position.y
|
|
|
- const x = cell.prop().position.x
|
|
|
- cell.prop("position", { x: x-5, y: y });
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 向右移动
|
|
|
- this.graph.bindKey(['right'], () => {
|
|
|
- const cells = this.graph.getSelectedCells()
|
|
|
- if (cells.length) {
|
|
|
- cells.forEach(cell=>{
|
|
|
- const y = cell.prop().position.y
|
|
|
- const x = cell.prop().position.x
|
|
|
- cell.prop("position", { x: x+5, y: y });
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 鼠标移入移出 连接桩显示/隐藏
|
|
|
- this.graph.on('node:mouseenter', FunctionExt.debounce(() => {
|
|
|
- const ports = this.$refs.container.querySelectorAll('.x6-port-body')
|
|
|
- this.showPorts(ports, true)
|
|
|
- }), 500,)
|
|
|
-
|
|
|
- this.graph.on('node:mouseleave', () => {
|
|
|
- const ports = this.$refs.container.querySelectorAll('.x6-port-body')
|
|
|
- this.showPorts(ports, false)
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 鼠标移入移出 动态添加连接线托拽工具
|
|
|
- this.graph.on('edge:mouseenter', ({ cell }) => {
|
|
|
- cell.addTools([
|
|
|
- {
|
|
|
- name: 'vertices',
|
|
|
- args: {
|
|
|
- // 移动路径点过程中的吸附半径。当路径点与邻近的路径点的某个坐标 (x, y) 距离在半径范围内时,将当前路径点的对应坐标 (x, y) 吸附到邻居路径的路径点。
|
|
|
- snapRadius: 5,
|
|
|
- // 在边上按下鼠标时,是否可以添加新的路径点。
|
|
|
- addable: true,
|
|
|
- // 是否可以通过双击移除路径点。
|
|
|
- removable: true,
|
|
|
- // 是否自动移除冗余的路径点。
|
|
|
- removeRedundancies: true,
|
|
|
- // 是否阻止工具上的鼠标事件冒泡到边视图上。阻止后鼠标与工具交互时将不会触发边的 mousedown、mousemove 和 mouseup 事件。
|
|
|
- stopPropagation: false
|
|
|
- }
|
|
|
- }
|
|
|
- ])
|
|
|
- })
|
|
|
- this.graph.on('edge:mouseleave', ({ cell }) => {
|
|
|
- cell.removeTools()
|
|
|
- })
|
|
|
- //endregion
|
|
|
-
|
|
|
- // region 右键连接线进入编辑模式
|
|
|
- this.graph.on('edge:contextmenu', ({ cell, e }) => {
|
|
|
- console.log("右键连线-prop",cell.prop())
|
|
|
- console.log("右键连线-attr",cell.attr())
|
|
|
- console.log("右键连线-data",cell.data)
|
|
|
- cell.addTools({
|
|
|
- name: 'edge-editor',
|
|
|
- args: {
|
|
|
- event: e,
|
|
|
- },
|
|
|
- })
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 双击节点进入编辑模式
|
|
|
- this.graph.on('node:dblclick', ({ node, e }) => {
|
|
|
- console.log("双击节点-id",node.id)
|
|
|
- console.log("双击节点-prop",node.prop())
|
|
|
- // console.log("双击节点-attr",node.attr())
|
|
|
- // console.log("双击节点-data",node.data)
|
|
|
- //如果是节点组,不打开弹窗
|
|
|
- if (node.data && node.data.parent) {
|
|
|
- return;
|
|
|
- }
|
|
|
- // this.setProcessNodeModalDisplay(true)
|
|
|
-
|
|
|
- // node.addTools({
|
|
|
- // name: 'node-editor',
|
|
|
- // args: {
|
|
|
- // event: e,
|
|
|
- // },
|
|
|
- // })
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 节点组展开/收起
|
|
|
- this.graph.on('node:collapse', ({ node, e }) => {
|
|
|
- e.stopPropagation()
|
|
|
- node.toggleCollapse()
|
|
|
- const collapsed = node.isCollapsed()
|
|
|
- const cells = node.getDescendants()
|
|
|
- // console.log('collapse',node)
|
|
|
- // console.log('getDescendants',cells)
|
|
|
- cells.forEach(n => {
|
|
|
- if (collapsed) {
|
|
|
- n.hide()
|
|
|
- } else {
|
|
|
- n.show()
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 节点的父级发生改变
|
|
|
- this.graph.on('node:change:parent', ({ node }) => {
|
|
|
- // console.log('change:parent',node)
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 节点的子级发生改变
|
|
|
- this.graph.on('node:change:children',({node,previous,current})=>{
|
|
|
- if(previous&¤t&&previous.length>current.length){
|
|
|
- console.log('移出')
|
|
|
- this.getSelectedCells().forEach(it=>{
|
|
|
- node.unembed(it);
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 节点的移入事件(父级、嵌套关系发生改变)
|
|
|
- this.graph.on('node:embedded',({node})=>{
|
|
|
- // debugger
|
|
|
- console.log("embedded",node.id,node.getParent())
|
|
|
- //如果所选所有节点的parent都一致,直接return
|
|
|
- let cells=this.getSelectedCells()
|
|
|
- if(cells.some((e) => cells.filter((e1) => e1.getParent() !== e.getParent()).length >0 )){
|
|
|
- console.log('存在不相同')
|
|
|
- let parent=node.getParent()
|
|
|
- let other =cells.filter((c) => c.id!==node.id)
|
|
|
- other.forEach(it=>{
|
|
|
- parent.embed(it);
|
|
|
- })
|
|
|
- }else{
|
|
|
- console.log('都相同')
|
|
|
- // return
|
|
|
- }
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 根据群组内部节点位置动态调整群组宽高
|
|
|
- this.graph.on('node:embedding', ({ e }) => {
|
|
|
- this.ctrlPressed = e.metaKey || e.ctrlKey
|
|
|
- })
|
|
|
-
|
|
|
- this.graph.on('node:embedded', () => {
|
|
|
- this.ctrlPressed = false
|
|
|
- })
|
|
|
-
|
|
|
- this.graph.on('node:change:size', ({ node, options }) => {
|
|
|
- if (options.skipParentHandler) {
|
|
|
- return
|
|
|
- }
|
|
|
|
|
|
- const children = node.getChildren()
|
|
|
- if (children && children.length) {
|
|
|
- node.prop('originSize', node.getSize())
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- this.graph.on('node:change:position', ({ node, options }) => {
|
|
|
- if (options.skipParentHandler || this.ctrlPressed) {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- const children = node.getChildren()
|
|
|
- if (children && children.length) {
|
|
|
- node.prop('originPosition', node.getPosition())
|
|
|
- }
|
|
|
-
|
|
|
- const parent = node.getParent()
|
|
|
- if (parent && parent.isNode()) {
|
|
|
- let originSize = parent.prop('originSize')
|
|
|
- if (originSize == null) {
|
|
|
- originSize = parent.getSize()
|
|
|
- parent.prop('originSize', originSize)
|
|
|
- }
|
|
|
-
|
|
|
- let originPosition = parent.prop('originPosition')
|
|
|
- if (originPosition == null) {
|
|
|
- originPosition = parent.getPosition()
|
|
|
- parent.prop('originPosition', originPosition)
|
|
|
- }
|
|
|
-
|
|
|
- let x = originPosition.x
|
|
|
- let y = originPosition.y
|
|
|
- let cornerX = originPosition.x + originSize.width
|
|
|
- let cornerY = originPosition.y + originSize.height
|
|
|
- let hasChange = false
|
|
|
-
|
|
|
- const children = parent.getChildren()
|
|
|
- if (children) {
|
|
|
- children.forEach((child) => {
|
|
|
- const bbox = child.getBBox().inflate(this.embedPadding)
|
|
|
- const corner = bbox.getCorner()
|
|
|
-
|
|
|
- if (bbox.x < x) {
|
|
|
- x = bbox.x
|
|
|
- hasChange = true
|
|
|
- }
|
|
|
-
|
|
|
- if (bbox.y < y) {
|
|
|
- y = bbox.y
|
|
|
- hasChange = true
|
|
|
- }
|
|
|
-
|
|
|
- if (corner.x > cornerX) {
|
|
|
- cornerX = corner.x
|
|
|
- hasChange = true
|
|
|
- }
|
|
|
-
|
|
|
- if (corner.y > cornerY) {
|
|
|
- cornerY = corner.y
|
|
|
- hasChange = true
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- if (hasChange) {
|
|
|
- parent.prop(
|
|
|
- {
|
|
|
- position: { x, y },
|
|
|
- size: { width: cornerX - x, height: cornerY - y },
|
|
|
- },
|
|
|
- { skipParentHandler: true },
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 将添加的节点组置为最底层
|
|
|
- this.graph.on("node:added", ({ node }) => {
|
|
|
- if (node.data && node.data.parent) {
|
|
|
- node.toBack()
|
|
|
- }
|
|
|
- });
|
|
|
- // endregion
|
|
|
-
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 图形配置
|
|
|
-
|
|
|
- // region 节点上下左右的四个连接桩
|
|
|
- const ports = {
|
|
|
- groups: {
|
|
|
- top: {
|
|
|
- position: 'top',
|
|
|
- attrs: {
|
|
|
- circle: {
|
|
|
- r: 4,
|
|
|
- magnet: true,
|
|
|
- stroke: '#5F95FF',
|
|
|
- strokeWidth: 1,
|
|
|
- fill: '#fff',
|
|
|
- style: {
|
|
|
- visibility: 'hidden',
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- right: {
|
|
|
- position: 'right',
|
|
|
- attrs: {
|
|
|
- circle: {
|
|
|
- r: 4,
|
|
|
- magnet: true,
|
|
|
- stroke: '#5F95FF',
|
|
|
- strokeWidth: 1,
|
|
|
- fill: '#fff',
|
|
|
- style: {
|
|
|
- visibility: 'hidden',
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- bottom: {
|
|
|
- position: 'bottom',
|
|
|
- attrs: {
|
|
|
- circle: {
|
|
|
- r: 4,
|
|
|
- magnet: true,
|
|
|
- stroke: '#5F95FF',
|
|
|
- strokeWidth: 1,
|
|
|
- fill: '#fff',
|
|
|
- style: {
|
|
|
- visibility: 'hidden',
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- left: {
|
|
|
- position: 'left',
|
|
|
- attrs: {
|
|
|
- circle: {
|
|
|
- r: 4,
|
|
|
- magnet: true,
|
|
|
- stroke: '#5F95FF',
|
|
|
- strokeWidth: 1,
|
|
|
- fill: '#fff',
|
|
|
- style: {
|
|
|
- visibility: 'hidden',
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- items: [
|
|
|
- {
|
|
|
- group: 'top',
|
|
|
- },
|
|
|
- {
|
|
|
- group: 'right',
|
|
|
- },
|
|
|
- {
|
|
|
- group: 'bottom',
|
|
|
- },
|
|
|
- {
|
|
|
- group: 'left',
|
|
|
- },
|
|
|
- ],
|
|
|
- }
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 注册自定义节点
|
|
|
- Graph.registerNode(
|
|
|
- 'custom-rect',
|
|
|
- {
|
|
|
- inherit: 'rect',
|
|
|
- width: 66,
|
|
|
- height: 36,
|
|
|
- attrs: {
|
|
|
- body: {
|
|
|
- strokeWidth: 1,
|
|
|
- stroke: '#5F95FF',
|
|
|
- fill: '#EFF4FF',
|
|
|
- },
|
|
|
- text: {
|
|
|
- fontSize: 12,
|
|
|
- fill: '#262626',
|
|
|
- },
|
|
|
- },
|
|
|
- ports: { ...ports },
|
|
|
- },
|
|
|
- true,
|
|
|
- )
|
|
|
-
|
|
|
- Graph.registerNode(
|
|
|
- 'custom-polygon',
|
|
|
- {
|
|
|
- inherit: 'polygon',
|
|
|
- width: 66,
|
|
|
- height: 36,
|
|
|
- attrs: {
|
|
|
- body: {
|
|
|
- strokeWidth: 1,
|
|
|
- stroke: '#5F95FF',
|
|
|
- fill: '#EFF4FF',
|
|
|
- },
|
|
|
- text: {
|
|
|
- fontSize: 12,
|
|
|
- fill: '#262626',
|
|
|
- },
|
|
|
- },
|
|
|
- ports: {
|
|
|
- ...ports,
|
|
|
- items: [
|
|
|
- {
|
|
|
- group: 'top',
|
|
|
- },
|
|
|
- {
|
|
|
- group: 'bottom',
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- },
|
|
|
- true,
|
|
|
- )
|
|
|
-
|
|
|
- Graph.registerNode(
|
|
|
- 'custom-circle',
|
|
|
- {
|
|
|
- inherit: 'circle',
|
|
|
- width: 45,
|
|
|
- height: 45,
|
|
|
- attrs: {
|
|
|
- body: {
|
|
|
- strokeWidth: 1,
|
|
|
- stroke: '#5F95FF',
|
|
|
- fill: '#EFF4FF',
|
|
|
- },
|
|
|
- text: {
|
|
|
- fontSize: 12,
|
|
|
- fill: '#262626',
|
|
|
- },
|
|
|
- },
|
|
|
- ports: { ...ports },
|
|
|
- },
|
|
|
- true,
|
|
|
- )
|
|
|
-
|
|
|
- Graph.registerNode(
|
|
|
- 'custom-image',
|
|
|
- {
|
|
|
- inherit: 'rect',
|
|
|
- width: 64,
|
|
|
- height: 64,
|
|
|
- markup: [
|
|
|
- {
|
|
|
- tagName: 'rect',
|
|
|
- selector: 'body',
|
|
|
- },
|
|
|
- {
|
|
|
- tagName: 'image',
|
|
|
- },
|
|
|
- {
|
|
|
- tagName: 'text',
|
|
|
- selector: 'label',
|
|
|
- },
|
|
|
- ],
|
|
|
- attrs: {
|
|
|
- body: {
|
|
|
- stroke: '#87CEFA',
|
|
|
- fill: '#1E90FF',
|
|
|
- },
|
|
|
- image: {
|
|
|
- width: 32,
|
|
|
- height: 32,
|
|
|
- refX: 22,
|
|
|
- refY: 22,
|
|
|
- },
|
|
|
- label: {
|
|
|
- refX:6,
|
|
|
- refY:6,
|
|
|
- textAnchor: 'left',
|
|
|
- textVerticalAnchor: 'top',
|
|
|
- fontSize: 12,
|
|
|
- fill: '#fff',
|
|
|
- },
|
|
|
- },
|
|
|
- ports: { ...ports },
|
|
|
- },
|
|
|
- true,
|
|
|
- )
|
|
|
-
|
|
|
-
|
|
|
- // region 节点组
|
|
|
- const g1 = this.graph.createNode({
|
|
|
- shape: 'groupNode',
|
|
|
- zIndex: 0,
|
|
|
- attrs: {
|
|
|
- text: {
|
|
|
- text: '节点组',
|
|
|
- },
|
|
|
- },
|
|
|
- data: {
|
|
|
- parent: true,
|
|
|
- },
|
|
|
- })
|
|
|
- stencil.load([g1], 'group')
|
|
|
- // endregion
|
|
|
-
|
|
|
- // endregion
|
|
|
-
|
|
|
- //region 创建工艺节点图元素节点
|
|
|
- const imageShapes = [
|
|
|
- {
|
|
|
- label: '交坯',
|
|
|
- image:getImg('交坯.png'),
|
|
|
- },
|
|
|
- {
|
|
|
- label: '半检',
|
|
|
- image:getImg('检查.png'),
|
|
|
- },
|
|
|
- {
|
|
|
- label: '施釉',
|
|
|
- image:getImg('喷雾.png'),
|
|
|
- },
|
|
|
- {
|
|
|
- label: '质量登记',
|
|
|
- image:getImg('登记.png'),
|
|
|
- },
|
|
|
- {
|
|
|
- label: '入窑',
|
|
|
- image:getImg('火炉.png'),
|
|
|
- },
|
|
|
- {
|
|
|
- label: '卸窑',
|
|
|
- image:getImg('装卸.png'),
|
|
|
-
|
|
|
- },
|
|
|
- {
|
|
|
- label: '重烧',
|
|
|
- image:getImg('火炉.png'),
|
|
|
- },
|
|
|
- {
|
|
|
- label: '包装',
|
|
|
- image:getImg('打包.png'),
|
|
|
- },
|
|
|
- {
|
|
|
- label: '回收',
|
|
|
- image:getImg('回收.png'),
|
|
|
-
|
|
|
- },
|
|
|
- {
|
|
|
- label: '干补',
|
|
|
- image:getImg('马桶.png'),
|
|
|
- },
|
|
|
- {
|
|
|
- label: '烘干',
|
|
|
- image:getImg('烘干.png'),
|
|
|
- },
|
|
|
- {
|
|
|
- label: '打磨',
|
|
|
- image:getImg('打磨.png'),
|
|
|
- },
|
|
|
- ]
|
|
|
- const imageNodes = imageShapes.map((item) =>
|
|
|
- this.graph.createNode({
|
|
|
- shape: 'custom-image',
|
|
|
- label: item.label,
|
|
|
- attrs: {
|
|
|
- image: {
|
|
|
- 'xlink:href': item.image,
|
|
|
- },
|
|
|
- },
|
|
|
- // shape: 'image', //可选值:Rect Circle Ellipse Polygon Polyline Path Image HTML TextBlock BorderedImage EmbeddedImage InscribedImage Cylinder
|
|
|
- // imageUrl: item.image,
|
|
|
- // width: 52,
|
|
|
- // height: 52,
|
|
|
- }),
|
|
|
- )
|
|
|
- stencil.load(imageNodes, 'c4')
|
|
|
- //endregion
|
|
|
-
|
|
|
- // endregion
|
|
|
+ init() {
|
|
|
|
|
|
// region 初始化数据
|
|
|
// this.graph.fromJSON(zt1)
|
|
|
@@ -961,19 +72,6 @@ export default {
|
|
|
|
|
|
},
|
|
|
|
|
|
- // region 显示/隐藏连接桩事件
|
|
|
- showPorts(ports, show) {
|
|
|
- for (let i = 0, len = ports.length; i < len; i = i + 1) {
|
|
|
- ports[i].style.visibility = show ? 'visible' : 'hidden'
|
|
|
- }
|
|
|
- },
|
|
|
- // endregion
|
|
|
-
|
|
|
- // region 获取所有选中的节点
|
|
|
- getSelectedCells() {
|
|
|
- return this.graph.getSelectedCells();
|
|
|
- },
|
|
|
- // endregion
|
|
|
|
|
|
}
|
|
|
}
|