@hzab/group-user-selector 0.0.3 → 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 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
- | schema | Object | | - | 数据信息的 schema |
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/group-user-selector",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "main": "src",
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useState, forwardRef } from "react";
2
- import { Input,message, Pagination, } from "antd";
2
+ import { Input, message, Pagination, } from "antd";
3
3
 
4
4
  import "./index.less";
5
5
 
@@ -27,15 +27,13 @@ function SearchRenter(props, ref) {
27
27
  setLoading && setLoading(true);
28
28
  searchModel &&
29
29
  searchModel.getList({ ...data }).then((res) => {
30
- console.log(res, 2222222);
31
-
32
30
  setSearchList(res?.list || res || []);
33
- setTotal(res?.pagination?.total||res?.total || 0);
31
+ setTotal(res?.pagination?.total || res?.total || 0);
34
32
  }).catch((err) => {
35
33
  message.error(err._message || "未知错误");
36
34
  })
37
35
  .finally(() => {
38
- setLoading && setLoading(false);
36
+ setLoading && setLoading(false);
39
37
  });
40
38
  }
41
39
 
@@ -54,12 +52,22 @@ function SearchRenter(props, ref) {
54
52
  }
55
53
 
56
54
  const onSearch = (value) => {
57
-
58
55
  setSearch(value);
59
- if (!value) return;
56
+ if (!value) {
57
+ setPageData({
58
+ pageSize: 10,
59
+ pageNum: 1
60
+ })
61
+ return
62
+ };
63
+ const data = {
64
+ pageSize: pageData?.pageSize || 10,
65
+ pageNum: 1
66
+ }
67
+ setPageData(data)
60
68
  handleSearch({
61
69
  [searchQueryKey]: value,
62
- ...pageData
70
+ ...data
63
71
  })
64
72
  };
65
73
 
@@ -80,7 +88,7 @@ function SearchRenter(props, ref) {
80
88
  </div> : null}
81
89
  </div>
82
90
  ) : null}
83
- </>
91
+ </>
84
92
  );
85
93
  }
86
94
 
package/src/index.tsx CHANGED
@@ -1,14 +1,14 @@
1
- import { useEffect, useState, useImperativeHandle, forwardRef } from "react";
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 'antd/es/locale/zh_CN';
3
+ import zhCN from "antd/es/locale/zh_CN";
4
4
  import { CloseCircleFilled, SearchOutlined } from "@ant-design/icons";
5
- import 'moment/locale/zh-cn';
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 './components/SearchRenter'
11
- import ItemRenter from './components/ItemRenter'
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
  {
@@ -35,10 +36,15 @@ function GroupSelection(props, ref) {
35
36
  const [selectedList, setSelectedList] = useState([...value]);
36
37
  const [queryValue, setQueryValue] = useState(undefined);
37
38
  const [total, setTotal] = useState(0);
38
- const [pageData, setPageData] = useState(hasPagination ? {
39
- pageSize: 10,
40
- pageNum: 1
41
- } : {});
39
+
40
+ const pageData = useRef(
41
+ hasPagination
42
+ ? {
43
+ pageSize: 10,
44
+ pageNum: 1,
45
+ }
46
+ : {},
47
+ );
42
48
 
43
49
  // 通过useImperativeHandle定义要抛出的值或方法
44
50
  useImperativeHandle(ref, () => ({
@@ -54,36 +60,32 @@ function GroupSelection(props, ref) {
54
60
  const getTreeData = (value?: string | number) => {
55
61
  setLoading(true);
56
62
  model &&
57
- model.getList({ [queryKey]: value || queryValue, ...pageData }).then((res) => {
58
- setSelectList(res?.list || res || []);
59
- setTotal(res?.pagination?.total||res?.total || 0);
60
- })
63
+ model[modelGetType]({ [queryKey]: value, ...pageData.current })
64
+ .then((res) => {
65
+ setSelectList(res?.list || res || []);
66
+ setTotal(res?.pagination?.total || res?.total || 0);
67
+ })
61
68
  .catch((err) => {
62
- message.error(err._message || "未知错误");
69
+ message.error(err._message || "未知错误");
63
70
  })
64
71
  .finally(() => {
65
- setLoading(false);
72
+ setLoading(false);
66
73
  });
67
74
  };
68
75
 
69
-
70
76
  useEffect(() => {
71
77
  getTreeData();
72
78
  }, []);
73
79
 
74
-
75
80
  const handleChangePage = (pageNum, pageSize) => {
76
81
  const pages = {
77
- pageNum: pageSize !== pageData?.pageSize ? 1 : pageNum,
78
- pageSize
79
- }
80
- setPageData({
81
- ...pages
82
- })
83
- getTreeData()
84
- }
85
-
82
+ pageNum: pageSize !== pageData.current?.pageSize ? 1 : pageNum,
83
+ pageSize,
84
+ };
85
+ pageData.current = pages;
86
86
 
87
+ getTreeData();
88
+ };
87
89
 
88
90
  const handleBreadcrumb = (e) => {
89
91
  const index = breadcrumb.findIndex((item) => item[valueKey] === e[valueKey]);
@@ -154,17 +156,22 @@ function GroupSelection(props, ref) {
154
156
 
155
157
  return (
156
158
  <ConfigProvider locale={zhCN}>
157
-
158
159
  <div className="group-selection">
159
- {loading ? <div className="group-selection-loading">
160
- <Spin tip="Loading..." spinning={loading} />
161
- </div> : null}
160
+ {loading ? (
161
+ <div className="group-selection-loading">
162
+ <Spin tip="Loading..." spinning={loading} />
163
+ </div>
164
+ ) : null}
162
165
  <div className="group-selection-list">
163
166
  <SearchRenter {...props} setLoading={setLoading} ItemRenter={Renter} />
164
167
  <Breadcrumb className="group-selection-breadcrumb">
165
168
  {breadcrumb.map((item) => {
166
169
  return (
167
- <Breadcrumb.Item className="group-selection-breadcrumb-item" onClick={() => handleBreadcrumb(item)} key={item[valueKey]}>
170
+ <Breadcrumb.Item
171
+ className="group-selection-breadcrumb-item"
172
+ onClick={() => handleBreadcrumb(item)}
173
+ key={item[valueKey]}
174
+ >
168
175
  {item[labelKey]}
169
176
  </Breadcrumb.Item>
170
177
  );
@@ -178,9 +185,17 @@ function GroupSelection(props, ref) {
178
185
  return Renter(item);
179
186
  })}
180
187
  </div>
181
- {hasPagination ? <div>
182
- <Pagination current={pageData?.pageNum} total={total} pageSize={pageData?.pageSize} onChange={handleChangePage} size="small" />
183
- </div> : null}
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}
184
199
  </div>
185
200
  <div className="group-selection-detail">
186
201
  <div className="group-selection-detail-list">