react-flow-chart-editor
v1.0.1
Published
react ggEditor flow editor 流程图编辑器 保存生成json
Downloads
9
Maintainers
Readme
安装
npm install -S react-flow-chart-editor
方法使用
import FlowEditor from 'react-flow-chart-editor';
class DataSourceManagement extends Component {
constructor(props) {
super(props)
this.state = {
data: {},
flowItemPanelData: []
}
}
handelSave = (resp) => {
//生成json
console.log(resp)
}
render() {
return (
<div className="management-content">
<FlowEditor flowItemPanelData={this.state.flowItemPanelData} save={this.handelSave} />
</div>
)
}
}
页面效果
初始数据设置
import FlowEditor from 'react-flow-chart-editor';
const data = { "nodes": [{ "type": "node", "size": "72*72", "shape": "flow-circle", "color": "#FA8C16", "label": "开始", "x": 192.84375, "y": 64, "id": "769fdc42", "index": 0 }, { "type": "node", "size": "80*48", "shape": "flow-rect", "color": "#1890FF", "label": "开始", "x": 192.84375, "y": 173.5, "id": "598189cb", "index": 1 }, { "type": "node", "size": "80*72", "shape": "flow-rhombus", "color": "#13C2C2", "label": "判断条件", "x": 193.34375, "y": 282.5, "id": "cc3ef546", "index": 4 }, { "type": "node", "size": "80*48", "shape": "flow-capsule", "color": "#722ED1", "label": "结果1", "x": 193.671875, "y": 389.8, "id": "6f4ece05", "index": 5 }, { "type": "node", "size": "80*72", "shape": "flow-rhombus", "color": "#13C2C2", "label": "判断条件2", "x": 395.671875, "y": 288, "id": "14806120", "index": 7 }, { "type": "node", "size": "80*48", "shape": "flow-rect", "color": "#1890FF", "label": "结果2", "x": 396.171875, "y": 380.2, "id": "977ef7a8", "index": 10 }], "edges": [{ "source": "769fdc42", "sourceAnchor": 2, "target": "598189cb", "targetAnchor": 0, "id": "95f5b5e6", "index": 2 }, { "source": "598189cb", "sourceAnchor": 2, "target": "cc3ef546", "targetAnchor": 0, "id": "6299a1c8", "index": 3 }, { "source": "cc3ef546", "sourceAnchor": 2, "target": "6f4ece05", "targetAnchor": 0, "id": "06d5f767", "label": "是", "shape": "flow-smooth", "index": 6 }, { "source": "cc3ef546", "sourceAnchor": 1, "target": "14806120", "targetAnchor": 3, "id": "feab2dd0", "label": "否", "shape": "flow-polyline", "index": 8 }, { "source": "14806120", "sourceAnchor": 2, "target": "977ef7a8", "targetAnchor": 0, "id": "1057e78e", "label": "是", "shape": "flow-smooth", "index": 9 }, { "source": "14806120", "sourceAnchor": 0, "target": "598189cb", "targetAnchor": 1, "id": "0201aa50", "label": "条件不成立", "shape": "flow-polyline", "index": 11 }] }
class DataSourceManagement extends Component {
constructor(props) {
super(props)
this.state = {
data, // 数据样式为保存之后的数据格式
flowItemPanelData: []
}
}
handelSave = (resp) => {
//生成json
console.log(resp)
}
render() {
return (
<div className="management-content">
<FlowEditor data={this.state.data} flowItemPanelData={this.state.flowItemPanelData} save={this.handelSave} />
</div>
)
}
}
设置左边功能栏
const flowItemPanelData = [
{
type: 'node',
size: '72*72',
shape: 'flow-circle',
model: {
color: '#FA8C16', //色值
label: '开始' // 描述
},
src: 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iODAiIGhlaWdodD0iODAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxkZWZzPjxjaXJjbGUgaWQ9ImIiIGN4PSIzNiIgY3k9IjM2IiByPSIzNiIvPjxmaWx0ZXIgeD0iLTkuNyUiIHk9Ii02LjklIiB3aWR0aD0iMTE5LjQlIiBoZWlnaHQ9IjExOS40JSIgZmlsdGVyVW5pdHM9Im9iamVjdEJvdW5kaW5nQm94IiBpZD0iYSI+PGZlT2Zmc2V0IGR5PSIyIiBpbj0iU291cmNlQWxwaGEiIHJlc3VsdD0ic2hhZG93T2Zmc2V0T3V0ZXIxIi8+PGZlR2F1c3NpYW5CbHVyIHN0ZERldmlhdGlvbj0iMiIgaW49InNoYWRvd09mZnNldE91dGVyMSIgcmVzdWx0PSJzaGFkb3dCbHVyT3V0ZXIxIi8+PGZlQ29tcG9zaXRlIGluPSJzaGFkb3dCb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SIwIDAgMCAwIDAgMCAwIDAgMCAwIDAgMCAwIDAgMCAwIDAgMCAwLjA0IDAiIGluPSJzaGFkb3dCbHVyT3V0ZXIxIi8+PC9maWx0ZXI+PC9kZWZzPjxnIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCI+PGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMyAxKSI+PHVzZSBmaWxsPSIjMDAwIiBmaWx0ZXI9InVybCgjYSkiIHhsaW5rOmhyZWY9IiNiIi8+PHVzZSBmaWxsLW9wYWNpdHk9Ii45MiIgZmlsbD0iI0U2RkZGQiIgeGxpbms6aHJlZj0iI2IiLz48cGF0aCBzdHJva2U9IiM1Q0RCRDMiIGQ9Ik00Mi4zMzcgMi4wNDJhMy41IDMuNSAwIDAgMC00LjY3NCAwTDIuNjk4IDMzLjM5NGEzLjUgMy41IDAgMCAwIDAgNS4yMTJsMzQuOTY1IDMxLjM1MmEzLjUgMy41IDAgMCAwIDQuNjc0IDBsMzQuOTY1LTMxLjM1MmEzLjUgMy41IDAgMCAwIDAtNS4yMTJMNDIuMzM3IDIuMDQyeiIvPjwvZz48dGV4dCBmb250LWZhbWlseT0iUGluZ0ZhbmdTQy1SZWd1bGFyLCBQaW5nRmFuZyBTQyIgZm9udC1zaXplPSIxMiIgZmlsbD0iIzAwMCIgZmlsbC1vcGFjaXR5PSIuNjUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDMgMSkiPjx0c3BhbiB4PSIxOCIgeT0iNDIiPkRlY2lzaW9uPC90c3Bhbj48L3RleHQ+PC9nPjwvc3ZnPg=='
}
]
class DataSourceManagement extends Component {
constructor(props) {
super(props)
this.state = {
data:{}, // 数据样式为保存之后的数据格式
flowItemPanelData
}
}
handelSave = (resp) => {
//生成json
console.log(resp)
}
render() {
return (
<div className="management-content">
<FlowEditor data={this.state.data} flowItemPanelData={this.state.flowItemPanelData} save={this.handelSave} />
</div>
)
}
}