@hzab/flowlong-designer 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -1
- package/README.md +24 -1
- package/package.json +4 -1
- package/src/components/NodeWrap/Nodes/Approver/index.tsx +32 -20
- package/src/components/NodeWrap/Nodes/Approver/options.ts +5 -4
- package/src/components/NodeWrap/Nodes/Branch/components/Field/index.tsx +30 -0
- package/src/components/NodeWrap/Nodes/Branch/components/GroupUserSelectorModal/index.less +4 -0
- package/src/components/NodeWrap/Nodes/Branch/components/GroupUserSelectorModal/index.tsx +97 -0
- package/src/components/NodeWrap/Nodes/Branch/index.less +40 -3
- package/src/components/NodeWrap/Nodes/Branch/index.tsx +34 -9
- package/src/components/NodeWrap/Nodes/Promoter/index.tsx +2 -2
- package/src/components/NodeWrap/Nodes/Send/index.less +3 -0
- package/src/components/NodeWrap/Nodes/Send/index.tsx +293 -95
- package/src/components/NodeWrap/Nodes/Send/options.ts +45 -0
- package/src/components/Selector/SelectContext.tsx +13 -9
- package/src/components/Selector/index.tsx +11 -194
- package/src/index.tsx +34 -10
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useRef, useState, useContext, useEffect } from "react";
|
|
2
2
|
import { Modal, Input, Button, Tree, Checkbox, Pagination, Avatar } from "antd";
|
|
3
3
|
import { RightOutlined, DeleteOutlined } from "@ant-design/icons";
|
|
4
|
-
|
|
4
|
+
import GroupUserSelector from "@hzab/group-user-selector";
|
|
5
5
|
import { SelectContext } from "./SelectContext";
|
|
6
6
|
|
|
7
7
|
import "./index.less";
|
|
@@ -11,163 +11,27 @@ const titleMap = ["人员选择", "角色选择"];
|
|
|
11
11
|
|
|
12
12
|
export const Selector = (props) => {
|
|
13
13
|
const selectorCtx = useContext(SelectContext);
|
|
14
|
-
const { open, type, value, onSave,
|
|
15
|
-
|
|
16
|
-
{
|
|
17
|
-
title: "Group-111",
|
|
18
|
-
key: "g-111",
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
title: "Group-222",
|
|
22
|
-
key: "g-222",
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
title: "Group-333",
|
|
26
|
-
key: "g-333",
|
|
27
|
-
},
|
|
28
|
-
]);
|
|
29
|
-
const [options, setOptions] = useState([
|
|
30
|
-
|
|
31
|
-
]);
|
|
32
|
-
|
|
33
|
-
const [roleOptions, setRoleOptions] = useState([
|
|
34
|
-
{
|
|
35
|
-
title: "Role-111",
|
|
36
|
-
key: "r-111",
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
title: "Role-222",
|
|
40
|
-
key: "r-222",
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
title: "Role-333",
|
|
44
|
-
key: "r-333",
|
|
45
|
-
},
|
|
46
|
-
]);
|
|
47
|
-
const [selected, setSelected] = useState(Array.isArray(value) ? value?.map((it) => it.id || it.key) : []);
|
|
48
|
-
const selectedRef = useRef(
|
|
49
|
-
Array.isArray(value)
|
|
50
|
-
? value?.map((it) => ({
|
|
51
|
-
...it,
|
|
52
|
-
title: it.name,
|
|
53
|
-
key: it.id,
|
|
54
|
-
}))
|
|
55
|
-
: [],
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const handleGetTree = () => {
|
|
60
|
-
treeModel?.get()
|
|
61
|
-
.then((res) => {
|
|
62
|
-
setGroupOptions(res);
|
|
63
|
-
})
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const handleGetList = (data?: any) => {
|
|
67
|
-
(type == 2 ? roleListModel :listModel)?.get(data || {})
|
|
68
|
-
.then((res) => {
|
|
69
|
-
setOptions(roleOptions);
|
|
70
|
-
})
|
|
71
|
-
};
|
|
14
|
+
const { open, type, value, onSave, roleListConfig, listConfig, initiatorListConfig, drawerType } =
|
|
15
|
+
selectorCtx.selectHandler;
|
|
72
16
|
|
|
73
|
-
|
|
74
|
-
if (type == 2) {
|
|
75
|
-
handleGetList();
|
|
76
|
-
} else if (type == 1) {
|
|
77
|
-
handleGetTree();
|
|
78
|
-
}
|
|
79
|
-
}, [type]);
|
|
80
|
-
|
|
81
|
-
useEffect(() => {
|
|
82
|
-
|
|
83
|
-
setSelected(Array.isArray(value) ? value?.map((it) => it.id || it.key) : []);
|
|
84
|
-
selectedRef.current = Array.isArray(value)
|
|
85
|
-
? value?.map((it) => ({
|
|
86
|
-
...it,
|
|
87
|
-
title: it.name,
|
|
88
|
-
key: it.id,
|
|
89
|
-
}))
|
|
90
|
-
: [];
|
|
91
|
-
}, [value]);
|
|
92
|
-
|
|
93
|
-
const pageRef = useRef(1);
|
|
94
|
-
const keywordRef = useRef("");
|
|
95
|
-
const keyIdRef = useRef(undefined);
|
|
96
|
-
const groupTreeRef = useRef();
|
|
17
|
+
const selectorRef = useRef(undefined);
|
|
97
18
|
|
|
98
19
|
function onModalSave() {
|
|
99
|
-
onSave && onSave(
|
|
20
|
+
onSave && onSave(selectorRef.current?.selectedList || []);
|
|
100
21
|
onModalClose();
|
|
101
22
|
}
|
|
102
23
|
|
|
103
24
|
function onModalClose() {
|
|
104
|
-
setSelected([]);
|
|
105
|
-
selectedRef.current = [];
|
|
106
25
|
selectorCtx.onClose();
|
|
107
26
|
}
|
|
108
27
|
|
|
109
|
-
function onSearch(value, event) {
|
|
110
|
-
// keywordRef.current = value;
|
|
111
|
-
handleGetList({orgId:keyIdRef.current, name:value});
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function groupClick(value, node) {
|
|
116
|
-
handleGetList({orgId:value});
|
|
117
|
-
keyIdRef.current = value;
|
|
118
|
-
|
|
119
|
-
// keywordRef.current = "";
|
|
120
|
-
// pageRef.current = 1;
|
|
121
|
-
// getUserOptions(value);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function getUserOptions(id) {
|
|
125
|
-
// TODO: 请求并设置用户列表
|
|
126
|
-
setTimeout(() => {
|
|
127
|
-
const list = [];
|
|
128
|
-
for (let i = 0; i < 10; i++) {
|
|
129
|
-
list.push({
|
|
130
|
-
title: "User-" + id + "-" + list.length,
|
|
131
|
-
key: "u-" + id + "-" + list.length,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
console.log(list);
|
|
135
|
-
|
|
136
|
-
// pageRef.current
|
|
137
|
-
setOptions(list);
|
|
138
|
-
}, 100);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function onUserCheck(key) {
|
|
142
|
-
|
|
143
|
-
const is = selected.includes(key);
|
|
144
|
-
if (!is) {
|
|
145
|
-
setSelected([...selected, key])
|
|
146
|
-
const item = options.find((it) => it.key === key);
|
|
147
|
-
selectedRef.current = [...selectedRef.current, {
|
|
148
|
-
...item,
|
|
149
|
-
id: item.key,
|
|
150
|
-
name: item.title,
|
|
151
|
-
}]
|
|
152
|
-
} else {
|
|
153
|
-
setSelected(selected.filter((it) => it !== key));
|
|
154
|
-
selectedRef.current = selectedRef.current.filter((it) => it.key !== key);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function deleteSelected(key) {
|
|
159
|
-
setSelected(selected.filter((it) => it !== key));
|
|
160
|
-
selectedRef.current = selectedRef.current.filter((it) => it.key !== key);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
28
|
return (
|
|
165
29
|
<div className="selector">
|
|
166
30
|
<Modal
|
|
167
31
|
wrapClassName="selector-modal"
|
|
168
32
|
open={open}
|
|
169
33
|
title={titleMap[type - 1]}
|
|
170
|
-
width={
|
|
34
|
+
width={850}
|
|
171
35
|
destroyOnClose
|
|
172
36
|
getContainer="body"
|
|
173
37
|
onCancel={onModalClose}
|
|
@@ -180,58 +44,11 @@ export const Selector = (props) => {
|
|
|
180
44
|
</div>
|
|
181
45
|
}
|
|
182
46
|
>
|
|
183
|
-
<
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
<div className="sc-user-select__select">
|
|
189
|
-
{type == 1 ? <div className="sc-user-select__tree" v-loading="showGrouploading">
|
|
190
|
-
<Tree className="menu" ref={groupTreeRef} treeData={groupOptions} onSelect={groupClick} />
|
|
191
|
-
</div> : null}
|
|
192
|
-
<div className="sc-user-select__user" v-loading="showUserloading">
|
|
193
|
-
<div className="sc-user-select__user__list">
|
|
194
|
-
{options?.map((item) => {
|
|
195
|
-
return (
|
|
196
|
-
<div className="sc-user-select__user__item" key={item.key}>
|
|
197
|
-
<Checkbox
|
|
198
|
-
checked={selected.includes(item.key)}
|
|
199
|
-
onChange={(e) => onUserCheck(item.key)}
|
|
200
|
-
>
|
|
201
|
-
{item.title}
|
|
202
|
-
</Checkbox>
|
|
203
|
-
</div>
|
|
204
|
-
)
|
|
205
|
-
})}
|
|
206
|
-
</div>
|
|
207
|
-
<footer>
|
|
208
|
-
<Pagination simple size="small" total={50} showSizeChanger showQuickJumper></Pagination>
|
|
209
|
-
</footer>
|
|
210
|
-
</div>
|
|
211
|
-
</div>
|
|
212
|
-
</div>
|
|
213
|
-
<div className="sc-user-select__toicon">
|
|
214
|
-
<RightOutlined />
|
|
215
|
-
</div>
|
|
216
|
-
<div className="sc-user-select__selected">
|
|
217
|
-
<header>已选 ({selected?.length ?? 0})</header>
|
|
218
|
-
<ul className="sc-user-select__selected-list">
|
|
219
|
-
{selectedRef.current?.map((item, idx) => {
|
|
220
|
-
return (
|
|
221
|
-
<li key={item.id ?? item.key}>
|
|
222
|
-
<span className="name">
|
|
223
|
-
<Avatar size="small">{item.title?.substring(0, 1)}</Avatar>
|
|
224
|
-
<label>{item.title}</label>
|
|
225
|
-
</span>
|
|
226
|
-
<span className="delete">
|
|
227
|
-
<DeleteOutlined onClick={() => deleteSelected(item.id ?? item.key)}></DeleteOutlined>
|
|
228
|
-
</span>
|
|
229
|
-
</li>
|
|
230
|
-
);
|
|
231
|
-
})}
|
|
232
|
-
</ul>
|
|
233
|
-
</div>
|
|
234
|
-
</div>
|
|
47
|
+
<GroupUserSelector
|
|
48
|
+
ref={selectorRef}
|
|
49
|
+
{...(drawerType == 1 ? initiatorListConfig : type == 2 ? roleListConfig : listConfig)}
|
|
50
|
+
value={value}
|
|
51
|
+
/>
|
|
235
52
|
</Modal>
|
|
236
53
|
</div>
|
|
237
54
|
);
|
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect,
|
|
1
|
+
import { useEffect, useImperativeHandle, forwardRef, useState } from "react";
|
|
2
2
|
import { Button, Drawer } from "antd";
|
|
3
3
|
|
|
4
4
|
import ScWorkflow from "./components/ScWorkflow";
|
|
@@ -43,21 +43,27 @@ function copy(str) {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
function FlowlongDesigner(props) {
|
|
47
|
-
const { value, flowName,
|
|
46
|
+
function FlowlongDesigner(props, ref) {
|
|
47
|
+
const { value, flowName, roleListConfig, listConfig, initiatorListConfig } = props;
|
|
48
48
|
const [drawer, setDrawer] = useState(false);
|
|
49
49
|
const [zoom, setZoom] = useState(1);
|
|
50
50
|
const [data, setData] = useState(Object.keys(value || {}).length > 0 ? value : getInitNodeData({ name: flowName }));
|
|
51
51
|
const [selectHandler, setSelectHandler] = useState<ISelectHandlerI>({
|
|
52
52
|
open: false,
|
|
53
53
|
type: -1,
|
|
54
|
+
drawerType: -1,
|
|
54
55
|
value: [],
|
|
55
56
|
onSave: (s) => {},
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
roleListConfig: {},
|
|
58
|
+
listConfig: {},
|
|
59
|
+
initiatorListConfig: {},
|
|
59
60
|
});
|
|
60
61
|
|
|
62
|
+
// 通过useImperativeHandle定义要抛出的值或方法
|
|
63
|
+
useImperativeHandle(ref, () => ({
|
|
64
|
+
data,
|
|
65
|
+
}));
|
|
66
|
+
|
|
61
67
|
useEffect(() => {
|
|
62
68
|
value && setData(value);
|
|
63
69
|
}, [value]);
|
|
@@ -79,11 +85,29 @@ function FlowlongDesigner(props) {
|
|
|
79
85
|
<SelectContext.Provider
|
|
80
86
|
value={{
|
|
81
87
|
selectHandler,
|
|
82
|
-
setSelectHandler(type, value, onSave) {
|
|
83
|
-
setSelectHandler({
|
|
88
|
+
setSelectHandler(type, value, onSave, drawerType) {
|
|
89
|
+
setSelectHandler({
|
|
90
|
+
open: true,
|
|
91
|
+
type,
|
|
92
|
+
drawerType,
|
|
93
|
+
value,
|
|
94
|
+
onSave,
|
|
95
|
+
roleListConfig,
|
|
96
|
+
listConfig,
|
|
97
|
+
initiatorListConfig,
|
|
98
|
+
});
|
|
84
99
|
},
|
|
85
100
|
onClose() {
|
|
86
|
-
setSelectHandler({
|
|
101
|
+
setSelectHandler({
|
|
102
|
+
open: false,
|
|
103
|
+
type: -1,
|
|
104
|
+
drawerType: -1,
|
|
105
|
+
value: [],
|
|
106
|
+
onSave: (s) => {},
|
|
107
|
+
roleListConfig,
|
|
108
|
+
listConfig,
|
|
109
|
+
initiatorListConfig,
|
|
110
|
+
});
|
|
87
111
|
},
|
|
88
112
|
}}
|
|
89
113
|
>
|
|
@@ -131,4 +155,4 @@ function FlowlongDesigner(props) {
|
|
|
131
155
|
);
|
|
132
156
|
}
|
|
133
157
|
|
|
134
|
-
export default FlowlongDesigner;
|
|
158
|
+
export default forwardRef(FlowlongDesigner);
|