Skip to content

Commit f35d17e

Browse files
committed
add UserSelectView
1 parent 6c98c4f commit f35d17e

File tree

8 files changed

+147
-21
lines changed

8 files changed

+147
-21
lines changed

admin-ui/src/api/user.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {page, post} from "@/api/index";
1+
import {page, post,get} from "@/api/index";
22

33
export async function list(
44
params: any,
@@ -12,6 +12,10 @@ export async function list(
1212
return page('/api/query/user/list', params, sort, filter, match);
1313
}
1414

15+
export async function users() {
16+
return get('/api/query/user/list', {current:1,pageSize:999999});
17+
}
18+
1519

1620
export async function save(body: any) {
1721
return post('/api/cmd/user/save', body);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import React, {useEffect} from "react";
2+
import {UserSelectProps} from "@/components/Flow/flow/types";
3+
import {ModalForm, ProForm, ProFormSelect} from "@ant-design/pro-components";
4+
import {users} from "@/api/user";
5+
6+
7+
const UserSelectView: React.FC<UserSelectProps> = (props) => {
8+
9+
const [form] = ProForm.useForm();
10+
11+
const [userList, setUserList] = React.useState<any[]>([]);
12+
13+
useEffect(() => {
14+
users().then((res) => {
15+
if (res.success) {
16+
const list = res.data.list.filter((item:any)=>{
17+
const specifyUserIds = props.specifyUserIds;
18+
if(specifyUserIds && specifyUserIds.length > 0){
19+
return specifyUserIds.includes(item.id);
20+
}
21+
});
22+
setUserList(list);
23+
// 默认选中当前用户
24+
form.setFieldValue("users", props.currentUserIds);
25+
}
26+
})
27+
}, []);
28+
29+
return (
30+
<ModalForm
31+
form={form}
32+
open={props.visible}
33+
title={"用户选择(模拟测试)"}
34+
modalProps={{
35+
onCancel: () => {
36+
props.setVisible(false);
37+
},
38+
onClose: () => {
39+
props.setVisible(false);
40+
}
41+
}}
42+
onFinish={async (values) => {
43+
const users = values.users;
44+
const selectedUsers = userList.filter((item: any) => {
45+
return users.includes(item.id);
46+
});
47+
props.onFinish(selectedUsers);
48+
props.setVisible(false);
49+
}}
50+
>
51+
<ProFormSelect
52+
mode={"tags"}
53+
name={"users"}
54+
label={"用户"}
55+
options={userList.map((item: any) => {
56+
return {
57+
label: item.name,
58+
value: item.id
59+
}
60+
})}
61+
/>
62+
</ModalForm>
63+
)
64+
}
65+
66+
export default UserSelectView;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export const registerEvents = (id: string,
292292
handlerTransferFlow(currentUser);
293293
}
294294

295-
if(selectUserType === 'flow' && selectUsers && selectUsers.length > 0){
295+
if(selectUserType === 'nextNodeUser' && selectUsers && selectUsers.length > 0){
296296
handleSubmitFlow(true,(res)=>{
297297
const flowSubmitResultBuilder = new FlowSubmitResultBuilder(res.data);
298298
dispatch(closeUserSelect());
@@ -337,7 +337,7 @@ export const registerEvents = (id: string,
337337
const approvalType = res.data.flowNode.approvalType;
338338
dispatch(setUserSelectModal({
339339
mode: approvalType==='SIGN'?'single':'multiple',
340-
type: 'flow',
340+
type: 'nextNodeUser',
341341
visible: true,
342342
specifyUserIds: userIds
343343
}));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {Provider, useDispatch, useSelector} from "react-redux";
2121
import {
2222
clearPostponed,
2323
clearResult,
24-
clearUserSelect, closeUserSelect,
24+
closeUserSelect,
2525
FlowReduxState,
2626
flowStore,
2727
setSelectUsers,
@@ -204,7 +204,7 @@ const $FlowView: React.FC<FlowViewProps> = (props) => {
204204
/>
205205
)}
206206

207-
{UserSelectView && (
207+
{UserSelectView && userSelectType && (
208208
<UserSelectView
209209
visible={userSelectVisible}
210210
setVisible={() => {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ export const UserSelectViewKey = 'UserSelectView';
6767

6868
export type UserSelectMode = 'single' | 'multiple';
6969

70+
export type UserSelectType =
71+
// 选择下级流程节点的人员,约定人员id范围
72+
'nextNodeUser'
73+
// 选择转办人员,约定本单位下的人员
74+
| 'transfer'
75+
// 选择所有人员,在流程配置上使用
76+
| 'users';
77+
7078
export interface FlowUser {
7179
id: string;
7280
name: string;
@@ -83,6 +91,8 @@ export interface UserSelectProps {
8391
mode: UserSelectMode;
8492
// 指定人员范围
8593
specifyUserIds: number[];
94+
// 当前选择的人员
95+
currentUserIds?: number[];
8696
// 选人类型
87-
userSelectType: string;
97+
userSelectType: UserSelectType;
8898
}

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

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React from "react";
2-
import {Divider} from "antd";
2+
import {Button, Divider, Space} from "antd";
33
import {ProForm, ProFormDigit, ProFormSelect, ProFormSwitch, ProFormText} from "@ant-design/pro-components";
4-
import {EyeOutlined} from "@ant-design/icons";
4+
import {EyeOutlined, SettingOutlined} from "@ant-design/icons";
55
import GroovyScript from "@/components/Flow/utils/script";
66
import ScriptModal from "@/components/Flow/panel/ScriptModal";
7+
import {getComponent} from "@/framework/ComponentBus";
8+
import {UserSelectProps, UserSelectViewKey} from "@/components/Flow/flow/types";
79

810
interface NodePanelProps {
911
id?: string,
@@ -19,6 +21,14 @@ const NodePanel: React.FC<NodePanelProps> = (props) => {
1921

2022
const [visible, setVisible] = React.useState(false);
2123

24+
const [userSelectVisible, setUserSelectVisible] = React.useState(false);
25+
26+
const [operatorMatcherType, setOperatorMatcherType] = React.useState(props.data?.operatorMatcherType);
27+
28+
// 用户选人视图
29+
const UserSelectView = getComponent(UserSelectViewKey) as React.ComponentType<UserSelectProps>;
30+
31+
2232
return (
2333
<>
2434
<ProForm
@@ -123,18 +133,33 @@ const NodePanel: React.FC<NodePanelProps> = (props) => {
123133
},
124134
]}
125135
onChange={(value) => {
136+
setOperatorMatcherType(value as string);
126137
props.form.setFieldsValue({
127138
operatorMatcher: GroovyScript.operatorMatcher(value as string)
128139
})
129140
}}
130141
addonAfter={(
131-
<EyeOutlined
132-
onClick={() => {
133-
const value = props.form.getFieldValue("operatorMatcher");
134-
form.setFieldValue("type", "operatorMatcher");
135-
form.setFieldValue("script", value);
136-
setVisible(true);
137-
}}/>
142+
<Space>
143+
{operatorMatcherType==='custom' && (
144+
<Button
145+
icon={<SettingOutlined/>}
146+
onClick={() => {
147+
setUserSelectVisible(true);
148+
}}
149+
>
150+
选择人员
151+
</Button>
152+
)}
153+
154+
<EyeOutlined
155+
onClick={() => {
156+
const value = props.form.getFieldValue("operatorMatcher");
157+
form.setFieldValue("type", "operatorMatcher");
158+
form.setFieldValue("script", value);
159+
setVisible(true);
160+
}}/>
161+
162+
</Space>
138163
)}
139164
/>
140165

@@ -248,6 +273,25 @@ const NodePanel: React.FC<NodePanelProps> = (props) => {
248273
form={form}
249274
setVisible={setVisible}
250275
visible={visible}/>
276+
277+
{UserSelectView && (
278+
<UserSelectView
279+
visible={userSelectVisible}
280+
setVisible={setUserSelectVisible}
281+
userSelectType={"users"}
282+
specifyUserIds={[]}
283+
mode={"multiple"}
284+
onFinish={(values)=>{
285+
const operatorMatcher = props.form.getFieldValue("operatorMatcher");
286+
const script = operatorMatcher.replaceAll("%s", values.map((item:any)=>item.id).join(","));
287+
console.log(script);
288+
props.form.setFieldsValue({
289+
operatorMatcher: script
290+
});
291+
}}
292+
/>
293+
)}
294+
251295
</>
252296
)
253297
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {registerComponent} from "@/framework/ComponentBus";
22
import PostponedFormView from "@/components/Flow/components/PostponedFormView";
33
import ResultFormView from "@/components/Flow/components/ResultFormView";
4-
import {PostponedFormViewKey, ResultFormViewKey} from "@/components/Flow/flow/types";
4+
import {PostponedFormViewKey, ResultFormViewKey, UserSelectViewKey} from "@/components/Flow/flow/types";
5+
import UserSelectView from "@/components/Flow/components/UserSelectView";
56

67
registerComponent(PostponedFormViewKey, PostponedFormView);
78
registerComponent(ResultFormViewKey, ResultFormView);
9+
registerComponent(UserSelectViewKey, UserSelectView);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {configureStore, createSlice, PayloadAction} from '@reduxjs/toolkit';
2-
import {FlowResultMessage, FlowUser, UserSelectMode} from "@/components/Flow/flow/types";
2+
import {FlowResultMessage, FlowUser, UserSelectMode, UserSelectType} from "@/components/Flow/flow/types";
33

44
export interface FlowStore {
55
// 延期时间窗口
@@ -15,7 +15,7 @@ export interface FlowStore {
1515
resultCloseFlow: boolean;
1616

1717
// 选人类型
18-
userSelectType: string;
18+
userSelectType: UserSelectType | null;
1919
// 选人窗口
2020
userSelectVisible: boolean;
2121
// 选人模式
@@ -40,7 +40,7 @@ export type FlowStoreAction = {
4040
setUserSelectModal: (state: FlowStore, action: PayloadAction<{
4141
mode: UserSelectMode,
4242
visible: boolean,
43-
type: string,
43+
type: UserSelectType,
4444
specifyUserIds: number[]
4545
}>) => void;
4646
setSelectUsers: (state: FlowStore, action: PayloadAction<FlowUser[]>) => void;
@@ -57,7 +57,7 @@ export const flowSlice = createSlice<FlowStore, FlowStoreAction, "flow", {}>({
5757
resultVisible: false,
5858
userSelectVisible: false,
5959
userSelectMode: 'single',
60-
userSelectType: '',
60+
userSelectType: null,
6161
resultCloseFlow: false,
6262
currentUsers: [],
6363
specifyUserIds: [],
@@ -107,7 +107,7 @@ export const flowSlice = createSlice<FlowStore, FlowStoreAction, "flow", {}>({
107107
state.userSelectMode = 'single';
108108
state.currentUsers = [];
109109
state.specifyUserIds = [];
110-
state.userSelectType = '';
110+
state.userSelectType = null;
111111
}
112112
},
113113
});

0 commit comments

Comments
 (0)