Skip to content

Commit e3ab7a1

Browse files
committed
重构
1 parent 4f9f76f commit e3ab7a1

File tree

12 files changed

+54
-35
lines changed

12 files changed

+54
-35
lines changed

src/example/WorkflowEditor/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
自定义编辑器参考这个

src/example/materialUis.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IMaterialUIs, IWorkFlowNode, NodeType } from "../workflow-editor";
1+
import { ContentPlaceholder, IMaterialUIs, IWorkFlowNode, NodeType } from "../workflow-editor";
22
import { ApproverPanel, IApproverSettings } from "./setterss/ApproverPanel";
33
import { AuditPanel, IAuditSettings } from "./setterss/AuditPanel";
44
import { ConditionPanel, IConditionSettings } from "./setterss/ConditionPanel";
@@ -7,32 +7,32 @@ import { IStartSettings, StartPanel } from "./setterss/StartPanel";
77

88
export const materialUis: IMaterialUIs = {
99
[NodeType.approver]: {
10-
viewContent: (node: IWorkFlowNode<IApproverSettings>)=>{
11-
return <></>
10+
viewContent: (node: IWorkFlowNode<IApproverSettings>, { t }) => {
11+
return <ContentPlaceholder secondary text={t("pleaseChooseApprover")} />
1212
},
1313
settingsPanel: ApproverPanel,
1414
},
1515
[NodeType.audit]: {
16-
viewContent: (node: IWorkFlowNode<IAuditSettings>)=>{
17-
return <></>
16+
viewContent: (node: IWorkFlowNode<IAuditSettings>, { t }) => {
17+
return <ContentPlaceholder secondary text={t("pleaseChooseDealer")} />
1818
},
1919
settingsPanel: AuditPanel,
2020
},
2121
[NodeType.condition]: {
22-
viewContent: (node: IWorkFlowNode<IConditionSettings>)=>{
23-
return <></>
22+
viewContent: (node: IWorkFlowNode<IConditionSettings>, { t }) => {
23+
return <ContentPlaceholder text={t("pleaseSetCondition")} />
2424
},
2525
settingsPanel: ConditionPanel,
2626
},
2727
[NodeType.notifier]: {
28-
viewContent: (node: IWorkFlowNode<INotifierSettings>)=>{
29-
return <></>
28+
viewContent: (node: IWorkFlowNode<INotifierSettings>, { t }) => {
29+
return <ContentPlaceholder text={t("pleaseChooseNotifier")} />
3030
},
3131
settingsPanel: NotifierPanel,
3232
},
3333
[NodeType.start]: {
34-
viewContent: (node: IWorkFlowNode<IStartSettings>)=>{
35-
return <></>
34+
viewContent: (node: IWorkFlowNode<IStartSettings>, { t }) => {
35+
return <ContentPlaceholder text={t("allMember")} />
3636
},
3737
settingsPanel: StartPanel,
3838
},

src/example/setterss/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
本目录定义属性面板表单,会跟业务结合

src/workflow-editor/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
本目录会作为NPM包发布

src/workflow-editor/WorkflowDiagram/defaultMaterials.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ export const defaultMaterials: INodeMaterial[] = [
1717
color: "#ff943e",
1818
label: "approver",
1919
icon: sealIcon,
20-
placeholder: "pleaseChooseApprover",
21-
placeholderSecondary: true,
2220
defaultConfig: {
2321
nodeType: NodeType.approver,
2422
},
@@ -27,7 +25,6 @@ export const defaultMaterials: INodeMaterial[] = [
2725
color: "#4ca3fb",
2826
label: "notifier",
2927
icon: notifierIcon,
30-
placeholder: "pleaseChooseNotifier",
3128
defaultConfig: {
3229
nodeType: NodeType.notifier,
3330
},
@@ -36,18 +33,15 @@ export const defaultMaterials: INodeMaterial[] = [
3633
color: "#fb602d",
3734
label: "dealer",
3835
icon: dealIcon,
39-
placeholder: "pleaseChooseDealer",
40-
placeholderSecondary: true,
4136
defaultConfig: {
4237
nodeType: NodeType.audit,
4338
},
4439
},
4540
{
4641
color: "#15bc83",
47-
label: "conditionNode",
42+
label: "routeNode",
4843
icon: conditionIcon,
49-
createDefault: (context) => {
50-
const { t } = context
44+
createDefault: ({t}) => {
5145
return {
5246
id: createUuid(),
5347
nodeType: NodeType.route,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { memo } from "react"
2+
import className from "classnames"
3+
4+
export const ContentPlaceholder = memo((
5+
props: {
6+
text?: string,
7+
secondary?: boolean,
8+
}
9+
) => {
10+
const { text, secondary } = props
11+
return (
12+
<span
13+
className={className("text", secondary ? " secondary" : "")}>
14+
{text}
15+
</span>
16+
)
17+
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from "./MemberSelect"
22
export * from "./ButtonSelect"
3+
export * from "./ContentPlaceholder"
34
export * from "./NavTabs"
45
export * from "./Toolbar"

src/workflow-editor/interfaces/material.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import { IWorkFlowNode } from "./workflow"
22

3-
export interface INodeMaterial<Context = any> {
3+
export interface IContext {
4+
//翻译
5+
t: (msg: string) => string | undefined
6+
}
7+
8+
export interface INodeMaterial<Context extends IContext = IContext> {
49
color: string
510
label: string
611
icon?: React.ReactElement
7-
placeholder?: string
8-
//浅色显示placeholder
9-
placeholderSecondary?: boolean,
1012
//默认配置
1113
defaultConfig?: IWorkFlowNode
1214
//创建一个默认节点,跟defaultCofig只选一个
13-
createDefault?: (context?: Context) => IWorkFlowNode
15+
createDefault?: (context: Context) => IWorkFlowNode
1416
//从物料面板隐藏,比如发起人节点
1517
hidden?: boolean
1618
}
1719

1820

1921
export interface IMaterialUI<FlowNode extends IWorkFlowNode, Settings = any, Context = any> {
20-
viewContent?: (node: FlowNode, context?: Context) => React.ReactNode
22+
viewContent?: (node: FlowNode, context: Context) => React.ReactNode
2123
//属性面板设置组件
2224
settingsPanel?: React.FC<{ value: Settings, onChange: (value: Settings) => void }>
2325
}

src/workflow-editor/locales.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const defalutLocales: ILocales = {
1515
approver: "审批人",
1616
notifier: "抄送人",
1717
dealer: "办理人",
18-
conditionNode: "条件分支",
18+
routeNode: "条件分支",
1919
condition: "条件",
2020
promoter: "发起人",
2121
allMember: "所有人",
@@ -59,7 +59,7 @@ export const defalutLocales: ILocales = {
5959
approver: "Approver",
6060
notifier: "Notifier",
6161
dealer: "Dealer",
62-
conditionNode: "Condition Branch",
62+
routeNode: "Condition Branch",
6363
condition: "Condition",
6464
promoter: "Promoter",
6565
allMember: "All",

src/workflow-editor/nodes/NormalNode.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useTranslate } from "../react-locales"
1111
import { useEditorStore } from "../hooks"
1212
import { NodeTitle } from "./NodeTitle"
1313
import { useNodeMaterial } from "../hooks/useNodeMaterial"
14+
import { useMaterialUI } from "../hooks/useMaterialUI"
1415

1516
export const NodeWrap = styled.div`
1617
display: flex;
@@ -118,6 +119,7 @@ export const NormalNode = memo((
118119
const { node } = props
119120
const t = useTranslate()
120121
const material = useNodeMaterial(node)
122+
const materialUi = useMaterialUI(node)
121123
const store = useEditorStore();
122124

123125
const handleClick = useCallback(() => {
@@ -129,10 +131,7 @@ export const NormalNode = memo((
129131
<NodeWrapBox className="node-wrap-box" onClick={handleClick}>
130132
<NodeTitle node={node} material={material} />
131133
<NodeContent className="content">
132-
<span
133-
className={"text" + ((material?.placeholderSecondary && !node.desc) ? " secondary" : "")}>
134-
{node.desc || t(material?.placeholder || "")}
135-
</span>
134+
{materialUi?.viewContent && materialUi?.viewContent(node, { t })}
136135
<RightOutlined className="arrow" />
137136
</NodeContent>
138137
</NodeWrapBox>

0 commit comments

Comments
 (0)