vue+go.js:实现流程图

摘要:
转载自:https://www.cnblogs.com/sexintercourse/p/12456291.html步骤1:导入package.json以导入gojs依赖包--“gojs”:“^2.0.3”,(npminstallgojs--save)步骤2:运行以下代码

转载自:https://www.cnblogs.com/sexintercourse/p/12456291.html

第一步:引入package.json引入gojs依赖包-- "gojs": "^2.0.3", (npm install gojs --save)

第二步:运行下述代码

复制代码
<template>
    <div id="wrap">
        <div id="chart-wrap">
            <div id="chart-palette"></div>
            <div id="chart-diagram"></div>
        </div>
        <button @click="onSubmit"></button>
    </div>
    </div>
</template>
<script>
    import go from 'gojs'
    const MAKE = go.GraphObject.make;
    export default {
        data() {
            return {}
        },
        mounted() {
            var mySelf = this;
            mySelf.myDiagram = MAKE(go.Diagram, "chart-diagram", {
                initialContentAlignment: go.Spot.Center, // 居中显示
                "undoManager.isEnabled": true, // 支持 Ctrl-Z 和 Ctrl-Y 操作
                "toolManager.hoverDelay": 100, //tooltip提示显示延时
                "toolManager.toolTipDuration": 10000, //tooltip持续显示时间
                //isReadOnly:true,//只读
                "grid.visible": true, //显示网格
                allowMove: true, //允许拖动
                // allowDragOut:true,
                allowDelete: true,
                allowCopy: true,
                allowClipboard: true,
                "toolManager.mouseWheelBehavior": go.ToolManager.WheelZoom, //有鼠标滚轮事件放大和缩小,而不是向上和向下滚动
                layout: MAKE(go.TreeLayout, {
                    angle: 0,
                    layerSpacing: 35
                })
            }); //构建gojs对象
            console.log(mySelf.myDiagram);
            mySelf.myDiagram.addDiagramListener("ObjectSingleClicked", function(e) {
                debugger
                console.log(e.subject.part);
 
            });
 
            mySelf.myDiagram.addDiagramListener("BackgroundSingleClicked", function(e) {
                debugger
                console.log("Double-clicked at" + e.diagram.lastInput.documentPoint);
            });
 
            mySelf.myDiagram.addDiagramListener("ClipboardPasted", function(e) {
                debugger
                console.log("Pasted" + e.diagram.selection.count + "parts");
            });
 
            mySelf.myDiagram.linkTemplate = MAKE(go.Link, {
                    curve: go.Link.Bezier
                }, // 贝塞尔曲线
                {
                    routing: go.Link.Orthogonal,
                    corner: 15
                },
                MAKE(go.Shape, {
                    strokeWidth: 2,
                    stroke: "#F60"
                }),
                MAKE(go.Shape, {
                    toArrow: "Standard",
                    fill: "red",
                    stroke: "blue"
                }), //箭头
                MAKE(go.TextBlock, {
                        margin: 20,
                        stroke: "blue",
                        font: "14px sans-serif",
                         50,
                        wrap: go.TextBlock.WrapDesiredSize
                    },
                    new go.Binding("text", "linktext")), {
                    toolTip: MAKE(go.Adornment, "Auto",
                        MAKE(go.Shape, {
                            fill: "#FFFFCC"
                        }),
                        MAKE(go.TextBlock, {
                            margin: 4
                        }, new go.Binding("text", "name1"))
                    ) // end of Adornment
                }
            );
            let myModel = MAKE(go.GraphLinksModel); //也可以创建link model;需要配置myModel.linkDataArray 如下
            myModel.nodeDataArray = [];
            myModel.linkDataArray = [];
 
            var lightText = "whitesmoke";
            mySelf.myDiagram.nodeTemplateMap.add(
                "Next",
                MAKE(
                    go.Node,
                    "Spot",
                    // nodeStyle(),
                    MAKE( //声明创建一个新的面板对象,自定义方式可参考mySelf.myDiagram.nodeTemplate
                        go.Panel, //表明需要创建一个panel面板对象
                        "Auto", //页面布局为自动
                        MAKE( //声明构建一个圆角矩形
                            go.Shape,
                            "RoundedRectangle", {
                                fill: "#44CCFF",
                                stroke: '#FFF',
                                strokeWidth: 1,
                                angle: 0
                            },
                            new go.Binding("figure", "figure") //声明并创建一个新的图形
                        ),
                        MAKE( //声明一个可编辑文本域
                            go.TextBlock, {
                                font: "12pt Helvetica, Arial, sans-serif",
                                stroke: lightText,
                                 125,
                                maxSize: new go.Size(360, NaN),
                                wrap: go.TextBlock.WrapFit, //文本域换行
                                editable: true, //是否可编辑
                                margin: 12,
                                wrap: go.TextBlock.WrapDesiredSize
                            },
                            new go.Binding("text").makeTwoWay()
                        )
                    ),
                    // four named ports, one on each side:
                    makePort("T", go.Spot.Top, false, true),
                    makePort("L", go.Spot.Left, true, true),
                    makePort("R", go.Spot.Right, true, true),
                    makePort("B", go.Spot.Bottom, true, false)
                )
            );
 
            //Node连接线
            function makePort(name, spot, output, input) {
                return MAKE(go.Shape, "Circle", {
                    fill: "transparent",
                    stroke: null, // this is changed to "white" in the showPorts function
                    desiredSize: new go.Size(10, 10),
                    alignment: spot,
                    alignmentFocus: spot, // align the port on the main Shape
                    portId: name, // declare this object to be a "port"
                    fromSpot: spot,
                    toSpot: spot, // declare where links may connect at this port
                    fromLinkable: output,
                    toLinkable: input, // declare whether the user may draw links to/from here
                    cursor: "pointer" // show a different cursor to indicate potential link point
                });
            };
            mySelf.myDiagram.model = myModel;
            mySelf.init();
        },
        methods: {
            onSubmit() {
 
            },
            init() {
                var mySelf = this;
                window.myPalette = MAKE(
                    go.Palette,
                    "chart-palette", // must name or refer to the DIV HTML element
                    {
                        scrollsPageOnFocus: false,
                        nodeTemplateMap: mySelf.myDiagram.nodeTemplateMap, // share the templates used by myDiagram
                        model: new go.GraphLinksModel([
                            // specify the contents of the Palette
                            {
                                category: "Next",
                                text: "新规则"
                            }
                        ])
                    }
                );
            },
        }
    }
</script>
<style lang="less" scoped>
    #form-wrap {
        padding: 20px 40px;
        // background-color: white;
        border: solid 1px rgb(244, 244, 244);
    }
 
    #submit {
         102px;
        height: 40px;
        float: right;
        margin: 20px 5px 16px 0;
    }
 
    #chart-wrap {
         100%;
        display: flex;
        justify-content: space-between;
        margin-bottom: 22px;
 
        #chart-palette {
             180px;
            margin-right: 30px;
            background-color: white;
            border: solid 1px rgb(244, 244, 244);
        }
 
        #chart-diagram {
            flex-grow: 1;
            height: 720px;
            background-color: white;
            border: solid 1px rgb(244, 244, 244);
        }
    }
 
    #lateEntry {
        clear: both;
        background-color: rgb(255, 255, 255);
        border: solid 1px rgb(244, 244, 244);
 
        >span {
            display: inline-block;
            height: 50px;
            font-size: 16px;
            line-height: 50px;
            text-indent: 30px;
            letter-spacing: 0.8px;
            text-align: left;
            color: rgb(35, 35, 35);
            // border-bottom: 1px solid rgb(234, 234, 234);
        }
    }
</style>
复制代码

第三步:去水印

在哪个文件中找到破解的文件。 

在node_modulesgojs eleasego.js 下进行破解

  1. 在文件中搜索7eba17a4ca3b1a8346,找到类似a.$q=b.V[Za("7eba17a4ca3b1a8346")][Za("78a118b7")](b.V,yk,4,4);这样结构的代码
  2. 将其注释,替换成a.$q=function(){return true;};
  3. 直接npm install可以在module里寻找go.js文件,需修改的代码一般在769行

------拓展:相关构建gojs流程图时的某些参数及相关配置使用方式

复制代码
====================-构建gojs流程面板
import go from  'gojs'
const MAKE = go.GraphObject.make;
mySelf.myDiagram = MAKE(go.Diagram, "mygoChart", {
    initialContentAlignment: go.Spot.Center, // 居中显示
    "undoManager.isEnabled": true, // 支持 Ctrl-Z 和 Ctrl-Y 操作
    "toolManager.hoverDelay": 100, //tooltip提示显示延时
    "toolManager.toolTipDuration": 10000, //tooltip持续显示时间
    //isReadOnly:true,//只读
    "grid.visible": true, //显示网格
    allowMove: true, //允许拖动
    // allowDragOut:true,
    allowDelete: true,//允许删除
    allowCopy: true,//允许复制
    allowClipboard: false,//允许剪切
    "toolManager.mouseWheelBehavior": go.ToolManager.WheelZoom, //有鼠标滚轮事件放大和缩小,而不是向上和向下滚动
    layout: MAKE(go.TreeLayout, {//创建布局,示例为树
        angle: 0,    //角度
        layerSpacing: 35 //层间距
    })
}); //构建gojs对象
====================-
mySelf.myDiagram.nodeTemplateMap.add(: //声明左侧Node工具栏Tools
        "Next", // 关键参数,需要与init初始化时window.myPalette中model对象配置的category保持一致
         MAKE(
            go.Node, //
            "Spot",
            // nodeStyle(),
            MAKE(//声明创建一个新的面板对象,自定义方式可参考mySelf.myDiagram.nodeTemplate
                go.Panel, //表明需要创建一个panel面板对象
                "Auto",      //页面布局为自动
                MAKE(     //声明构建一个圆角矩形
                    go.Shape,
                    "RoundedRectangle", {
                        fill: "rgb(54, 128, 181)", //内填充颜色
                        stroke: null  //外边框颜色
                    },
                    new go.Binding("figure", "figure") //声明并创建一个新的图形
                ),
                MAKE(    //声明一个可编辑文本域
                    go.TextBlock, {
                        font: "11pt Helvetica, Arial, sans-serif",
                        stroke: lightText,
                        margin: 8,
                        maxSize: new go.Size(160, NaN),
                        wrap: go.TextBlock.WrapFit, //文本域换行
                        editable: true    //是否可编辑
                    },
                    new go.Binding("text").makeTwoWay()
                )
            ),
            makePort("T", go.Spot.Top, false, true),//创建Top顶端可延申链接点
            makePort("L", go.Spot.Left, true, true),//创建Left左端可延申链接点
            makePort("R", go.Spot.Right, true, true),//创建Righ右端可延申链接点
            makePort("B", go.Spot.Bottom, true, false)//创建Buttom底端可延申链接点
        )
    );
====================-自定义流程图流程节点相关配置
mySelf.myDiagram.nodeTemplate : 自定义流程图节点
    -> MAKE(go.Node,//声明创建的是node对象
        new go.Binding("location", "loc", go.Point.parse),//创建节点并设定节点的初始位置
        MAKE(go.Shape, "RoundedRectangle", {//构建节点的形状,示例为圆角矩形
            fill: "#44CCFF",//模块内填充颜色
            stroke: 'green',//外填充颜色(可理解为margin,也可以当成外边框颜色来理解)
            strokeWidth: 2,//外边框(填充)宽度
            angle: 0//模块形状的偏移量(角度)
       }),
       "Auto", //设置并定义节点模块内容布局走向:Vertical(垂直),Auto(自动),Horizontal(水平)
       { background: "#44CCFF" },//将Node背景底色渲染为蓝色
       MAKE(go.Picture,//构建Node区域图像类内容
            { source:"../assets/img/01.png",margin: 10,  50, height: 50, background: "red" },//基本参数设置
       new go.Binding("source")),//*Picture.source参数值与模型数据中的"source"字段绑定
       MAKE(go.TextBlock,//构建Node区域文本类内容
         "Default Text",  // 初始化默认文本
         // 文字周围的空隙, 大号字体, 白色笔画:
         { margin: 12, stroke: "white", font: "bold 16px sans-serif",
            75,
            wrap: go.TextBlock.WrapDesiredSize
         },
       new go.Binding("text", "name1")), // name1为linktext为nodeDataArray对象中的参数
       {
           mouseEnter: function(e, node, prev) {
               console.log('mouseEnter');//鼠标点击事件
           },
           mouseLeave: function(e, node, prev) {
               mySelf.detailShow = false;//鼠标移开事件
           },
       },
       MAKE(go.Panel, "Horizontal", {//创建并设置node内模板:实现Node块内的控件布局
               padding: 5
       },
====================-自定义流程图连接线相关配置
mySelf.myDiagram.linkTemplate:自定义流程图连接线
    -> { curve: go.Link.Bezier } : 设置并定义连接线曲线样式,示例为贝塞尔曲线
    -> MAKE(go.Shape, {
            strokeWidth: 2, //连接线宽(厚)度
            stroke: "#F60"//连接线笔画默认(未选中)颜色
        }) : 设置并定义连接线宽度及颜色
    -> MAKE(go.Shape, {
            toArrow: "Standard",//箭头样式,示例为标准
            fill: "#000",//箭头的填充颜色(内填充,可以理解为padding)
            stroke: null//连接线笔画默认(未选中)颜色,(外填充,可以理解为margin)
        }), //设置并定义箭头样式
    --> MAKE(go.TextBlock, { //文本块创建器
                margin: 20,//外边距,默认单位为px
                stroke: "blue",//字体颜色
                font: "14px sans-serif",//字体样式
                50,//内容宽度
                wrap: go.TextBlock.WrapDesiredSize//样式包装器
            },
            new go.Binding("text", "linktext")), { //创建并绑定显示的文本域信息,linktext为nodeDataArray对象中的参数
            toolTip: MAKE(go.Adornment, "Auto",
                    MAKE(go.Shape, {
                        fill: "#FFFFCC",//悬浮提示框内填充颜色
                    }),
                    MAKE(go.TextBlock, {
                        margin: 4 // 外边距
                    }, new go.Binding("text", "name1")) //创建并绑定显示的文本域信息,name1为nodeDataArray对象中的参数
                ) :设置并定义鼠标悬浮提示信息样式
            } : 设置并定义连接线指示及指针悬浮提示内容
=================-渲染数据相关配置
--> let myModel = MAKE(go.Model);//无连接线模型渲染
    let myModel = MAKE(go.GraphLinksModel);//指定连接(适用于复杂业务);需要配置myModel.linkDataArray
    let myModel = MAKE(go.TreeModel); //使用Tree树图模型渲染
--> myModel.nodeDataArray = [{},{},{}] : 流程节点数据(对象数组)
--> myModel.linkDataArray = [ {from:"1",to:"2"}, {from:"1",to:"2"}……] : 流程链接指示数组,用于构建各个node节点间的数据关系,需要使用go.GraphLinksModel
--> mySelf.myDiagram.model = myModel; 需渲染数据赋值
复制代码

免责声明:文章转载自《vue+go.js:实现流程图》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇scss 常用语法mongodb的增、删、改、插的一个实例下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

为什么每个前端开发者都要理解页面的渲染?

今天我要将关注点放到页面渲染以及其重要性上。虽然已经有很多文章提到过这个主题了,但大部分信息都是零碎的片段。为了思考这件事情,我需要研究很多信息的来源。这也就是为什么我觉得我应该写这篇文章的原因。我相信这篇文章对新手会很有用,并且对想刷新和巩固他们已经了解的东西的高手也同样适用。 渲染应该从最开始当页面布局被定义时就进行优化,样式和脚本在页面渲染中扮演着非...

Android SurfaceView播放视频时横竖屏的调整

对于横屏录制的视频就横屏播放,对于竖屏录制的视频就竖屏播放。 在mainifest文件里对负责播放的Activity添加以下属性“ android:configChanges="orientation|keyboardHidden|screenSize"  重写Acitivity的onConfigurationChanged方法: @Ov...

HTML标签CSS默认值研究

   最近写css的时候,发现在div元素里面添加ul元素后发现,ul列表在div里面距离最上方总是有一段空行,当时很奇怪,以为是哪个css出了问题,就把css去掉了,发现问题依旧,然后就查了一下发现html标签在不同浏览器里面是有默认的css样式的,要去掉默认样式,在样式表里添加 *{margin:0;padding:0;}即可,同时找到一个很有用的文档...

圣杯布局和双飞翼布局区别

圣杯布局和双飞翼布局实现的都是两边侧栏宽度固定,中间宽度自适应,效果如下: 圣杯布局是由国外的Kevin Cornell提出的一个布局模型概念,在国内由淘宝UED的工程师传播开来布局要求:1.三列布局,中间宽度自适应,两边定宽2.中间栏要在浏览器中优先渲染3.允许任意列的高度最高4.用最简单的CSS、最少的HACK语句 双飞翼布局是经淘宝UED工程师针对圣...

仿苹果电脑任务栏菜单&amp;amp;&amp;amp;拼图小游戏&amp;amp;&amp;amp;模拟表单控件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> &...

【使用 DOM】使用事件

1. 使用简单事件处理器 可以用几种不同的方式处理事件。最直接的方式是用事件属性创建一个简单事件处理器(simple event handler)。元素为它们支持的每一种事件都定义了一个事件属性。举个例子,onmouseover事件属性对应全局事件mouseover,后者会在用户把光标移动到元素占据的浏览器屏幕的上方时触发。(这是一种通用的模式:大多数事件...