叁两木 發表於 2020-2-25 10:35:00

react引入ggEditor流程图

<h2>遇到的问题</h2>
<p>1.propsAPI获取不到内容:withPropsAPI包裹的组件必须是GGEditor的子组件。</p>
<p>2.自定义组件如何使用:正确的办法是通过config配置,参照上面的代码(之前我在在内部RegisterCommand以后,在onAfterExecuteCommand中截获命令,通过函数控制图例操作。这中间需要下钻到内部组件调用propsAPI,我就通过setState去设置状态传递到子组件。)</p>
<p>3.如何设置拖拽组件:太羞耻了,居然不晓得在Item双标签内放名称。</p>
<p>4.操作流程图后获取数据延迟:如果获取数据有延迟,尝试使用setTimeout,时间间隔设为0后再调propsAPI属性的方法操作。</p>
<p>&nbsp;</p>
<p><span style="font-size: 18pt"><strong>1. 两种不同颜色的线</strong></span></p>
<p><span style="font-size: 16px">用onAfterChange监听,然后用先的更新设置不同的颜色即可。</span></p>
<p><span style="font-size: 18pt"><strong>2. 节点和线的更新</strong></span></p>
<div class="cnblogs_code">
<pre>import React, { Fragment } from 'react'<span style="color: rgba(0, 0, 0, 1)">;
import { Card, Form, Input, Select } from </span>'antd'<span style="color: rgba(0, 0, 0, 1)">;
import { withPropsAPI } from </span>'gg-editor'<span style="color: rgba(0, 0, 0, 1)">;
import upperFirst from </span>'lodash/upperFirst'<span style="color: rgba(0, 0, 0, 1)">;

const { Item } </span>=<span style="color: rgba(0, 0, 0, 1)"> Form;
const { Option } </span>=<span style="color: rgba(0, 0, 0, 1)"> Select;

const inlineFormItemLayout </span>=<span style="color: rgba(0, 0, 0, 1)"> {
labelCol: {
    sm: { span: </span>8<span style="color: rgba(0, 0, 0, 1)"> },
},
wrapperCol: {
    sm: { span: </span>16<span style="color: rgba(0, 0, 0, 1)"> },
},
};

class DetailForm extends React.Component {
get item() {
    const { propsAPI } </span>= <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.props;

    </span><span style="color: rgba(0, 0, 255, 1)">return</span> propsAPI.getSelected();
}

handleSubmit </span>= (e) =&gt;<span style="color: rgba(0, 0, 0, 1)"> {
    </span><span style="color: rgba(0, 0, 255, 1)">if</span> (e &amp;&amp;<span style="color: rgba(0, 0, 0, 1)"> e.preventDefault) {
      e.preventDefault();
    }

    const { form, propsAPI } </span>= <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.props;
    const { getSelected, executeCommand, update } </span>=<span style="color: rgba(0, 0, 0, 1)"> propsAPI;

    setTimeout(() </span>=&gt;<span style="color: rgba(0, 0, 0, 1)"> {
      form.validateFieldsAndScroll((err, values) </span>=&gt;<span style="color: rgba(0, 0, 0, 1)"> {
      </span><span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (err) {
          </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
      }

      const item </span>= getSelected();

      </span><span style="color: rgba(0, 0, 255, 1)">if</span> (!<span style="color: rgba(0, 0, 0, 1)">item) {
          </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
      }
      console.log(item,values,</span>'values'<span style="color: rgba(0, 0, 0, 1)">)
      executeCommand(() </span>=&gt;<span style="color: rgba(0, 0, 0, 1)"> {
          update(item, {
            ...values,
          });
      });
      });
    }, </span>0<span style="color: rgba(0, 0, 0, 1)">);
};

renderEdgeShapeSelect </span>= () =&gt;<span style="color: rgba(0, 0, 0, 1)"> {
    </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> (
      </span>&lt;Select onChange={<span style="color: rgba(0, 0, 255, 1)">this</span>.handleSubmit}&gt;
      &lt;Option value="flow-smooth"&gt;Smooth&lt;/Option&gt;
      &lt;Option value="flow-polyline"&gt;Polyline&lt;/Option&gt;
      &lt;Option value="flow-polyline-round"&gt;Polyline Round&lt;/Option&gt;
      &lt;/Select&gt;
<span style="color: rgba(0, 0, 0, 1)">    );
};

renderNodeDetail </span>= () =&gt;<span style="color: rgba(0, 0, 0, 1)"> {
    const { form } </span>= <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.props;
    const { label } </span>= <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.item.getModel();
    </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> (
      </span>&lt;Item label="Label" {...inlineFormItemLayout}&gt;<span style="color: rgba(0, 0, 0, 1)">
      {form.getFieldDecorator(</span>'label'<span style="color: rgba(0, 0, 0, 1)">, {
          initialValue: label.text </span>?<span style="color: rgba(0, 0, 0, 1)"> label.text : label,
      })(</span>&lt;Input onBlur={<span style="color: rgba(0, 0, 255, 1)">this</span>.handleSubmit} /&gt;)}
      &lt;/Item&gt;
<span style="color: rgba(0, 0, 0, 1)">    );
};

renderEdgeDetail </span>= () =&gt;<span style="color: rgba(0, 0, 0, 1)"> {
    const { form } </span>= <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.props;
    const { label </span>= '', shape = 'flow-smooth' } = <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.item.getModel();

    </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> (
      </span>&lt;Fragment&gt;
      &lt;Item label="Label" {...inlineFormItemLayout}&gt;<span style="color: rgba(0, 0, 0, 1)">
          {form.getFieldDecorator(</span>'label'<span style="color: rgba(0, 0, 0, 1)">, {
            initialValue: label,
          })(</span>&lt;Input onBlur={<span style="color: rgba(0, 0, 255, 1)">this</span>.handleSubmit} /&gt;)}
      &lt;/Item&gt;
      &lt;Item label="Shape" {...inlineFormItemLayout}&gt;<span style="color: rgba(0, 0, 0, 1)">
          {form.getFieldDecorator(</span>'shape'<span style="color: rgba(0, 0, 0, 1)">, {
            initialValue: shape,
          })(</span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.renderEdgeShapeSelect())}
      </span>&lt;/Item&gt;
      &lt;/Fragment&gt;
<span style="color: rgba(0, 0, 0, 1)">    );
};

renderGroupDetail </span>= () =&gt;<span style="color: rgba(0, 0, 0, 1)"> {
    const { form } </span>= <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.props;
    const { label </span>= '新建分组' } = <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.item.getModel();

    </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> (
      </span>&lt;Item label="Label" {...inlineFormItemLayout}&gt;<span style="color: rgba(0, 0, 0, 1)">
      {form.getFieldDecorator(</span>'label'<span style="color: rgba(0, 0, 0, 1)">, {
          initialValue: label,
      })(</span>&lt;Input onBlur={<span style="color: rgba(0, 0, 255, 1)">this</span>.handleSubmit} /&gt;)}
      &lt;/Item&gt;
<span style="color: rgba(0, 0, 0, 1)">    );
};

render() {
    const { type } </span>= <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.props;

    </span><span style="color: rgba(0, 0, 255, 1)">if</span> (!<span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.item) {
      </span><span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
    }

    </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> (
      </span>&lt;Card type="inner" size="small" title={upperFirst(type)} bordered={<span style="color: rgba(0, 0, 255, 1)">false</span>}&gt;
      &lt;Form onSubmit={<span style="color: rgba(0, 0, 255, 1)">this</span>.handleSubmit}&gt;<span style="color: rgba(0, 0, 0, 1)">
          {type </span>=== 'node' &amp;&amp; <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.renderNodeDetail()}
          {type </span>=== 'edge' &amp;&amp; <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.renderEdgeDetail()}
          {type </span>=== 'group' &amp;&amp; <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.renderGroupDetail()}
      </span>&lt;/Form&gt;
      &lt;/Card&gt;
<span style="color: rgba(0, 0, 0, 1)">    );
}
}

export </span><span style="color: rgba(0, 0, 255, 1)">default</span> Form.create()(withPropsAPI(DetailForm));</pre>
</div>
<p>&nbsp;</p>
<p><span style="font-size: 18pt"><strong>3. 提交数据</strong></span></p>
<p><span style="font-size: 18pt"><strong>4. 自定义节点,注册节点</strong></span></p>
<p><strong><span style="font-size: 18px">EditorCustomFlowMap组件</span></strong></p>
<div class="cnblogs_code">
<pre>import React from 'react'<span style="color: rgba(0, 0, 0, 1)">;
import { Col } from </span>'antd'<span style="color: rgba(0, 0, 0, 1)">;
import { Flow } from </span>'gg-editor'<span style="color: rgba(0, 0, 0, 1)">;
import { withPropsAPI } from </span>'gg-editor'<span style="color: rgba(0, 0, 0, 1)">;
import CustomNode from </span>'../EditorCustomNode'<span style="color: rgba(0, 0, 0, 1)">;</span><span style="color: rgba(0, 0, 0, 1)">

const FlowMap </span>= (props) =&gt;<span style="color: rgba(0, 0, 0, 1)"> {</span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> (
      </span>&lt;Col span={21} className='editorContent'&gt;
            &lt;<span style="color: rgba(0, 0, 0, 1)">Flow
                className</span>='flow'<span style="color: rgba(0, 0, 0, 1)">
                data</span>=<span style="color: rgba(0, 0, 0, 1)">{props.data} // 已有节点那数据结构
                noEndEdge</span>={<span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">}</span>/&gt;
            &lt;CustomNode /&gt;
      &lt;/Col&gt;
<span style="color: rgba(0, 0, 0, 1)">      );
};

export </span><span style="color: rgba(0, 0, 255, 1)">default</span> withPropsAPI(FlowMap);</pre>
</div>
<pre><strong><span style="font-size: 18px">CustomNode 组件,注册节点</span></strong></pre>
<div class="cnblogs_code">
<pre>import React from "react"<span style="color: rgba(0, 0, 0, 1)">;
import { RegisterNode } from </span>"gg-editor"<span style="color: rgba(0, 0, 0, 1)">;

class CustomNode extends React.Component {
render() {
    const config </span>=<span style="color: rgba(0, 0, 0, 1)"> {
      draw(item) {
      const keyShape </span>= <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.drawKeyShape(item);

      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 绘制图标</span>
      const group =<span style="color: rgba(0, 0, 0, 1)"> item.getGraphicGroup();
      const model </span>=<span style="color: rgba(0, 0, 0, 1)"> item.getModel();

      group.addShape(</span>"image"<span style="color: rgba(0, 0, 0, 1)">, {
          attrs: {
            x: </span>-35<span style="color: rgba(0, 0, 0, 1)">,
            y: </span>-10<span style="color: rgba(0, 0, 0, 1)">,
            width: </span>20<span style="color: rgba(0, 0, 0, 1)">,
            height: </span>20<span style="color: rgba(0, 0, 0, 1)">,
            img: model.icon
          }
      });

      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 绘制标签</span>
      <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.drawLabel(item);

      </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> keyShape;
      },

      anchor: [
      [</span>0.5, 0], <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 上边中点</span>
      , <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 右边中点</span>
      , <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 底边中点</span>
       <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 左边中点</span>
<span style="color: rgba(0, 0, 0, 1)">      ]
    };

    </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> (
      </span>&lt;RegisterNode name="custom-node" config={config} extend={"flow-circle"} /&gt;
<span style="color: rgba(0, 0, 0, 1)">    );
}
}

export </span><span style="color: rgba(0, 0, 255, 1)">default</span> CustomNode;</pre>
</div>
<p>&nbsp;</p>
<p><span style="font-size: 18pt"><strong>5.已有节点的数据结构</strong></span></p>
<div class="cnblogs_Highlighter">
<pre class="brush:javascript;gutter:true;">{
    "nodes": [
    {
      "id": "1",
      "flowType":"flow-circle", // 节点使用的形状
      "label":"开始",
      "x": 100, // 节点X轴坐标位置
      "y": 50,// 节点Y轴坐标位置
      "color":"blue", // 节点的颜色
      "size ": "80*48", // 节点的宽度和高度
      "shape ": "flow-rect"
    }
],
"edges": [
    {
      "source":"1",
      "sourceAnchor": 1,
      "target":"2",
      "targetAnchor": 3,
      "id": "d1",<br>    "color":"red" // 连线的颜色
    }
]
}
</pre>
</div>
<p><strong><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 18pt">6.左侧待拖动的节点</span></strong></p>
<p>这里的节点和flow图里面的节点样式控制不一样,这里的节点样式是靠css来控制。</p>
<p>flow图里面的节点样式,1,已有节点,靠的是已有节点的数据来控制,2,即将拖拽到flow区域的节点,是靠这里的Item属性来控制样式。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)"> 1</span> import React from 'react'<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 2</span> import { Card } from 'antd'<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 3</span> import { ItemPanel, Item } from 'gg-editor'<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 4</span> import './index.less'<span style="color: rgba(0, 0, 0, 1)">;</span><span style="color: rgba(0, 128, 128, 1)"> 6</span>
<span style="color: rgba(0, 128, 128, 1)"> 7</span> const FlowItemPanel = () =&gt;<span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)"> 8</span>   <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> (</span>
<span style="color: rgba(0, 128, 128, 1)">10</span>   &lt;ItemPanel className='itemPanel'&gt;
<span style="color: rgba(0, 128, 128, 1)">11</span>       &lt;Card bordered={<span style="color: rgba(0, 0, 255, 1)">false</span>}&gt;      
<span style="color: rgba(0, 128, 128, 1)">12</span>         &lt;<span style="color: rgba(0, 0, 0, 1)">Item
</span><span style="color: rgba(0, 128, 128, 1)">13</span>         type="node"
<span style="color: rgba(0, 128, 128, 1)">14</span>         size="72*72"<span style="color: rgba(0, 128, 128, 1)">15</span>         shape="custom-node" // 自定义注册节点名称
<span style="color: rgba(0, 128, 128, 1)">16</span>         model=<span style="color: rgba(0, 0, 0, 1)">{{
</span><span style="color: rgba(0, 128, 128, 1)">17</span>             icon:'//img.alicdn.com/tfs/TB1OzAmyyLaK1RjSZFxXXamPFXa-200-200.svg'<span style="color: rgba(0, 0, 0, 1)">,
</span><span style="color: rgba(0, 128, 128, 1)">18</span>             color: '#FA8C16'<span style="color: rgba(0, 0, 0, 1)">,
</span><span style="color: rgba(0, 128, 128, 1)">19</span> <span style="color: rgba(0, 0, 0, 1)">            label:{
</span><span style="color: rgba(0, 128, 128, 1)">20</span>               text:'流程'<span style="color: rgba(0, 0, 0, 1)">,
</span><span style="color: rgba(0, 128, 128, 1)">21</span>               fill: 'green'
<span style="color: rgba(0, 128, 128, 1)">22</span> <span style="color: rgba(0, 0, 0, 1)">            },
</span><span style="color: rgba(0, 128, 128, 1)">23</span> <span style="color: rgba(0, 0, 0, 1)">          }}
</span><span style="color: rgba(0, 128, 128, 1)">24</span>         &gt;
<span style="color: rgba(0, 128, 128, 1)">25</span>         &lt;div className="flow-node"&gt;流程&lt;/div&gt;
<span style="color: rgba(0, 128, 128, 1)">26</span>         &lt;/Item&gt;
<span style="color: rgba(0, 128, 128, 1)">27</span>         
<span style="color: rgba(0, 128, 128, 1)">28</span>         &lt;<span style="color: rgba(0, 0, 0, 1)">Item
</span><span style="color: rgba(0, 128, 128, 1)">29</span>         type="node"
<span style="color: rgba(0, 128, 128, 1)">30</span>         size="80*48"<span style="color: rgba(0, 128, 128, 1)">31</span>         shape="flow-rect"
<span style="color: rgba(0, 128, 128, 1)">32</span>         model=<span style="color: rgba(0, 0, 0, 1)">{{
</span><span style="color: rgba(0, 128, 128, 1)">33</span>             color: '#1890FF'<span style="color: rgba(0, 0, 0, 1)">,
</span><span style="color: rgba(0, 128, 128, 1)">34</span> <span style="color: rgba(0, 0, 0, 1)">            label:{
</span><span style="color: rgba(0, 128, 128, 1)">35</span>               text:'文档'<span style="color: rgba(0, 0, 0, 1)">,
</span><span style="color: rgba(0, 128, 128, 1)">36</span>               fill: '#000'
<span style="color: rgba(0, 128, 128, 1)">37</span> <span style="color: rgba(0, 0, 0, 1)">            },
</span><span style="color: rgba(0, 128, 128, 1)">38</span> <span style="color: rgba(0, 0, 0, 1)">          }}
</span><span style="color: rgba(0, 128, 128, 1)">39</span>         &gt;
<span style="color: rgba(0, 128, 128, 1)">40</span>         &lt;div className="document-node"&gt;文档&lt;/div&gt;
<span style="color: rgba(0, 128, 128, 1)">41</span>         &lt;/Item&gt;
<span style="color: rgba(0, 128, 128, 1)">42</span>       &lt;/Card&gt;
<span style="color: rgba(0, 128, 128, 1)">43</span>   &lt;/ItemPanel&gt;
<span style="color: rgba(0, 128, 128, 1)">44</span> <span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">45</span> <span style="color: rgba(0, 0, 0, 1)">};
</span><span style="color: rgba(0, 128, 128, 1)">46</span>
<span style="color: rgba(0, 128, 128, 1)">47</span> export <span style="color: rgba(0, 0, 255, 1)">default</span> FlowItemPanel;</pre>
</div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)"> 1</span> .flow-<span style="color: rgba(0, 0, 0, 1)">node{
</span><span style="color: rgba(0, 128, 128, 1)"> 2</span> <span style="color: rgba(0, 0, 0, 1)">border: 1px solid #fed49a;
</span><span style="color: rgba(0, 128, 128, 1)"> 3</span>   background-<span style="color: rgba(0, 0, 0, 1)">color: #fef6e7;
</span><span style="color: rgba(0, 128, 128, 1)"> 4</span>   border-radius: 50%<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 5</span> <span style="color: rgba(0, 0, 0, 1)">padding: 20px;
</span><span style="color: rgba(0, 128, 128, 1)"> 6</span> <span style="color: rgba(0, 0, 0, 1)">color: green;
</span><span style="color: rgba(0, 128, 128, 1)"> 7</span>   -webkit-user-<span style="color: rgba(0, 0, 0, 1)">select: none;
</span><span style="color: rgba(0, 128, 128, 1)"> 8</span>   -ms-user-select: none; <span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)"> Internet Explorer/Edge </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)"> 9</span> <span style="color: rgba(0, 0, 0, 1)">}
</span><span style="color: rgba(0, 128, 128, 1)">10</span>
<span style="color: rgba(0, 128, 128, 1)">11</span> .document-<span style="color: rgba(0, 0, 0, 1)">node{
</span><span style="color: rgba(0, 128, 128, 1)">12</span>   border-radius: 10%<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">13</span> <span style="color: rgba(0, 0, 0, 1)">border: 1px solid #a7dafe;
</span><span style="color: rgba(0, 128, 128, 1)">14</span>   background-<span style="color: rgba(0, 0, 0, 1)">color: #e7f6fe;
</span><span style="color: rgba(0, 128, 128, 1)">15</span> <span style="color: rgba(0, 0, 0, 1)">padding: 15px 20px;
</span><span style="color: rgba(0, 128, 128, 1)">16</span>   -webkit-user-<span style="color: rgba(0, 0, 0, 1)">select: none;
</span><span style="color: rgba(0, 128, 128, 1)">17</span>   -ms-user-select: none; <span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)"> Internet Explorer/Edge </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">18</span> }</pre>
</div>
<p><span style="font-size: 18pt; font-family: &quot;Microsoft YaHei&quot;"><strong>7.操作栏的设置</strong></span></p>
<div class="cnblogs_code">
<pre>import React from 'react'<span style="color: rgba(0, 0, 0, 1)">;
import { Divider } from </span>'antd'<span style="color: rgba(0, 0, 0, 1)">;
import { Toolbar } from </span>'gg-editor'<span style="color: rgba(0, 0, 0, 1)">;
import ToolbarButton from </span>'./ToolbarButton'<span style="color: rgba(0, 0, 0, 1)">;
import </span>'./index.less'<span style="color: rgba(0, 0, 0, 1)">;

const FlowToolbar </span>= () =&gt;<span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> (
    </span>&lt;Toolbar className='toolbar'&gt;
      &lt;ToolbarButton command="undo" text="回退一步" /&gt;
      &lt;ToolbarButton command="redo" text="前进一步" /&gt;
      &lt;Divider type="vertical" /&gt;
      &lt;ToolbarButton command="copy" text="复制" /&gt;
      &lt;ToolbarButton command="paste" text="粘贴" /&gt;
      &lt;ToolbarButton command="delete" text="删除" /&gt;
      &lt;Divider type="vertical" /&gt;
      &lt;ToolbarButton command="zoomIn" icon="zoom-in" text="Zoom In" /&gt;
      &lt;ToolbarButton command="zoomOut" icon="zoom-out" text="Zoom Out" /&gt;
      &lt;ToolbarButton command="autoZoom" icon="fit-map" text="Fit Map" /&gt;
      &lt;ToolbarButton command="resetZoom" icon="actual-size" text="Actual Size" /&gt;
      &lt;Divider type="vertical" /&gt;
      &lt;ToolbarButton command="toBack" icon="to-back" text="To Back" /&gt;
      &lt;ToolbarButton command="toFront" icon="to-front" text="To Front" /&gt;
      &lt;Divider type="vertical" /&gt;
      &lt;ToolbarButton command="multiSelect" icon="multi-select" text="Multi Select" /&gt;
      &lt;ToolbarButton command="addGroup" icon="group" text="Add Group" /&gt;
      &lt;ToolbarButton command="unGroup" icon="ungroup" text="Ungroup" /&gt;
    &lt;/Toolbar&gt;
<span style="color: rgba(0, 0, 0, 1)">);
};

export </span><span style="color: rgba(0, 0, 255, 1)">default</span> FlowToolbar;</pre>
</div>
<p>&nbsp;</p>
<p>8. 总</p>
<div class="cnblogs_code">
<pre>import React from 'react'<span style="color: rgba(0, 0, 0, 1)">;
import { Row, Col } from </span>'antd'<span style="color: rgba(0, 0, 0, 1)">;
import GGEditor from </span>'gg-editor'<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 0, 1)">import EditorMinimap from '../components/EditorMinimap';</span>
import { FlowContextMenu } from '../components/EditorContextMenu'<span style="color: rgba(0, 0, 0, 1)">;
import { FlowToolbar } from </span>'../components/EditorToolbar'<span style="color: rgba(0, 0, 0, 1)">;
import { FlowItemPanel } from </span>'../components/EditorItemPanel'<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 0, 1)">import { FlowDetailPanel } from '../components/EditorDetailPanel';</span>
import './index.less'<span style="color: rgba(0, 0, 0, 1)">;
import EditorCustomDetailPanel from </span>'../components/EditorCustomDetailPanel'<span style="color: rgba(0, 0, 0, 1)">;
import EditorCustomFlowMap from </span>'../components/EditorCustomFlowMap'<span style="color: rgba(0, 0, 0, 1)">;</span><span style="color: rgba(0, 0, 0, 1)">
const flowData </span>=<span style="color: rgba(0, 0, 0, 1)"> {nodes:[],edges:[]};

const FlowPage </span>= (props) =&gt;<span style="color: rgba(0, 0, 0, 1)"> {</span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> (
      </span>&lt;GGEditorclassName='editor' style={{height:props.height}}&gt;
          &lt;Row type="flex" className='editorHd'&gt;
            &lt;Col span={24}&gt;
            &lt;FlowToolbar /&gt;
            &lt;/Col&gt;
          &lt;/Row&gt;
          &lt;Row type="flex" className='editorBd'&gt;
            &lt;Col span={3} className='editorSidebar'&gt;
            &lt;FlowItemPanel /&gt;
            &lt;/Col&gt;
            &lt;<span style="color: rgba(0, 0, 0, 1)">EditorCustomFlowMap
            data</span>=<span style="color: rgba(0, 0, 0, 1)">{flowData}
            onNodeClick</span>=<span style="color: rgba(0, 0, 0, 1)">{props.handleNodeClick}
            onNodeDragEnd    </span>=<span style="color: rgba(0, 0, 0, 1)">{props.handleNodeDragEnd}
            handleAfterChange</span>=<span style="color: rgba(0, 0, 0, 1)">{props.handleAfterChange}
            </span>/&gt;
            <span style="color: rgba(0, 128, 0, 1)">&lt;Col span={4} className='editorSidebar'&gt;
            &lt;FlowDetailPanel /&gt;
            &lt;EditorMinimap /&gt;
            &lt;/Col&gt;</span>&lt;/Row&gt;
          &lt;FlowContextMenu /&gt;
          &lt;<span style="color: rgba(0, 0, 0, 1)">EditorCustomDetailPanel
            visibleDetailPanel</span>=<span style="color: rgba(0, 0, 0, 1)">{props.visibleDetailPanel}
            hideVisibleDetailPanel</span>=<span style="color: rgba(0, 0, 0, 1)">{props.hideVisibleDetailPanel}
            detailPanel</span>=<span style="color: rgba(0, 0, 0, 1)">{props.detailPanel}
            currentNode</span>=<span style="color: rgba(0, 0, 0, 1)">{props.currentNode}
            changeDetailPanel</span>=<span style="color: rgba(0, 0, 0, 1)">{props.changeDetailPanel}
            submitCurrentNode</span>=<span style="color: rgba(0, 0, 0, 1)">{props.submitCurrentNode}
          </span>/&gt;
      &lt;/GGEditor&gt;
<span style="color: rgba(0, 0, 0, 1)">      );
};

export </span><span style="color: rgba(0, 0, 255, 1)">default</span> FlowPage;</pre>
</div>
<p>&nbsp;</p>

</div>
<div id="MySignature" role="contentinfo">
    快乐学习,积累在于一点一滴。
希望能够帮到你,如果有问题,请多多指教,谢谢!<br><br>
来源:https://www.cnblogs.com/hibiscus-ben/p/12360401.html
頁: [1]
查看完整版本: react引入ggEditor流程图