Skip to content

Commit 7b5745d

Browse files
committed
add FlowNodeHistory
1 parent 885c415 commit 7b5745d

4 files changed

Lines changed: 113 additions & 69 deletions

File tree

frontend/apps/app-pc/src/pages/todo.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ const TodoPage: React.FC = () => {
180180
key={"create"}
181181
type={'primary'}
182182
onClick={() => {
183+
setCurrentRecordId('');
183184
setSelectVisible(true);
184185
}}>发起流程</Button>
185186
)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from "react";
2+
import {useApprovalContext} from "@/components/flow-approval/hooks/use-approval-context";
3+
import {ProcessNode} from "@/components/flow-approval/typings";
4+
5+
export interface FlowNodeHistoryAction{
6+
refresh:()=>void;
7+
}
8+
9+
interface FlowNodeHistoryProps{
10+
actionRef?:React.Ref<FlowNodeHistoryAction>;
11+
}
12+
13+
export const FlowNodeHistory: React.FC<FlowNodeHistoryProps> = (props) => {
14+
15+
const {context} = useApprovalContext();
16+
17+
const [processNodes, setProcessNodes] = React.useState<ProcessNode[]>([]);
18+
19+
const triggerProcessNodes = () => {
20+
context.getPresenter().processNodes().then(nodes => {
21+
setProcessNodes(nodes);
22+
});
23+
}
24+
25+
React.useEffect(()=>{
26+
triggerProcessNodes();
27+
},[]);
28+
29+
React.useImperativeHandle(props.actionRef,()=>{
30+
return {
31+
refresh:()=>{
32+
triggerProcessNodes();
33+
}
34+
}
35+
},[]);
36+
37+
return (
38+
<div>
39+
流转历史 {processNodes.length}
40+
</div>
41+
)
42+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import React from "react";
2+
import {useApprovalContext} from "@/components/flow-approval/hooks/use-approval-context";
3+
import {ViewPlugin} from "@/plugins/view";
4+
import { Form } from "antd";
5+
6+
interface FormViewComponentProps{
7+
onValuesChange?:(values:any)=>void;
8+
}
9+
10+
export const FormViewComponent: React.FC<FormViewComponentProps> = (props) => {
11+
const {state, context} = useApprovalContext();
12+
const ViewComponent = ViewPlugin.getInstance().get(state.flow?.view || 'default');
13+
// 是否可合并审批
14+
const mergeable = state.flow?.mergeable || false;
15+
const todos = state.flow?.todos || [];
16+
const viewForms = todos.length>0?todos.map(item => {
17+
return {
18+
instance: Form.useForm()[0],
19+
data: item.data,
20+
}
21+
}):[
22+
{
23+
instance: Form.useForm()[0],
24+
data: undefined,
25+
}
26+
]
27+
28+
React.useEffect(() => {
29+
viewForms.forEach(item => {
30+
const formInstance = item.instance;
31+
const data = item.data;
32+
context.getPresenter().getFormActionContext().addAction({
33+
save(): any {
34+
return formInstance.getFieldsValue();
35+
},
36+
key(): string {
37+
return 'view-form'
38+
}
39+
});
40+
formInstance.setFieldsValue(data);
41+
});
42+
}, []);
43+
44+
if (ViewComponent) {
45+
if (mergeable) {
46+
return (
47+
<div>
48+
<h3>合并审批</h3>
49+
</div>
50+
)
51+
}
52+
return (
53+
<>
54+
{viewForms.map((item, index) => (
55+
<ViewComponent
56+
key={index}
57+
form={item.instance}
58+
onValuesChange={props.onValuesChange}
59+
/>
60+
))}
61+
</>
62+
)
63+
}
64+
}

frontend/packages/flow-design/src/components/flow-approval/layout/body.tsx

Lines changed: 6 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,13 @@
11
import React from "react";
2-
import {useApprovalContext} from "@/components/flow-approval/hooks/use-approval-context";
3-
import {Col, Form, Row} from "antd";
4-
import {ViewPlugin} from "@/plugins/view";
5-
6-
interface FormViewComponentProps{
7-
onValuesChange?:(values:any)=>void;
8-
}
9-
10-
const FormViewComponent: React.FC<FormViewComponentProps> = (props) => {
11-
const {state, context} = useApprovalContext();
12-
const ViewComponent = ViewPlugin.getInstance().get(state.flow?.view || 'default');
13-
// 是否可合并审批
14-
const mergeable = state.flow?.mergeable || false;
15-
const todos = state.flow?.todos || [];
16-
const viewForms = todos.length>0?todos.map(item => {
17-
return {
18-
instance: Form.useForm()[0],
19-
data: item.data,
20-
}
21-
}):[
22-
{
23-
instance: Form.useForm()[0],
24-
data: undefined,
25-
}
26-
]
27-
28-
React.useEffect(() => {
29-
viewForms.forEach(item => {
30-
const formInstance = item.instance;
31-
const data = item.data;
32-
context.getPresenter().getFormActionContext().addAction({
33-
save(): any {
34-
return formInstance.getFieldsValue();
35-
},
36-
key(): string {
37-
return 'view-form'
38-
}
39-
});
40-
formInstance.setFieldsValue(data);
41-
});
42-
}, []);
43-
44-
if (ViewComponent) {
45-
if (mergeable) {
46-
return (
47-
<div>
48-
<h3>合并审批</h3>
49-
</div>
50-
)
51-
}
52-
return (
53-
<>
54-
{viewForms.map((item, index) => (
55-
<ViewComponent
56-
key={index}
57-
form={item.instance}
58-
onValuesChange={props.onValuesChange}
59-
/>
60-
))}
61-
</>
62-
)
63-
}
64-
}
2+
import {Col, Row} from "antd";
3+
import {FormViewComponent} from "@/components/flow-approval/components/form-view-component";
4+
import {FlowNodeHistory, FlowNodeHistoryAction} from "@/components/flow-approval/components/flow-node-history";
655

666
export const Body = () => {
67-
68-
const {state, context} = useApprovalContext();
7+
const flowNodeHistoryAction = React.useRef<FlowNodeHistoryAction>(null);
698

709
const handleValuesChange = (values:any) => {
71-
context.getPresenter().processNodes().then(nodes => {
72-
console.log('流程节点:', nodes);
73-
});
10+
flowNodeHistoryAction.current?.refresh();
7411
}
7512

7613
return (
@@ -82,7 +19,7 @@ export const Body = () => {
8219
/>
8320
</Col>
8421
<Col span={6}>
85-
流转历史
22+
<FlowNodeHistory actionRef={flowNodeHistoryAction}/>
8623
</Col>
8724
</Row>
8825
)

0 commit comments

Comments
 (0)