Skip to content

Commit 851367b

Browse files
committed
add test assert
1 parent 08f2ed3 commit 851367b

File tree

25 files changed

+167
-78
lines changed

25 files changed

+167
-78
lines changed

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@ import {ProForm, ProFormTextArea} from "@ant-design/pro-components";
44
import {CustomButtonType, FlowFormView, FlowFormViewProps} from "@/components/Flow/flow/types";
55
import {FlowData} from "@/components/Flow/flow/data";
66
import {useDispatch, useSelector} from "react-redux";
7-
import {
8-
clearTriggerClick,
9-
FlowReduxState,
10-
hideOpinionEditor,
11-
showOpinionEditor
12-
} from "@/components/Flow/store/FlowSlice";
7+
import {FlowReduxState, hideOpinionEditor, showOpinionEditor} from "@/components/Flow/store/FlowSlice";
138
import {FormInstance} from "antd/es/form/hooks/useForm";
149

1510
interface FlowDetailProps {
1611
view: React.ComponentType<FlowFormViewProps> | FlowFormView;
17-
visible: boolean;
18-
form: any;
12+
form: FormInstance<any>;
1913
adviceForm: FormInstance<any>;
2014
review?: boolean;
2115
flowData: FlowData;
16+
// 请求数据加载
17+
requestLoading: boolean;
18+
// 设置请求数据加载状态
19+
setRequestLoading: (loading: boolean) => void;
2220
// 流程交互操作
2321
handlerClick: (data: {
2422
type: CustomButtonType;
@@ -31,23 +29,26 @@ const FlowDetail: React.FC<FlowDetailProps> = (props) => {
3129

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

34-
// 触发点击事件
35-
const triggerClickVisible = useSelector((state: FlowReduxState) => state.flow.triggerClickVisible);
32+
// 触发点击事件Key
33+
const eventKey = useSelector((state: FlowReduxState) => state.flow.eventKey);
3634

3735
// 审批意见输入框
3836
const opinionEditorVisible = useSelector((state: FlowReduxState) => state.flow.opinionEditorVisible);
3937

38+
// 流程视图内容
39+
const flowViewVisible = useSelector((state: FlowReduxState) => state.flow.flowViewVisible);
40+
4041
// flow store redux
4142
const dispatch = useDispatch();
4243

4344
useEffect(() => {
44-
if(props.visible){
45+
if (flowViewVisible) {
4546
const advice = flowData.getOpinionAdvice();
4647
props.adviceForm.setFieldsValue({
4748
advice: advice
4849
});
4950
}
50-
}, [props.visible]);
51+
}, [flowViewVisible]);
5152

5253
return (
5354
<>
@@ -60,21 +61,20 @@ const FlowDetail: React.FC<FlowDetailProps> = (props) => {
6061
data={flowData.getFlowData()}
6162
form={props.form}
6263
flowData={flowData}
63-
visible={props.visible}
64+
visible={flowViewVisible}
6465
opinions={flowData.getOpinions()}
6566
editable={!flowData.isDone() && flowData.getFlowNodeEditable()}
6667
compare={!flowData.isStartFlow()}
67-
triggerClickVisible={triggerClickVisible}
68+
eventKey={eventKey}
69+
requestLoading={props.requestLoading}
70+
setRequestLoading={props.setRequestLoading}
6871
opinionEditorVisible={(visible) => {
6972
if (visible) {
7073
dispatch(showOpinionEditor());
7174
} else {
7275
dispatch(hideOpinionEditor());
7376
}
7477
}}
75-
clearTriggerClick={() => {
76-
dispatch(clearTriggerClick());
77-
}}
7878
/>
7979
</div>
8080
)}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@ import {FormInstance} from "antd/es/form/hooks/useForm";
66
import FlowHistory from "@/components/Flow/flow/FlowHistory";
77
import FlowChart from "@/components/Flow/flow/FlowChart";
88
import FlowDetail from "@/components/Flow/flow/FlowDetail";
9+
import {useSelector} from "react-redux";
10+
import {FlowReduxState} from "@/components/Flow/store/FlowSlice";
911

1012

1113
interface FlowTabsProps {
1214
flowData: FlowData;
1315
view: React.ComponentType<FlowFormViewProps> | FlowFormView;
14-
visible: boolean;
1516
form: FormInstance<any>;
1617
adviceForm: FormInstance<any>;
1718
// 预览模式
1819
review?: boolean;
20+
// 请求数据加载
21+
requestLoading: boolean;
22+
// 设置请求数据加载状态
23+
setRequestLoading: (loading: boolean) => void;
1924

2025
// 流程交互操作
2126
handlerClick: (data: {
@@ -76,7 +81,8 @@ const FlowTabs: React.FC<FlowTabsProps> = (props) => {
7681
flowData={flowData}
7782
adviceForm={props.adviceForm}
7883
form={props.form}
79-
visible={props.visible}
84+
requestLoading={props.requestLoading}
85+
setRequestLoading={props.setRequestLoading}
8086
view={props.view}/>
8187
),
8288
},

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import React from "react";
22
import {Button, Space} from "antd";
33
import {FlowData} from "@/components/Flow/flow/data";
44
import FlowButtons from "@/components/Flow/flow/FlowButtons";
5+
import {useDispatch} from "react-redux";
6+
import {hideFlowView} from "@/components/Flow/store/FlowSlice";
57

68
interface FlowTitleProps {
7-
setVisible: (visible: boolean) => void;
89
flowData: FlowData;
910
requestLoading: boolean;
1011
setRequestLoading: (loading: boolean) => void;
@@ -17,6 +18,9 @@ const FlowTitle: React.FC<FlowTitleProps> = (props) => {
1718

1819
const title = flowData.getCurrentNodeTitle();
1920

21+
// flow store redux
22+
const dispatch = useDispatch();
23+
2024
return (
2125
<div style={{display: 'flex', justifyContent: 'space-between', alignItems: 'center'}}>
2226
<h3 style={{margin: 0}}>{title}</h3>
@@ -31,7 +35,7 @@ const FlowTitle: React.FC<FlowTitleProps> = (props) => {
3135

3236
<Button
3337
onClick={() => {
34-
props.setVisible(false);
38+
dispatch(hideFlowView());
3539
}}
3640
>
3741
关闭

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ export class FlowData extends FlowWorkData {
132132
return null;
133133
}
134134

135+
// 获取当前节点的按钮
136+
getNodeButton = (buttonId: string) => {
137+
if (this.data) {
138+
const buttons = this.data.flowNode.buttons;
139+
if(buttons){
140+
return buttons.find((item:any) => item.id === buttonId);
141+
}
142+
}
143+
return null;
144+
}
145+
135146
// 获取当前节点的标题
136147
getCurrentNodeTitle = () => {
137148
if (this.data) {

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +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-
clearTriggerClick,
8+
clearTriggerEventClick,
99
clearUserSelect,
1010
closeUserSelect,
1111
FlowReduxState,
1212
setUserSelectModal,
1313
showPostponed,
1414
showResult,
15-
triggerClick
15+
triggerEventClick
1616
} from "@/components/Flow/store/FlowSlice";
1717
import {FlowUser} from "@/components/Flow/flow/types";
1818

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

3232
const selectUserType = useSelector((state: FlowReduxState) => state.flow.userSelectType);
3333

34-
const triggerClickVisible = useSelector((state: FlowReduxState) => state.flow.triggerClickVisible);
35-
3634
const dispatch = useDispatch();
3735

3836
let recordId = id;
@@ -437,10 +435,13 @@ export const registerEvents = (id: string,
437435
break;
438436
}
439437
case 'VIEW': {
440-
if (triggerClickVisible) {
441-
dispatch(clearTriggerClick());
442-
} else {
443-
dispatch(triggerClick());
438+
if (button.id) {
439+
const buttonId = button.id;
440+
const customButton = data.getNodeButton(buttonId);
441+
dispatch(triggerEventClick(customButton.eventKey));
442+
setTimeout(()=>{
443+
dispatch(clearTriggerEventClick());
444+
},300);
444445
}
445446
break;
446447
}

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import {
2323
clearResult,
2424
closeUserSelect,
2525
FlowReduxState,
26-
flowStore,
26+
flowStore, hideFlowView,
2727
setSelectUsers,
28-
setTimeOut
28+
setTimeOut, showFlowView
2929
} from "@/components/Flow/store/FlowSlice";
3030
import "./index.scss";
3131

@@ -80,7 +80,8 @@ const $FlowView: React.FC<FlowViewProps> = (props) => {
8080
const userSelectMode = useSelector((state: FlowReduxState) => state.flow.userSelectMode);
8181
// 选人类型
8282
const userSelectType = useSelector((state: FlowReduxState) => state.flow.userSelectType);
83-
83+
// 流程视图内容
84+
const flowViewVisible = useSelector((state: FlowReduxState) => state.flow.flowViewVisible);
8485

8586
// flow store redux
8687
const dispatch = useDispatch();
@@ -110,11 +111,22 @@ const $FlowView: React.FC<FlowViewProps> = (props) => {
110111
setData(null);
111112
setRecordId(props.id);
112113
if (props.visible) {
114+
dispatch(showFlowView());
113115
loadFlowDetail();
116+
}else{
117+
dispatch(hideFlowView());
114118
}
115119
}, [props.visible]);
116120

117121

122+
// 关闭视图时回掉父级关闭对象
123+
useEffect(() => {
124+
if(!flowViewVisible){
125+
props.setVisible(false);
126+
}
127+
}, [flowViewVisible]);
128+
129+
118130
// 注册事件
119131
const handlerClicks = registerEvents(
120132
recordId,
@@ -160,7 +172,6 @@ const $FlowView: React.FC<FlowViewProps> = (props) => {
160172
closable={false}
161173
title={
162174
<FlowTitle
163-
setVisible={props.setVisible}
164175
flowData={new FlowData(data, props.formParams)}
165176
requestLoading={requestLoading}
166177
setRequestLoading={setRequestLoading}
@@ -174,7 +185,8 @@ const $FlowView: React.FC<FlowViewProps> = (props) => {
174185
handlerClick={handlerClicks}
175186
flowData={new FlowData(data, props.formParams)}
176187
view={props.view}
177-
visible={props.visible}
188+
requestLoading={requestLoading}
189+
setRequestLoading={setRequestLoading}
178190
form={viewForm}
179191
adviceForm={adviceForm}
180192
review={props.review}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react";
22
import {FormInstance} from "antd/es/form/hooks/useForm";
33
import {FlowData} from "@/components/Flow/flow/data";
4+
import {clearTriggerEventClick} from "@/components/Flow/store/FlowSlice";
45

56
// 自定义按钮类型
67
export type CustomButtonType = 'SAVE' | 'START' | 'SUBMIT' | 'TRY_SUBMIT' | 'SPECIFY_SUBMIT' | 'REJECT' | 'TRANSFER' | 'RECALL' | 'POSTPONED' | 'URGE' | 'CUSTOM' | 'VIEW';
@@ -27,11 +28,13 @@ export interface FlowFormViewProps {
2728
id?: string;
2829
}) => void;
2930

30-
// 自定义前端点击事件触发
31-
triggerClickVisible?: boolean;
31+
// 请求数据加载
32+
requestLoading?: boolean;
33+
// 设置请求数据加载状态
34+
setRequestLoading?: (loading: boolean) => void;
3235

33-
// 关闭自定义前端点击事件触发
34-
clearTriggerClick?: () => void;
36+
// 自定义前端点击事件触发事件
37+
eventKey?: string;
3538

3639
// 审批意见输入框
3740
opinionEditorVisible?: (visible: boolean) => void;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,20 @@ const ButtonPanel: React.FC<ButtonPanelProps> = (props) => {
284284
}}
285285
/>
286286

287+
{type === 'VIEW' && (
288+
<ProFormText
289+
name={"eventKey"}
290+
label={"事件Key"}
291+
tooltip={"事件Key用于流程Form的事件触发"}
292+
rules={[
293+
{
294+
required: true,
295+
message: '请输入事件Key'
296+
}
297+
]}
298+
/>
299+
)}
300+
287301
<ProFormText
288302
name={"groovy"}
289303
hidden={true}

0 commit comments

Comments
 (0)