@hzab/group-user-selector 0.0.4 → 0.0.5
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 +17 -0
- package/README.md +15 -3
- package/package.json +1 -1
- package/src/index.tsx +46 -32
package/CHANGELOG.md
CHANGED
|
@@ -1,2 +1,19 @@
|
|
|
1
|
+
# @hzab/group-user-selector@0.0.5
|
|
2
|
+
|
|
3
|
+
完善请求类型
|
|
4
|
+
|
|
5
|
+
# @hzab/group-user-selector@0.0.4
|
|
6
|
+
|
|
7
|
+
修复分页 bug
|
|
8
|
+
|
|
9
|
+
# @hzab/group-user-selector@0.0.3
|
|
10
|
+
|
|
11
|
+
增加列表自定义分页
|
|
12
|
+
|
|
13
|
+
# @hzab/group-user-selector@0.0.2
|
|
14
|
+
|
|
15
|
+
增加搜索列表自定义分页
|
|
16
|
+
|
|
1
17
|
# @hzab/group-user-selector@0.0.1
|
|
18
|
+
|
|
2
19
|
组件初始化
|
package/README.md
CHANGED
|
@@ -20,9 +20,21 @@ import Demo from "@hzab/group-user-selector";
|
|
|
20
20
|
|
|
21
21
|
### InfoPanel Attributes
|
|
22
22
|
|
|
23
|
-
| 参数
|
|
24
|
-
|
|
|
25
|
-
|
|
|
23
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
|
24
|
+
| ------------------- | ------- | ---- | -------- | ----------------------------------- |
|
|
25
|
+
| value | Object | 否 | [] | 选中的人员数据 |
|
|
26
|
+
| model | Object | 否 | - | 列表的请求 model (getListApi) |
|
|
27
|
+
| modelGetType | string | 否 | getList | 列表的请求类型 |
|
|
28
|
+
| searchModel | Object | 否 | - | 搜索列表的请求 model (getListApi) |
|
|
29
|
+
| queryKey | string | 否 | parentId | 列表的请求 model 的入参 key |
|
|
30
|
+
| searchQueryKey | string | 否 | search | 搜索列表的请求 model 的入参 key |
|
|
31
|
+
| labelKey | string | 否 | label | labelKey |
|
|
32
|
+
| valueKey | string | 否 | value | valueKey |
|
|
33
|
+
| imgKey | string | 否 | img | imgKey 头像 |
|
|
34
|
+
| isUserKey | string | 否 | isUser | 区分部门和人员 |
|
|
35
|
+
| hasPagination | boolean | 否 | true | 列表是否分页 |
|
|
36
|
+
| hasSearch | boolean | 否 | true | 是否有搜索 |
|
|
37
|
+
| hasSearchPagination | boolean | 否 | true | 搜索列表是否分页 |
|
|
26
38
|
|
|
27
39
|
# 组件开发流程
|
|
28
40
|
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { useEffect, useState, useImperativeHandle, forwardRef, useReducer, useRef } from "react";
|
|
2
2
|
import { Input, Breadcrumb, Checkbox, message, Spin, Pagination, ConfigProvider } from "antd";
|
|
3
|
-
import zhCN from
|
|
3
|
+
import zhCN from "antd/es/locale/zh_CN";
|
|
4
4
|
import { CloseCircleFilled, SearchOutlined } from "@ant-design/icons";
|
|
5
|
-
import
|
|
5
|
+
import "moment/locale/zh-cn";
|
|
6
6
|
import _ from "lodash";
|
|
7
7
|
|
|
8
8
|
import defaultAvatar from "./assets/imgs/defaultAvatar.png";
|
|
9
9
|
import department from "./assets/imgs/department.png";
|
|
10
|
-
import SearchRenter from
|
|
11
|
-
import ItemRenter from
|
|
10
|
+
import SearchRenter from "./components/SearchRenter";
|
|
11
|
+
import ItemRenter from "./components/ItemRenter";
|
|
12
12
|
|
|
13
13
|
import "./index.less";
|
|
14
14
|
|
|
@@ -22,6 +22,7 @@ function GroupSelection(props, ref) {
|
|
|
22
22
|
isUserKey = "isUser",
|
|
23
23
|
imgKey = "img",
|
|
24
24
|
hasPagination = true,
|
|
25
|
+
modelGetType = "getList",
|
|
25
26
|
} = props;
|
|
26
27
|
const [breadcrumb, setBreadcrumb] = useState([
|
|
27
28
|
{
|
|
@@ -36,11 +37,14 @@ function GroupSelection(props, ref) {
|
|
|
36
37
|
const [queryValue, setQueryValue] = useState(undefined);
|
|
37
38
|
const [total, setTotal] = useState(0);
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
const pageData = useRef(
|
|
41
|
+
hasPagination
|
|
42
|
+
? {
|
|
43
|
+
pageSize: 10,
|
|
44
|
+
pageNum: 1,
|
|
45
|
+
}
|
|
46
|
+
: {},
|
|
47
|
+
);
|
|
44
48
|
|
|
45
49
|
// 通过useImperativeHandle定义要抛出的值或方法
|
|
46
50
|
useImperativeHandle(ref, () => ({
|
|
@@ -56,35 +60,32 @@ function GroupSelection(props, ref) {
|
|
|
56
60
|
const getTreeData = (value?: string | number) => {
|
|
57
61
|
setLoading(true);
|
|
58
62
|
model &&
|
|
59
|
-
model
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
model[modelGetType]({ [queryKey]: value, ...pageData.current })
|
|
64
|
+
.then((res) => {
|
|
65
|
+
setSelectList(res?.list || res || []);
|
|
66
|
+
setTotal(res?.pagination?.total || res?.total || 0);
|
|
67
|
+
})
|
|
63
68
|
.catch((err) => {
|
|
64
|
-
|
|
69
|
+
message.error(err._message || "未知错误");
|
|
65
70
|
})
|
|
66
71
|
.finally(() => {
|
|
67
|
-
|
|
72
|
+
setLoading(false);
|
|
68
73
|
});
|
|
69
74
|
};
|
|
70
75
|
|
|
71
|
-
|
|
72
76
|
useEffect(() => {
|
|
73
77
|
getTreeData();
|
|
74
78
|
}, []);
|
|
75
79
|
|
|
76
|
-
|
|
77
80
|
const handleChangePage = (pageNum, pageSize) => {
|
|
78
81
|
const pages = {
|
|
79
82
|
pageNum: pageSize !== pageData.current?.pageSize ? 1 : pageNum,
|
|
80
|
-
pageSize
|
|
81
|
-
}
|
|
82
|
-
pageData.current = pages
|
|
83
|
-
|
|
84
|
-
getTreeData()
|
|
85
|
-
}
|
|
86
|
-
|
|
83
|
+
pageSize,
|
|
84
|
+
};
|
|
85
|
+
pageData.current = pages;
|
|
87
86
|
|
|
87
|
+
getTreeData();
|
|
88
|
+
};
|
|
88
89
|
|
|
89
90
|
const handleBreadcrumb = (e) => {
|
|
90
91
|
const index = breadcrumb.findIndex((item) => item[valueKey] === e[valueKey]);
|
|
@@ -155,17 +156,22 @@ function GroupSelection(props, ref) {
|
|
|
155
156
|
|
|
156
157
|
return (
|
|
157
158
|
<ConfigProvider locale={zhCN}>
|
|
158
|
-
|
|
159
159
|
<div className="group-selection">
|
|
160
|
-
{loading ?
|
|
161
|
-
<
|
|
162
|
-
|
|
160
|
+
{loading ? (
|
|
161
|
+
<div className="group-selection-loading">
|
|
162
|
+
<Spin tip="Loading..." spinning={loading} />
|
|
163
|
+
</div>
|
|
164
|
+
) : null}
|
|
163
165
|
<div className="group-selection-list">
|
|
164
166
|
<SearchRenter {...props} setLoading={setLoading} ItemRenter={Renter} />
|
|
165
167
|
<Breadcrumb className="group-selection-breadcrumb">
|
|
166
168
|
{breadcrumb.map((item) => {
|
|
167
169
|
return (
|
|
168
|
-
<Breadcrumb.Item
|
|
170
|
+
<Breadcrumb.Item
|
|
171
|
+
className="group-selection-breadcrumb-item"
|
|
172
|
+
onClick={() => handleBreadcrumb(item)}
|
|
173
|
+
key={item[valueKey]}
|
|
174
|
+
>
|
|
169
175
|
{item[labelKey]}
|
|
170
176
|
</Breadcrumb.Item>
|
|
171
177
|
);
|
|
@@ -179,9 +185,17 @@ function GroupSelection(props, ref) {
|
|
|
179
185
|
return Renter(item);
|
|
180
186
|
})}
|
|
181
187
|
</div>
|
|
182
|
-
{hasPagination ?
|
|
183
|
-
<
|
|
184
|
-
|
|
188
|
+
{hasPagination ? (
|
|
189
|
+
<div>
|
|
190
|
+
<Pagination
|
|
191
|
+
current={pageData.current?.pageNum}
|
|
192
|
+
total={total}
|
|
193
|
+
pageSize={pageData.current?.pageSize}
|
|
194
|
+
onChange={handleChangePage}
|
|
195
|
+
size="small"
|
|
196
|
+
/>
|
|
197
|
+
</div>
|
|
198
|
+
) : null}
|
|
185
199
|
</div>
|
|
186
200
|
<div className="group-selection-detail">
|
|
187
201
|
<div className="group-selection-detail-list">
|