@kne/react-flow-chart 0.1.10 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -19
- package/dist/index.css +285 -166
- package/dist/index.css.map +1 -1
- package/dist/index.js +238 -160
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +206 -107
- package/dist/index.modern.js.map +1 -1
- package/dist/locale/en.js +8 -1
- package/dist/locale/en.js.map +1 -1
- package/dist/locale/en.modern.js +8 -1
- package/dist/locale/en.modern.js.map +1 -1
- package/dist/locale/zh-cn.js +8 -1
- package/dist/locale/zh-cn.js.map +1 -1
- package/dist/locale/zh-cn.modern.js +8 -1
- package/dist/locale/zh-cn.modern.js.map +1 -1
- package/package.json +2 -2
- package/dist/arrow~bbpMpvlG.svg +0 -1
package/README.md
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
1
|
# react-flow-chart
|
|
3
2
|
|
|
4
|
-
|
|
5
3
|
### 描述
|
|
6
4
|
|
|
7
5
|
用于展示或编辑一个审批流.
|
|
8
6
|
|
|
9
|
-
|
|
10
7
|
### 安装
|
|
11
8
|
|
|
12
9
|
```shell
|
|
13
10
|
npm i --save @kne/react-flow-chart
|
|
14
11
|
```
|
|
15
12
|
|
|
16
|
-
|
|
17
13
|
### 概述
|
|
18
14
|
|
|
19
15
|
**致谢:** 本项目的大部分代码迁移自 @wanglin1994/simple-flow-chart,源项目为Vue2实现,我将它用React重新实现
|
|
@@ -25,7 +21,6 @@ npm i --save @kne/react-flow-chart
|
|
|
25
21
|
|
|
26
22
|
### 示例
|
|
27
23
|
|
|
28
|
-
|
|
29
24
|
#### 示例样式
|
|
30
25
|
|
|
31
26
|
```scss
|
|
@@ -38,8 +33,8 @@ npm i --save @kne/react-flow-chart
|
|
|
38
33
|
|
|
39
34
|
#### 示例代码
|
|
40
35
|
|
|
41
|
-
-
|
|
42
|
-
-
|
|
36
|
+
- 基本示例
|
|
37
|
+
- 包含普通节点、条件分支(可嵌套)和并行分支,支持横向、纵向展示
|
|
43
38
|
- _ReactFlowChart(@kne/current-lib_react-flow-chart),(@kne/current-lib_react-flow-chart/dist/index.css),antd(antd)
|
|
44
39
|
|
|
45
40
|
```jsx
|
|
@@ -87,6 +82,16 @@ const BaseExample = () => {
|
|
|
87
82
|
'id': '07e2e432-1b3c-47e6-ac4a-54a677d9ac69', 'type': 'condition', 'title': '条件分支', 'children': [[{
|
|
88
83
|
'id': '133d8b89-b79a-4daf-ad46-4c2915fec339', 'type': 'branch', 'title': '条件', 'content': '条件内容'
|
|
89
84
|
}], [{'id': '46ee06d5-bbf1-4c4a-8389-71e412d9af51', 'type': 'branch', 'title': '条件', 'content': '条件内容'}]]
|
|
85
|
+
}, {
|
|
86
|
+
'id': 'parallel-1', 'type': 'parallel', 'title': '并行分支', 'content': '全部分支完成后继续', 'children': [[{
|
|
87
|
+
'id': 'parallel-1-branch-1', 'type': 'branch', 'title': '分支', 'content': '财务'
|
|
88
|
+
}, {
|
|
89
|
+
'id': 'parallel-1-node-1', 'type': 'normal', 'title': '财务审批', 'content': '财务经理'
|
|
90
|
+
}], [{
|
|
91
|
+
'id': 'parallel-1-branch-2', 'type': 'branch', 'title': '分支', 'content': '法务'
|
|
92
|
+
}, {
|
|
93
|
+
'id': 'parallel-1-node-2', 'type': 'normal', 'title': '法务审批', 'content': '法务专员'
|
|
94
|
+
}]]
|
|
90
95
|
}, {
|
|
91
96
|
'id': 'c6fb9b16-5124-4bdd-b1c6-a899f257d4b4', 'type': 'normal', 'title': '普通节点', 'content': '节点内容'
|
|
92
97
|
}, {'id': 'endEvent', 'type': 'end', 'title': '结束'}]} onChange={(nodeList) => {
|
|
@@ -106,18 +111,84 @@ render(<BaseExample/>);
|
|
|
106
111
|
|
|
107
112
|
```
|
|
108
113
|
|
|
114
|
+
- 自定义节点类型与渲染
|
|
115
|
+
- 通过 nodeTypeList 自定义添加菜单,nodeTemplate 支持函数生成默认数据,renderNodeContent 自定义节点内容,getNodeClassName 叠加节点状态样式
|
|
116
|
+
- _ReactFlowChart(@kne/current-lib_react-flow-chart),(@kne/current-lib_react-flow-chart/dist/index.css),antd(antd)
|
|
109
117
|
|
|
110
|
-
|
|
118
|
+
```jsx
|
|
119
|
+
const {default: ReactFlowChart} = _ReactFlowChart;
|
|
120
|
+
const {Flex, Tag} = antd;
|
|
121
|
+
const {useState} = React;
|
|
122
|
+
|
|
123
|
+
const nodeTypeList = [{
|
|
124
|
+
name: '审批', list: [{type: 'approval', name: '审批节点'}, {type: 'cc', name: '抄送节点'}]
|
|
125
|
+
}, {
|
|
126
|
+
name: '分支', list: [{type: 'condition', name: '条件分支'}, {type: 'parallel', name: '并行分支'}]
|
|
127
|
+
}];
|
|
128
|
+
|
|
129
|
+
const statusColor = {passed: 'success', running: 'processing', rejected: 'error'};
|
|
130
|
+
|
|
131
|
+
const CustomExample = () => {
|
|
132
|
+
const [value, setValue] = useState([{id: 'start', type: 'start', title: '发起人'}, {
|
|
133
|
+
id: 'approval-1', type: 'approval', title: '直属上级', content: '上级审批', status: 'passed'
|
|
134
|
+
}, {
|
|
135
|
+
id: 'cc-1', type: 'cc', title: '抄送', content: 'HR', status: 'running'
|
|
136
|
+
}, {id: 'end', type: 'end', title: '结束'}]);
|
|
137
|
+
return <Flex vertical gap={8}>
|
|
138
|
+
<ReactFlowChart value={value} onChange={setValue} nodeTypeList={nodeTypeList}
|
|
139
|
+
nodeTemplate={{
|
|
140
|
+
approval: () => ({title: '审批人', content: '请设置审批人'}),
|
|
141
|
+
cc: {title: '抄送人', content: '请设置抄送人'},
|
|
142
|
+
parallel: {content: '全部分支完成后继续'},
|
|
143
|
+
branch: ({parentType}) => parentType === 'parallel' ? {title: '分支', content: '请设置'} : {
|
|
144
|
+
title: '条件', content: '请设置条件'
|
|
145
|
+
}
|
|
146
|
+
}}
|
|
147
|
+
renderNodeContent={({nodeData, content}) => <Flex gap={4} align="center">
|
|
148
|
+
{nodeData.status && <Tag color={statusColor[nodeData.status]}>{nodeData.status}</Tag>}
|
|
149
|
+
<span>{content}</span>
|
|
150
|
+
</Flex>}
|
|
151
|
+
getNodeClassName={({nodeData}) => nodeData.status ? `node-status-${nodeData.status}` : null}
|
|
152
|
+
onEditNode={({nodeData, replaceNode}) => {
|
|
153
|
+
replaceNode(Object.assign({}, nodeData, {content: `${nodeData.content}(已编辑)`}));
|
|
154
|
+
}}/>
|
|
155
|
+
</Flex>;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
render(<CustomExample/>);
|
|
111
159
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
| defaultValue | 节点数据,非受控模式 | array | - |
|
|
116
|
-
| onChange | 节点数据发生修改时触发事件 | function | - |
|
|
117
|
-
| readonly | 是否只读 | boolean | false |
|
|
118
|
-
| showScrollBar | 是否展示滚动条 | boolean | true |
|
|
119
|
-
| enableDrag | 内容区域是否可以拖拽滚动 | boolean | true |
|
|
120
|
-
| initFit | 初始化时是否自适应缩放大小 | boolean | true |
|
|
121
|
-
| vertical | 是否纵向展示 | boolean | false |
|
|
122
|
-
| onEditNode | 点击节点内容触发事件,可以用来修改节点数据 | function | - |
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### API
|
|
123
163
|
|
|
164
|
+
| 属性名 | 说明 | 类型 | 默认值 |
|
|
165
|
+
|-------------------|-----------------------------------------------------------------------------------------------------|----------------------------------------|-------|
|
|
166
|
+
| value | 节点数据,受控模式 | array | - |
|
|
167
|
+
| defaultValue | 节点数据,非受控模式 | array | - |
|
|
168
|
+
| onChange | 节点数据发生修改时触发事件 | function | - |
|
|
169
|
+
| readonly | 是否只读 | boolean | false |
|
|
170
|
+
| showScrollBar | 是否展示滚动条 | boolean | true |
|
|
171
|
+
| enableDrag | 内容区域是否可以拖拽滚动 | boolean | true |
|
|
172
|
+
| initFit | 初始化时是否自适应缩放大小 | boolean | true |
|
|
173
|
+
| vertical | 是否纵向展示 | boolean | false |
|
|
174
|
+
| onEditNode | 点击节点内容触发事件,参数为 `{ nodeData, replaceNode }`,调用 `replaceNode(node)` 修改节点数据 | function | - |
|
|
175
|
+
| nodeTypeList | 添加节点菜单,格式为 `[{ name, list: [{ type, name }] }]`;`type` 可以是任意自定义类型,`condition`、`parallel` 为分支容器 | array | 内置普通节点、条件分支、并行分支 |
|
|
176
|
+
| nodeTemplate | 按节点类型设置新建节点的默认数据,值可以是对象或 `({ type, parentType }) => object`;`branch` 的 `parentType` 为所在分支容器类型 | object | {} |
|
|
177
|
+
| renderNodeContent | 自定义节点内容区,参数为 `{ nodeData, content }` | function | - |
|
|
178
|
+
| getNodeClassName | 为节点卡片追加 className,参数为 `{ nodeData }`,可用于展示运行状态(开始、结束节点没有卡片) | function | - |
|
|
179
|
+
|
|
180
|
+
#### 节点数据
|
|
181
|
+
|
|
182
|
+
| 字段 | 说明 |
|
|
183
|
+
|----------|--------------------------------------------------------------------------|
|
|
184
|
+
| id | 节点唯一标识 |
|
|
185
|
+
| type | `start`、`end`、`condition`(条件分支)、`parallel`(并行分支)、`branch`(分支头),其余类型均按普通节点渲染 |
|
|
186
|
+
| title | 节点标题 |
|
|
187
|
+
| content | 节点内容;分支容器设置了 `content` 时会展示容器头部,可点击编辑 |
|
|
188
|
+
| children | 分支容器的分支列表,格式为 `[[branch, ...nodes], ...]`,每个分支以一个 `branch` 节点开头 |
|
|
189
|
+
|
|
190
|
+
节点外层会带上 `flow-chart-node-{type}` className,分支容器带上 `flow-chart-{type}-node` className,节点卡片带上 `flow-chart-node-content` className。
|
|
191
|
+
|
|
192
|
+
#### treeUtil
|
|
193
|
+
|
|
194
|
+
导出 `treeUtil`:`findNode`、`appendNode`、`removeNode`、`replaceNode`、`isBranchContainer`,用于在外部操作节点树。
|