Skip to content

Commit 1129663

Browse files
committed
backup
1 parent 750a4ae commit 1129663

File tree

7 files changed

+103
-4
lines changed

7 files changed

+103
-4
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { Button, Modal } from "antd"
2+
import { memo, useState } from "react"
3+
import { useEditorStore } from "../../workflow-editor"
4+
import { useTranslate } from "../../workflow-editor/react-locales"
5+
import { CloseCircleOutlined } from "@ant-design/icons"
6+
import { styled } from "styled-components"
7+
8+
const Title = styled.div`
9+
display: flex;
10+
align-items: center;
11+
`
12+
13+
const ErrorIcon = styled(CloseCircleOutlined)`
14+
color: red;
15+
font-size: 20px;
16+
margin-right: 8px;
17+
`
18+
19+
const Tip = styled.div`
20+
color: ${props => props.theme.token?.colorTextSecondary};
21+
`
22+
23+
export interface ErrorItem {
24+
category: string,
25+
message: string,
26+
}
27+
28+
export const PublishButton = memo(() => {
29+
const [errors, setErrors] = useState<ErrorItem[]>();
30+
31+
const t = useTranslate()
32+
const editorStore = useEditorStore()
33+
34+
const handleValidate = () => {
35+
setErrors([{ category: "", message: "" }]);
36+
};
37+
38+
const handleOk = () => {
39+
setErrors(undefined);
40+
};
41+
42+
const handleCancel = () => {
43+
setErrors(undefined);
44+
};
45+
46+
return (
47+
<>
48+
<Button type="primary" onClick={handleValidate}>{t("publish")}</Button>
49+
<Modal
50+
title={
51+
<Title>
52+
<ErrorIcon />
53+
{t("cantNotPublish")}
54+
</Title>
55+
}
56+
open={!!errors?.length}
57+
cancelText={t("gotIt")}
58+
okText={t("gotoEdit")}
59+
onOk={handleOk}
60+
onCancel={handleCancel}
61+
>
62+
<Tip>
63+
{t("canNotPublishTip")}
64+
</Tip>
65+
<p>Some contents...</p>
66+
<p>Some contents...</p>
67+
<p>Some contents...</p>
68+
</Modal >
69+
</>
70+
)
71+
})

src/example/WorkflowEditor/WorkFlowEditorInner.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import classNames from "classnames"
66
import { NavTabs, Toolbar, WorkflowDiagram, useImport } from "../../workflow-editor"
77
import { useTranslate } from "../../workflow-editor/react-locales"
88
import { useExport } from "../../workflow-editor"
9+
import { PublishButton } from "./PublishButton"
910

1011
const Container = styled.div`
1112
flex:1;
@@ -30,6 +31,7 @@ export const WorkFlowEditorInner = memo((props: {
3031
const t = useTranslate()
3132
const exportjson = useExport()
3233
const importJson = useImport()
34+
3335
const items: MenuProps['items'] = useMemo(() => [
3436
{
3537
label: t("import"),
@@ -64,7 +66,7 @@ export const WorkFlowEditorInner = memo((props: {
6466
<Button type="text" icon={<QuestionCircleOutlined />}>{t("help")}</Button>
6567
<Button type="text" icon={<MobileOutlined />}>{t("preview")}</Button>
6668
<Button type="text" icon={<SaveOutlined />}>{t("save")}</Button>
67-
<Button type="primary">{t("publish")}</Button>
69+
<PublishButton />
6870
<Dropdown menu={{ items }} trigger={['click']}>
6971
<Button icon={<EllipsisOutlined />} />
7072
</Dropdown>

src/example/materialUis.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,24 @@ export const materialUis: IMaterialUIs = {
1111
return <ContentPlaceholder secondary text={t("pleaseChooseApprover")} />
1212
},
1313
settingsPanel: ApproverPanel,
14+
validate: (node: IWorkFlowNode<IApproverSettings>, { t }) => {
15+
if (!node.config) {
16+
return (t("noSelectedApprover"))
17+
}
18+
return true
19+
}
1420
},
1521
[NodeType.audit]: {
1622
viewContent: (node: IWorkFlowNode<IAuditSettings>, { t }) => {
1723
return <ContentPlaceholder secondary text={t("pleaseChooseDealer")} />
1824
},
1925
settingsPanel: AuditPanel,
26+
validate: (node: IWorkFlowNode<IApproverSettings>, { t }) => {
27+
if (!node.config) {
28+
return (t("noSelectedDealer"))
29+
}
30+
return true
31+
}
2032
},
2133
[NodeType.condition]: {
2234
viewContent: (node: IWorkFlowNode<IConditionSettings>, { t }) => {

src/workflow-editor/classes/EditorStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Store } from "redux"
2-
import { IState } from "../interfaces/state"
2+
import { IErrors, IState } from "../interfaces/state"
33
import { configureStore } from "@reduxjs/toolkit"
44
import { mainReducer } from "../reducers"
55
import { RedoListChangeListener, SelectedListener, StartNodeListener, UndoListChangeListener } from "../interfaces/listeners"
@@ -19,7 +19,7 @@ export class EditorStore {
1919
this.store = makeStoreInstance(debugMode || false)
2020
}
2121

22-
validate = () => {
22+
validate = (): IErrors | true => {
2323
throw new Error("Not implements")
2424
}
2525

src/workflow-editor/interfaces/material.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export interface IMaterialUI<FlowNode extends IWorkFlowNode, Settings = any, Con
2222
viewContent?: (node: FlowNode, context: Context) => React.ReactNode
2323
//属性面板设置组件
2424
settingsPanel?: React.FC<{ value: Settings, onChange: (value: Settings) => void }>
25+
//校验失败返回错误消息,成功返回ture
26+
validate?: (node: FlowNode, context: Context) => string | true
2527
}
2628

2729
export interface IMaterialUIs {

src/workflow-editor/interfaces/workflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface IWorkFlowNode<Config = unknown> {
1919
name?: string
2020
desc?: string
2121
childNode?: IWorkFlowNode
22-
const?: Config
22+
config?: Config
2323
}
2424

2525
export interface IRouteNode extends IWorkFlowNode {

src/workflow-editor/locales.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ export const defalutLocales: ILocales = {
4646
search: "搜索",
4747
operateSuccess: "操作成功",
4848
fileIllegal: "文件不合法",
49+
noSelectedApprover: "未选择审批人",
50+
noSelectedDealer: "未选择办理人",
51+
cantNotPublish: "当前无法发布",
52+
canNotPublishTip: "以下内容不完善,请修改后发布",
53+
gotIt: "我知道了",
54+
gotoEdit: "前往修改",
4955
},
5056
'en-US': {
5157
baseSettings: "Base Settings",
@@ -92,5 +98,11 @@ export const defalutLocales: ILocales = {
9298
search: "Search",
9399
operateSuccess: "Operate success",
94100
fileIllegal: "File Illegal",
101+
noSelectedApprover: "No selected approver",
102+
noSelectedDealer: "NO selected dealer",
103+
cantNotPublish: "Can not publish",
104+
canNotPublishTip: "The following content is incomplete, please modify and publish it",
105+
gotIt: "Got it",
106+
gotoEdit: "Goto Edit",
95107
}
96108
}

0 commit comments

Comments
 (0)