Skip to content

Commit 1e0c2b3

Browse files
committed
重构
1 parent 8194a08 commit 1e0c2b3

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/workflow-editor/WorkflowDiagram/defaultMaterials.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
import { conditionIcon, dealIcon, notifierIcon, sealIcon } from "../icons";
1+
import { routeIcon, dealIcon, notifierIcon, sealIcon } from "../icons";
22
import { NodeType } from "../interfaces";
33
import { INodeMaterial } from "../interfaces/material";
44
import { createUuid } from "../utils/create-uuid";
55

66
export const defaultMaterials: INodeMaterial[] = [
7+
//发起人节点
78
{
9+
//标题,引擎会通过国际化t函数翻译
810
label: "promoter",
11+
//颜色
912
color: "rgb(87, 106, 149)",
13+
//引擎会直接去defaultConfig来生成一个节点,会克隆一份defaultConfig数据保证immutable
1014
defaultConfig: {
15+
//默认配置,可以把类型上移一层,但是如果增加其它默认属性的话,不利于扩展
1116
nodeType: NodeType.start,
1217
},
1318
//不在物料板显示
1419
hidden: true,
1520
},
21+
//审批人节点
1622
{
1723
color: "#ff943e",
1824
label: "approver",
@@ -21,6 +27,7 @@ export const defaultMaterials: INodeMaterial[] = [
2127
nodeType: NodeType.approver,
2228
},
2329
},
30+
//通知人节点
2431
{
2532
color: "#4ca3fb",
2633
label: "notifier",
@@ -37,11 +44,12 @@ export const defaultMaterials: INodeMaterial[] = [
3744
nodeType: NodeType.audit,
3845
},
3946
},
47+
//条件节点
4048
{
4149
color: "#15bc83",
4250
label: "routeNode",
43-
icon: conditionIcon,
44-
createDefault: ({t}) => {
51+
icon: routeIcon,
52+
createDefault: ({ t }) => {
4553
return {
4654
id: createUuid(),
4755
nodeType: NodeType.route,
@@ -61,6 +69,7 @@ export const defaultMaterials: INodeMaterial[] = [
6169
},
6270

6371
},
72+
//分支节点
6473
{
6574
label: "condition",
6675
color: "",

src/workflow-editor/icons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const dealIcon = <span role="img" className="anticon">
3232
</svg>
3333
</span>
3434

35-
export const conditionIcon = <span role="img" className="anticon">
35+
export const routeIcon = <span role="img" className="anticon">
3636
<svg width='1em' height="1em" fill="currentColor" viewBox="0 0 1024 1024">
3737
<path d="M525.96 69.895l256.652 124.437c15.903 7.71 22.544 26.852 14.834 42.755a32 32 0 0 1-14.834 14.833L544 367.61V472c0 1.006-0.023 2.006-0.07 3H720c34.993 0 63.426 28.084 63.991 62.942L784 539v123h96c17.673 0 32 14.327 32 32v186c0 17.673-14.327 32-32 32H624c-17.673 0-32-14.327-32-32V694c0-17.673 14.327-32 32-32h96V539H304v123h96c17.673 0 32 14.327 32 32v186c0 17.673-14.327 32-32 32H144c-17.673 0-32-14.327-32-32V694c0-17.673 14.327-32 32-32h96V539c0-34.993 28.084-63.426 62.942-63.991L304 475h176V367.61L241.388 251.92c-15.903-7.71-22.544-26.852-14.834-42.755a32 32 0 0 1 14.834-14.833L498.039 69.895a32 32 0 0 1 27.922 0z" p-id="41560"></path>
3838
</svg>

src/workflow-editor/nodes/AddButton/MaterialItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export const MaterialItem = memo((
4949
const newId = createUuid()
5050
const newName = t(material.label)
5151
if (material.defaultConfig) {
52-
editorStore?.addNode(nodeId, { ...material.defaultConfig, id: newId, name: newName })
52+
//复制一份配置数据,保证immutable
53+
editorStore?.addNode(nodeId, { ...JSON.parse(JSON.stringify(material.defaultConfig)), id: newId, name: newName })
5354
} else if (material.createDefault) {
5455
editorStore?.addNode(nodeId, { ...material.createDefault({ t }), name: newName })
5556
} else {

0 commit comments

Comments
 (0)