最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

GOJS+VUE實現(xiàn)流程圖效果

 更新時間:2018年12月01日 15:35:20   作者:cicistream  
這篇文章主要為大家詳細介紹了GOJS+VUE實現(xiàn)流程圖效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下

前言及展示

在項目中需要根據(jù)傳過來的數(shù)據(jù)畫出流程圖,采用了GOJS插件,功能很全面,可以根據(jù)自己的需要調(diào)整,不過建議簡單的流程圖還是自己手寫一個組件,更加便于維護和變換。有一點需要注意的是,GOJS是需要收費的,有水印,雖然可以手動去掉,但是公司用的話還是需要買。GOJS的官網(wǎng)上有關(guān)于在VUE中應(yīng)用GOJS的小例子:Minimal GoJS Sample in Vue.js。推薦看一下,可以解決大部分簡單需求,這個例子可以滿足你并行步驟數(shù)比較固定的二叉樹畫法的流程圖。

這是官網(wǎng)的例子,其中模塊,線,箭頭等畫布元素都可以交互。
由于我的并行步驟數(shù)不固定,于是在圖中加入了Group(組)。先展示一下成品:

其中批次中可以包含多個項目,表示并行的步驟。

具體實現(xiàn)

分為兩個文件:
diagram.vue && stepMap.vue
diagram.vue聲明組件,stepMap引用

diagram.vue

基本聲明:

<script>
 import go from 'gojs';
 let $ = go.GraphObject.make; // 后面很多用到該變量來初始化diagram
 export default{
  name: 'diagram',
  props: ['modelData'], // accept model data as a parameter
  data() {
   return {
   diagram: null,
   }; 
  }, // provide access to the GoJS Diagram

初始化diagram:

mounted: function() {
  let self = this;
  let myDiagram =
   $(go.Diagram, this.$el,
   {
    'initialContentAlignment': go.Spot.Center,
    'isEnabled': false, // 是否可拖拽,默認為是
    // 'toolManager.mouseWheelBehavior': go.ToolManager.WheelNone,
    'allowLink': false, 
    'allowMove': false,
    'allowRelink': false, // 由于項目只想展示數(shù)據(jù),我禁用了大部分圖像交互操作,具體可參看官網(wǎng)API
    'layout': $(go.TreeLayout, {angle: 0, arrangement: go.TreeLayout.ArrangementHorizontal}),  // angle可控制圖像展示方向
    'undoManager.isEnabled': true,
    // Model ChangedEvents get passed up to component users
    'ChangedSelection': function(e) {
     self.$emit('changed-selection', e); 
    },
   });
   
  myDiagram.nodeTemplate = // 節(jié)點的初始化設(shè)置
   $(go.Node, 'Auto',
   $(go.Shape, // 節(jié)點形狀設(shè)置
   {
    fill: 'white', strokeWidth: 1,
    portId: '', fromLinkable: true, toLinkable: true, cursor: 'pointer',
   },
    new go.Binding('fill', '', this.nodeColorConverter)), // nodeColorConverter是我自定義函數(shù),根據(jù)節(jié)點狀態(tài)設(shè)置節(jié)點的背景顏色
   $(go.TextBlock, // 節(jié)點提示文字設(shè)置
    {margin: 16, editable: false},
    new go.Binding('text').makeTwoWay())
   );

  myDiagram.linkTemplate =
   $(go.Link,
   {relinkableFrom: true, relinkableTo: true},
   $(go.Shape, // 連線形狀設(shè)置
   {strokeWidth: 2},
   new go.Binding('stroke', '', this.linkColorConverter)), // 連線的顏色設(shè)置
   $(go.Shape, // arrowhead
   {toArrow: 'Triangle', stroke: null, scale: 1.5}, // 箭頭設(shè)置
   new go.Binding('fill', '', this.linkColorConverter))
   );
  
  myDiagram.groupTemplate = // 分組的初始化
   $(go.Group, 'Auto',
    { // define the group's internal layout
    layout: $(go.TreeLayout,
       {angle: 90, arrangement: go.TreeLayout.ArrangementVertical, isRealtime: false}),
    // the group begins unexpanded;
    // upon expansion, a Diagram Listener will generate contents for the group
    // when a group is expanded, if it contains no parts, generate a subGraph inside of it
    // subGraphExpandedChanged: function(group) {
    // if (group.memberParts.count === 0) {
    //  randomGroup(group.data.key);
    // }
    // },
    },
   $(go.Shape, 'Rectangle',
    {fill: null, stroke: 'gray', strokeWidth: 2}),
   $(go.Panel, 'Vertical',
    {defaultAlignment: go.Spot.Left, margin: 4},
    $(go.Panel, 'Horizontal',
    {defaultAlignment: go.Spot.Top},
    $('SubGraphExpanderButton', {alignment: go.Spot.Top, margin: 5}),
    // the SubGraphExpanderButton is a panel that functions as a button to expand or collapse the subGraph
    $(go.TextBlock,
     {
     font: 'Bold 14px Sans-Serif',
     margin: 10,
     },
     new go.Binding('text', 'text'))
    ),
   // create a placeholder to represent the area where the contents of the group are
    $(go.Placeholder,
    {padding: new go.Margin(0, 10)}),
   ) // end Vertical Panel
   ); // end Group

   // generate the initial model
  this.diagram = myDiagram;
  this.updateModel(this.modelData);

更新圖中數(shù)據(jù)時需要的函數(shù):

watch: {
  modelData: function(val) { 
   this.updateModel(val); 
  },
  },
  methods: {
  model: function() { 
   return this.diagram.model; 
  },
  updateModel: function(val) {
   // No GoJS transaction permitted when replacing Diagram.model.
   if (val instanceof go.Model) {
   this.diagram.model = val;
   } else {
   let m = new go.GraphLinksModel();
   if (val) {
    for (let p in val) {
    if (val[p]) {
     m[p] = val[p];
    }
    }
   }
   this.diagram.model = m;
   }
  },
  updateDiagramFromData: function() {
   this.diagram.startTransaction();
   // This is very general but very inefficient.
   // It would be better to modify the diagramData data by calling
   // Model.setDataProperty or Model.addNodeData, et al.
   this.diagram.updateAllRelationshipsFromData();
   this.diagram.updateAllTargetBindings();
   this.diagram.commitTransaction('updated');
  },
  },
 };
</script>

聲明后在stepMap調(diào)用,比較重要的是這兩個方法:

updateDiagramFromData: function() {
   this.$refs.diag.updateDiagramFromData(); // 數(shù)據(jù)變化時調(diào)用組件中的更新方法
  },
changedSelection: function(e) {
   let node = e.diagram.selection.first();
   if (node instanceof go.Node) {
   this.currentNode = node;
   this.currentNodeText = node.data.text;
   this.selectNode(node.data);
   } else {
   this.currentNode = null;
   this.currentNodeText = '';
   }
  },

最后,將需要展示的數(shù)據(jù)轉(zhuǎn)化為需要的格式就可以啦。

流程圖所需格式如下:

無分組:
 "nodeDataArray": [ 
{"key":1, "text":"Alpha", "color":"lightblue"},
{"key":2, "text":"Beta", "color":"orange"},
{"key":3, "text":"Gamma", "color":"lightgreen"},
{"key":4, "text":"Delta", "color":"pink"}
 ]
 "linkDataArray": [ 
{"from":1, "to":2},
{"from":1, "to":3},
{"from":3, "to":4}
 ]
有分組:
 var nodeDataArray = [
 { key: "Alpha" },
 { key: "Beta", group: "Omega" },
 { key: "Gamma", group: "Omega" },
 { key: "Omega", isGroup: true }, 
 { key: "Delta" }
 ];
 var linkDataArray = [
 { from: "Alpha", to: "Beta" }, 
 { from: "Beta", to: "Gamma" }, 
 { from: "Omega", to: "Delta" } 
 ];

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • c#程序員對TypeScript的認識過程

    c#程序員對TypeScript的認識過程

    本文向大家詳細展示了從C#程序員的視角學(xué)習(xí)TypeScript的過程,主要是針對這兩種語言的異同進行了簡單的對比學(xué)習(xí),希望對大家能夠有所幫助。
    2015-06-06
  • 不使用中間變量,交換int型的 a, b兩個變量的值。

    不使用中間變量,交換int型的 a, b兩個變量的值。

    群中的題目,不過這樣大眾臉的題想必大家都見過,就看能玩出什么新花招
    2010-10-10
  • 淺談bootstrap使用中的一些問題以及解決過程

    淺談bootstrap使用中的一些問題以及解決過程

    下面小編就為大家?guī)硪黄獪\談bootstrap使用中的一些問題以及解決過程。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-10-10
  • Echarts圖表點擊x軸y軸切換圖表二級數(shù)據(jù)實例代碼

    Echarts圖表點擊x軸y軸切換圖表二級數(shù)據(jù)實例代碼

    最近項目用到了Echarts圖進行數(shù)據(jù)展示,所以下面這篇文章主要給大家介紹了關(guān)于Echarts圖表點擊x軸y軸切換圖表二級數(shù)據(jù)的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-04-04
  • JS實現(xiàn)時間軸自動播放

    JS實現(xiàn)時間軸自動播放

    這篇文章主要為大家詳細介紹了JS實現(xiàn)時間軸自動播放,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • js實現(xiàn)星星打分效果

    js實現(xiàn)星星打分效果

    這篇文章主要為大家詳細介紹了js實現(xiàn)星星打分效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • js實現(xiàn)的常用的左側(cè)導(dǎo)航效果

    js實現(xiàn)的常用的左側(cè)導(dǎo)航效果

    使用js簡單實現(xiàn)下常用的左側(cè)導(dǎo)航效果為提高導(dǎo)航性能而生,各位朋友可以參考應(yīng)用,希望對大家有所幫助
    2013-10-10
  • Javascript中apply、call、bind的巧妙使用

    Javascript中apply、call、bind的巧妙使用

    Javascript中apply、call、bind都是為了改變函數(shù)體內(nèi)部 this 的指向。下面通過本文重點給大家介紹js中apply,call,bind的巧妙使用方法,感興趣的朋友一起學(xué)習(xí)吧
    2016-08-08
  • 單擊某一段文字改寫文本顏色

    單擊某一段文字改寫文本顏色

    單擊某一段文字,改文字變?yōu)榧t色,再次單擊之后,文字又變回黑色,示例如下,需要的朋友可以參考下
    2014-06-06
  • 微信小程序?qū)崿F(xiàn)接收驗證碼

    微信小程序?qū)崿F(xiàn)接收驗證碼

    這篇文章主要為大家詳細介紹了微信小程序?qū)崿F(xiàn)接收驗證碼,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05

最新評論

和田市| 汝州市| 崇州市| 武隆县| 合山市| 平阳县| 当雄县| 霍林郭勒市| 郑州市| 乌兰察布市| 内黄县| 高陵县| 丹阳市| 边坝县| 方山县| 遵义县| 嘉兴市| 平舆县| 石渠县| 乌恰县| 定远县| 吉安市| 仲巴县| 砚山县| 黄陵县| 合阳县| 贵南县| 府谷县| 夏河县| 唐山市| 周宁县| 汉寿县| 桐柏县| 巨野县| 鹤岗市| 方山县| 图片| 深州市| 溆浦县| 海盐县| 拜泉县|