@hzab/group-user-selector 0.0.6 → 0.0.8
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 +8 -0
- package/README.md +1 -0
- package/package.json +1 -1
- package/src/components/SearchRenter/index.jsx +49 -36
- package/src/index.tsx +3 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -35,6 +35,7 @@ import Demo from "@hzab/group-user-selector";
|
|
|
35
35
|
| hasPagination | boolean | 否 | true | 列表是否分页 |
|
|
36
36
|
| hasSearch | boolean | 否 | true | 是否有搜索 |
|
|
37
37
|
| hasSearchPagination | boolean | 否 | true | 搜索列表是否分页 |
|
|
38
|
+
| searchPlaceholder | string | 否 | "搜索成员"| 搜索框的提示词 |
|
|
38
39
|
|
|
39
40
|
# 组件开发流程
|
|
40
41
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState, forwardRef } from "react";
|
|
2
|
-
import { Input, message, Pagination
|
|
2
|
+
import { Input, message, Pagination } from "antd";
|
|
3
3
|
|
|
4
4
|
import "./index.less";
|
|
5
5
|
|
|
@@ -7,74 +7,79 @@ function SearchRenter(props, ref) {
|
|
|
7
7
|
const {
|
|
8
8
|
searchModel,
|
|
9
9
|
searchQueryKey = "search",
|
|
10
|
+
searchPlaceholder = "搜索成员",
|
|
10
11
|
hasSearchPagination = true,
|
|
11
12
|
hasSearch = true,
|
|
12
13
|
ItemRenter,
|
|
13
|
-
setLoading = () => {
|
|
14
|
+
setLoading = () => {},
|
|
14
15
|
} = props;
|
|
15
16
|
|
|
16
17
|
const [search, setSearch] = useState("");
|
|
17
18
|
const [searchList, setSearchList] = useState([]);
|
|
18
19
|
const [total, setTotal] = useState(0);
|
|
19
|
-
const [pageData, setPageData] = useState(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const [pageData, setPageData] = useState(
|
|
21
|
+
hasSearchPagination
|
|
22
|
+
? {
|
|
23
|
+
pageSize: 10,
|
|
24
|
+
pageNum: 1,
|
|
25
|
+
}
|
|
26
|
+
: {},
|
|
27
|
+
);
|
|
25
28
|
|
|
26
29
|
const handleSearch = (data) => {
|
|
27
30
|
setLoading && setLoading(true);
|
|
28
31
|
searchModel &&
|
|
29
|
-
searchModel
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
searchModel
|
|
33
|
+
.getList({ ...data })
|
|
34
|
+
.then((res) => {
|
|
35
|
+
setSearchList(res?.list || res || []);
|
|
36
|
+
setTotal(res?.pagination?.total || res?.total || 0);
|
|
37
|
+
})
|
|
38
|
+
.catch((err) => {
|
|
39
|
+
message.error(err._message || "未知错误");
|
|
40
|
+
})
|
|
35
41
|
.finally(() => {
|
|
36
42
|
setLoading && setLoading(false);
|
|
37
43
|
});
|
|
38
|
-
}
|
|
44
|
+
};
|
|
39
45
|
|
|
40
46
|
const handleChangePage = (pageNum, pageSize) => {
|
|
41
47
|
const pages = {
|
|
42
48
|
pageNum: pageSize !== pageData?.pageSize ? 1 : pageNum,
|
|
43
|
-
pageSize
|
|
44
|
-
}
|
|
49
|
+
pageSize,
|
|
50
|
+
};
|
|
45
51
|
setPageData({
|
|
46
|
-
...pages
|
|
47
|
-
})
|
|
52
|
+
...pages,
|
|
53
|
+
});
|
|
48
54
|
handleSearch({
|
|
49
55
|
[searchQueryKey]: search,
|
|
50
|
-
...pages
|
|
51
|
-
})
|
|
52
|
-
}
|
|
56
|
+
...pages,
|
|
57
|
+
});
|
|
58
|
+
};
|
|
53
59
|
|
|
54
60
|
const onSearch = (value) => {
|
|
55
61
|
setSearch(value);
|
|
56
62
|
if (!value) {
|
|
57
63
|
setPageData({
|
|
58
64
|
pageSize: 10,
|
|
59
|
-
pageNum: 1
|
|
60
|
-
})
|
|
61
|
-
return
|
|
62
|
-
}
|
|
65
|
+
pageNum: 1,
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
63
69
|
const data = {
|
|
64
70
|
pageSize: pageData?.pageSize || 10,
|
|
65
|
-
pageNum: 1
|
|
66
|
-
}
|
|
67
|
-
setPageData(data)
|
|
71
|
+
pageNum: 1,
|
|
72
|
+
};
|
|
73
|
+
setPageData(data);
|
|
68
74
|
handleSearch({
|
|
69
75
|
[searchQueryKey]: value,
|
|
70
|
-
...data
|
|
71
|
-
})
|
|
76
|
+
...data,
|
|
77
|
+
});
|
|
72
78
|
};
|
|
73
79
|
|
|
74
|
-
|
|
75
80
|
return (
|
|
76
81
|
<>
|
|
77
|
-
{hasSearch ? <Input.Search onSearch={onSearch} enterButton placeholder=
|
|
82
|
+
{hasSearch ? <Input.Search onSearch={onSearch} enterButton placeholder={searchPlaceholder} allowClear /> : null}
|
|
78
83
|
{search ? (
|
|
79
84
|
<div className="group-selection-search-view">
|
|
80
85
|
<div className="group-selection-search-list">
|
|
@@ -83,9 +88,17 @@ function SearchRenter(props, ref) {
|
|
|
83
88
|
})}
|
|
84
89
|
</div>
|
|
85
90
|
|
|
86
|
-
{hasSearchPagination ?
|
|
87
|
-
<
|
|
88
|
-
|
|
91
|
+
{hasSearchPagination ? (
|
|
92
|
+
<div className="group-selection-search-pagination">
|
|
93
|
+
<Pagination
|
|
94
|
+
current={pageData?.pageNum}
|
|
95
|
+
total={total}
|
|
96
|
+
pageSize={pageData?.pageSize}
|
|
97
|
+
onChange={handleChangePage}
|
|
98
|
+
size="small"
|
|
99
|
+
/>
|
|
100
|
+
</div>
|
|
101
|
+
) : null}
|
|
89
102
|
</div>
|
|
90
103
|
) : null}
|
|
91
104
|
</>
|
package/src/index.tsx
CHANGED