基于G6-Editor的流程图编辑器

一、介绍

一个基于G6-Editor的流程图编辑器组件

二、依赖

AntV-G6
G6-Editor
antd

三、组件目录结构

  	-  Flow
  	--  images // 组件使用相关图片
  		--  error.svg  //未编辑
  		--  success.svg // 编辑成功
  		--  type.svg // 节点类型
  	--  model // 分离小组件
  		--  ContextMenu.js // 右键菜单
  		--  DetailPannel.js // 详情面板
  		--  ItemPannel.js // 左侧节点列表
  		--  Minimap.js // 导航器
  		--  Page.js // Canvas
  		--  Toolbar.js // 顶部toolbar
  	--  style // 组件样式
  		--  index.css
  	--  Flow.js
  	--  index.js

四、组件使用

import React, { Component } from 'react';
import { Button,Divider,Modal } from 'antd';
import Flow from './components/Flow'; // 编辑器组件

import "./App.css";

class App extends Component {

  constructor(props) {
    super(props);

    this.state = {
      visible: false,
      currentModel: {},
      relation: {nodes: []}
    }
  };

  onNodeClick = (model,relation) => {
    console.log(model,relation);
    this.setState({ currentModel: model,relation })
  }

  onNodeDbClick = (model) => {
    console.log(model);
    this.openEditNodeModal()
  }

  onPublish = (relation) => {
    console.log("保存",relation);
  }

  editNode = () => {
    console.log("编辑节点");
    this.openEditNodeModal()

    // 打开编辑模态框
    // 通过表单提交修改的节点信息
    // 并修改relation
    // 通过 this.flow.renderData(relation)
    // 重新渲染流程图数据
  }

  closeEditNodeModal = () => {
    this.setState({
      visible:false
    })
  };

  openEditNodeModal = () => {
    this.setState({
      visible: true
    })
  }

  render (){
    const { currentModel,visible } = this.state;

    return <div className="App">
        <Flow 
          className="process-flow"
          ref={(node) => this.flow = node}
          onNodeDbClick={this.onNodeDbClick}
          onNodeClick={this.onNodeClick}
          onPublish={this.onPublish}
          nodeDetailPannel={<>
              流程节点名称: {currentModel.flowNodeName}
              <Divider />
              流程角色名称: {currentModel.flowNodeRole}
              <Divider />
              <Button type="primary" onClick={this.editNode}>编辑节点</Button>
          </>}
          >
        </Flow>
        <Modal title="编辑节点" 
          forceRender={true}
          style={{top: 20}}
          width={ 1000 }
          visible={visible} 
          onCancel={this.closeEditNodeModal}
          footer={null}>
          编辑节点表单
        </Modal>
    </div>
  };
}

export default App;

五、展示

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值