Skip to content

Commit 438e82f

Browse files
committed
add custom event
1 parent 19241ad commit 438e82f

File tree

9 files changed

+127
-26
lines changed

9 files changed

+127
-26
lines changed

admin-ui/src/components/Flow/flow/FlowDetail.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React from "react";
22
import { Divider, Result } from "antd";
33
import { ProForm, ProFormTextArea } from "@ant-design/pro-components";
4-
import { FlowFormView, FlowFormViewProps } from "@/components/Flow/flow/types";
4+
import {CustomButtonType, FlowFormView, FlowFormViewProps} from "@/components/Flow/flow/types";
55
import { FlowData } from "@/components/Flow/flow/data";
6+
import {useDispatch, useSelector} from "react-redux";
7+
import {clearTriggerClick, FlowReduxState} from "@/components/Flow/store/FlowSlice";
68

79
interface FlowDetailProps {
810
view: React.ComponentType<FlowFormViewProps> | FlowFormView;
@@ -11,24 +13,41 @@ interface FlowDetailProps {
1113
adviceForm: any;
1214
review?: boolean;
1315
flowData: FlowData;
16+
// 流程交互操作
17+
handlerClick: (data: {
18+
type: CustomButtonType;
19+
id?: string;
20+
}) => void;
1421
}
1522

1623
const FlowDetail: React.FC<FlowDetailProps> = (props) => {
1724
const flowData = props.flowData;
1825

1926
const FlowFormView = flowData.getFlowFormView(props.view) as React.ComponentType<FlowFormViewProps>;
2027

28+
// 触发点击事件
29+
const triggerClickVisible = useSelector((state: FlowReduxState) => state.flow.triggerClickVisible);
30+
31+
// flow store redux
32+
const dispatch = useDispatch();
33+
2134
return (
2235
<>
2336
<div className="flowApprovalViewBox">
2437
{FlowFormView && (
2538
<div className="flowViewDetail" style={{ height: !FlowFormView || flowData.isStartFlow() ? '85vh' : '68vh' }}>
2639
<FlowFormView
40+
handlerClick={props.handlerClick}
2741
data={flowData.getFlowData()}
2842
form={props.form}
43+
flowData={flowData}
2944
visible={props.visible}
3045
editable={!flowData.isDone() && flowData.getFlowNodeEditable()}
3146
compare={!flowData.isStartFlow()}
47+
triggerClickVisible={triggerClickVisible}
48+
clearTriggerClick={() => {
49+
dispatch(clearTriggerClick());
50+
}}
3251
/>
3352
</div>
3453
)}

admin-ui/src/components/Flow/flow/FlowTabs.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import {FlowData} from "@/components/Flow/flow/data";
33
import {Skeleton, Tabs} from "antd";
4-
import {FlowFormView, FlowFormViewProps} from "@/components/Flow/flow/types";
4+
import {CustomButtonType, FlowFormView, FlowFormViewProps} from "@/components/Flow/flow/types";
55
import {FormInstance} from "antd/es/form/hooks/useForm";
66
import FlowHistory from "@/components/Flow/flow/FlowHistory";
77
import FlowChart from "@/components/Flow/flow/FlowChart";
@@ -16,6 +16,12 @@ interface FlowTabsProps {
1616
adviceForm: FormInstance<any>;
1717
// 预览模式
1818
review?: boolean;
19+
20+
// 流程交互操作
21+
handlerClick: (data: {
22+
type: CustomButtonType;
23+
id?: string;
24+
}) => void;
1925
}
2026

2127
const FlowTabs: React.FC<FlowTabsProps> = (props) => {
@@ -66,6 +72,7 @@ const FlowTabs: React.FC<FlowTabsProps> = (props) => {
6672
label: '流程详情',
6773
children: (
6874
<FlowDetail
75+
handlerClick={props.handlerClick}
6976
flowData={flowData}
7077
adviceForm={props.adviceForm}
7178
form={props.form}

admin-ui/src/components/Flow/flow/events.tsx

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ import {custom, postponed, recall, saveFlow, startFlow, submitFlow, transfer, tr
55
import {message} from "antd";
66
import {useDispatch, useSelector} from "react-redux";
77
import {
8-
clearUserSelect, closeUserSelect,
8+
clearTriggerClick,
9+
clearUserSelect,
10+
closeUserSelect,
911
FlowReduxState,
1012
setUserSelectModal,
1113
showPostponed,
12-
showResult
14+
showResult,
15+
triggerClick
1316
} from "@/components/Flow/store/FlowSlice";
1417
import {FlowUser} from "@/components/Flow/flow/types";
1518

@@ -28,6 +31,8 @@ export const registerEvents = (id: string,
2831

2932
const selectUserType = useSelector((state: FlowReduxState) => state.flow.userSelectType);
3033

34+
const triggerClickVisible = useSelector((state: FlowReduxState) => state.flow.triggerClickVisible);
35+
3136
const dispatch = useDispatch();
3237

3338
let recordId = id;
@@ -126,7 +131,7 @@ export const registerEvents = (id: string,
126131
}
127132

128133
// 提交流程
129-
const handleSubmitFlow = (flowState: boolean, callback: (res: any) => void,operatorIds?:any[]) => {
134+
const handleSubmitFlow = (flowState: boolean, callback: (res: any) => void, operatorIds?: any[]) => {
130135
const advice = adviceForm.getFieldValue('advice');
131136
setRequestLoading(true);
132137

@@ -135,7 +140,7 @@ export const registerEvents = (id: string,
135140
const body = {
136141
recordId,
137142
advice: advice,
138-
operatorIds:operatorIds,
143+
operatorIds: operatorIds,
139144
success: flowState,
140145
formData: {
141146
...flowData,
@@ -292,22 +297,25 @@ export const registerEvents = (id: string,
292297
handlerTransferFlow(currentUser);
293298
}
294299

295-
if(selectUserType === 'nextNodeUser' && selectUsers && selectUsers.length > 0){
296-
handleSubmitFlow(true,(res)=>{
300+
if (selectUserType === 'nextNodeUser' && selectUsers && selectUsers.length > 0) {
301+
handleSubmitFlow(true, (res) => {
297302
const flowSubmitResultBuilder = new FlowSubmitResultBuilder(res.data);
298303
dispatch(closeUserSelect());
299304
dispatch(showResult({
300305
closeFlow: true,
301306
result: flowSubmitResultBuilder.builder()
302307
}));
303-
},selectUsers.map((item:FlowUser)=> {
308+
}, selectUsers.map((item: FlowUser) => {
304309
return item.id;
305310
}));
306311
}
307312
}, [selectUsers]);
308313

309314

310-
return (button: any) => {
315+
return (button: {
316+
type: string,
317+
id?: string
318+
}) => {
311319
switch (button.type) {
312320
case 'SAVE': {
313321
// 保存流程,如果没有创建流程先创建,若已经创建则保存
@@ -336,16 +344,16 @@ export const registerEvents = (id: string,
336344
});
337345
const approvalType = res.data.flowNode.approvalType;
338346
dispatch(setUserSelectModal({
339-
mode: approvalType==='SIGN'?'single':'multiple',
347+
mode: approvalType === 'SIGN' ? 'single' : 'multiple',
340348
type: 'nextNodeUser',
341349
visible: true,
342350
specifyUserIds: userIds
343351
}));
344352
});
345353
}
346-
if(recordId){
354+
if (recordId) {
347355
_trySubmitFlow();
348-
}else{
356+
} else {
349357
handlerStartFlow((id) => {
350358
recordId = id;
351359
_trySubmitFlow();
@@ -415,13 +423,24 @@ export const registerEvents = (id: string,
415423
break;
416424
}
417425
case 'CUSTOM': {
418-
if (recordId) {
419-
handleCustomFlow(button.id);
426+
if (button.id) {
427+
const buttonId = button.id;
428+
if (recordId) {
429+
handleCustomFlow(buttonId);
430+
} else {
431+
handlerStartFlow((id) => {
432+
recordId = id;
433+
handleCustomFlow(buttonId);
434+
});
435+
}
436+
}
437+
break;
438+
}
439+
case 'VIEW': {
440+
if (triggerClickVisible) {
441+
dispatch(clearTriggerClick());
420442
} else {
421-
handlerStartFlow((id) => {
422-
recordId = id;
423-
handleCustomFlow(button.id);
424-
});
443+
dispatch(triggerClick());
425444
}
426445
break;
427446
}

admin-ui/src/components/Flow/flow/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ const $FlowView: React.FC<FlowViewProps> = (props) => {
169169
}
170170
>
171171
<FlowTabs
172+
handlerClick={handlerClicks}
172173
flowData={new FlowData(data, props.formParams)}
173174
view={props.view}
174175
visible={props.visible}

admin-ui/src/components/Flow/flow/types.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import React from "react";
2-
import { FormInstance } from "antd/es/form/hooks/useForm";
2+
import {FormInstance} from "antd/es/form/hooks/useForm";
3+
import {FlowData} from "@/components/Flow/flow/data";
4+
5+
// 自定义按钮类型
6+
export type CustomButtonType = 'SAVE' | 'START' | 'SUBMIT' | 'TRY_SUBMIT' | 'SPECIFY_SUBMIT' | 'REJECT' | 'TRANSFER' | 'RECALL' | 'POSTPONED' | 'URGE' | 'CUSTOM' | 'VIEW';
37

48
// 表单视图属性
59
export interface FlowFormViewProps {
@@ -15,9 +19,21 @@ export interface FlowFormViewProps {
1519
compare: boolean;
1620
// 审批意见
1721
opinions?: any;
22+
// 流程详情数据信息
23+
flowData?: FlowData;
24+
// 流程交互操作
25+
handlerClick?: (item: {
26+
type: CustomButtonType;
27+
id?: string;
28+
}) => void;
29+
30+
// 自定义前端点击事件触发
31+
triggerClickVisible?: boolean;
32+
33+
// 关闭自定义前端点击事件触发
34+
clearTriggerClick?: () => void;
1835
}
1936

20-
2137
// 表单视图
2238
export interface FlowFormView {
2339
[key: string]: React.ComponentType<FlowFormViewProps>;
@@ -44,7 +60,7 @@ export const ResultFormViewKey = 'ResultFormView';
4460

4561
export interface FlowResultMessage {
4662
title: string,
47-
resultState:string,
63+
resultState: string,
4864
items: FlowResultItem[]
4965
}
5066

admin-ui/src/components/Flow/panel/ButtonPanel.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {Button, ColorPicker, Popconfirm, Space} from "antd";
1414
import FlowUtils from "@/components/Flow/utils";
1515
import ScriptModal from "@/components/Flow/panel/ScriptModal";
1616
import {EyeOutlined, ReloadOutlined} from "@ant-design/icons";
17+
import {CustomButtonType} from "@/components/Flow/flow/types";
1718

1819
interface ButtonPanelProps {
1920
id: string;
@@ -61,10 +62,17 @@ const buttonEventOptions = [
6162
value: "URGE"
6263
},
6364
{
64-
label: "自定义",
65+
label: "自定义接口",
6566
value: "CUSTOM"
6667
},
67-
]
68+
{
69+
label: "自定义事件",
70+
value: "VIEW"
71+
},
72+
] as {
73+
label: string;
74+
value: CustomButtonType;
75+
}[];
6876

6977

7078
const ButtonPanel: React.FC<ButtonPanelProps> = (props) => {
@@ -224,7 +232,7 @@ const ButtonPanel: React.FC<ButtonPanelProps> = (props) => {
224232
</Space>
225233
)}
226234
normalize={(value) => {
227-
if(value) {
235+
if (value) {
228236
return {
229237
background: value.toHexString()
230238
};

admin-ui/src/components/Flow/store/FlowSlice.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export interface FlowStore {
2424
currentUsers: FlowUser[];
2525
// 指定人员
2626
specifyUserIds: number[];
27+
28+
// 自定义前端点击事件触发
29+
triggerClickVisible: boolean;
2730
}
2831

2932
export type FlowStoreAction = {
@@ -46,6 +49,9 @@ export type FlowStoreAction = {
4649
setSelectUsers: (state: FlowStore, action: PayloadAction<FlowUser[]>) => void;
4750
closeUserSelect: (state: FlowStore) => void;
4851
clearUserSelect: (state: FlowStore) => void;
52+
53+
triggerClick: (state: FlowStore) => void;
54+
clearTriggerClick: (state: FlowStore) => void;
4955
}
5056

5157
export const flowSlice = createSlice<FlowStore, FlowStoreAction, "flow", {}>({
@@ -61,6 +67,7 @@ export const flowSlice = createSlice<FlowStore, FlowStoreAction, "flow", {}>({
6167
resultCloseFlow: false,
6268
currentUsers: [],
6369
specifyUserIds: [],
70+
triggerClickVisible: false
6471
},
6572
reducers: {
6673
showPostponed: (state) => {
@@ -108,6 +115,14 @@ export const flowSlice = createSlice<FlowStore, FlowStoreAction, "flow", {}>({
108115
state.currentUsers = [];
109116
state.specifyUserIds = [];
110117
state.userSelectType = null;
118+
},
119+
120+
triggerClick: (state) => {
121+
state.triggerClickVisible = true;
122+
},
123+
124+
clearTriggerClick: (state) => {
125+
state.triggerClickVisible = false;
111126
}
112127
},
113128
});
@@ -122,7 +137,9 @@ export const {
122137
clearUserSelect,
123138
setUserSelectModal,
124139
closeUserSelect,
125-
setSelectUsers
140+
setSelectUsers,
141+
triggerClick,
142+
clearTriggerClick
126143
} = flowSlice.actions;
127144
export const flowStore = configureStore({
128145
reducer: {

admin-ui/src/pages/flow/leave/LeaveForm.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, {useEffect} from "react";
22
import {ProForm, ProFormDigit, ProFormText, ProFormTextArea} from "@ant-design/pro-components";
33
import {FlowFormViewProps} from "@/components/Flow/flow/types";
4+
import {Button} from "antd";
45

56

67
const LeaveForm: React.FC<FlowFormViewProps> = (props) => {
@@ -9,6 +10,8 @@ const LeaveForm: React.FC<FlowFormViewProps> = (props) => {
910
props.form.setFieldsValue(props.data);
1011
}, []);
1112

13+
const triggerClickVisible = props.triggerClickVisible;
14+
1215

1316
return (
1417
<ProForm
@@ -50,6 +53,15 @@ const LeaveForm: React.FC<FlowFormViewProps> = (props) => {
5053
}
5154
]}
5255
/>
56+
57+
{triggerClickVisible && (
58+
<Button
59+
onClick={()=>{
60+
props.clearTriggerClick && props.clearTriggerClick();
61+
}}
62+
>点击了自定义事件</Button>
63+
)}
64+
5365
</ProForm>
5466
)
5567
}

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/em/FlowButtonType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ public enum FlowButtonType {
2424
URGE,
2525
// 自定义
2626
CUSTOM,
27+
// 前端
28+
VIEW,
2729
}

0 commit comments

Comments
 (0)