@hzab/group-user-selector 0.0.2 → 0.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/group-user-selector",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
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
 
@@ -7,7 +7,7 @@ function SearchRenter(props, ref) {
7
7
  const {
8
8
  searchModel,
9
9
  searchQueryKey = "search",
10
- hasPagination = true,
10
+ hasSearchPagination = true,
11
11
  hasSearch = true,
12
12
  ItemRenter,
13
13
  setLoading = () => { },
@@ -16,7 +16,7 @@ function SearchRenter(props, ref) {
16
16
  const [search, setSearch] = useState("");
17
17
  const [searchList, setSearchList] = useState([]);
18
18
  const [total, setTotal] = useState(0);
19
- const [pageData, setPageData] = useState(hasPagination ? {
19
+ const [pageData, setPageData] = useState(hasSearchPagination ? {
20
20
  pageSize: 10,
21
21
  pageNum: 1
22
22
  } : {});
@@ -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);
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
 
@@ -75,12 +83,12 @@ function SearchRenter(props, ref) {
75
83
  })}
76
84
  </div>
77
85
 
78
- {hasPagination ? <div className="group-selection-search-pagination">
86
+ {hasSearchPagination ? <div className="group-selection-search-pagination">
79
87
  <Pagination current={pageData?.pageNum} total={total} pageSize={pageData?.pageSize} onChange={handleChangePage} size="small" />
80
88
  </div> : null}
81
89
  </div>
82
90
  ) : null}
83
- </>
91
+ </>
84
92
  );
85
93
  }
86
94
 
package/src/index.tsx CHANGED
@@ -1,4 +1,4 @@
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
3
  import zhCN from 'antd/es/locale/zh_CN';
4
4
  import { CloseCircleFilled, SearchOutlined } from "@ant-design/icons";
@@ -21,6 +21,7 @@ function GroupSelection(props, ref) {
21
21
  valueKey = "value",
22
22
  isUserKey = "isUser",
23
23
  imgKey = "img",
24
+ hasPagination = true,
24
25
  } = props;
25
26
  const [breadcrumb, setBreadcrumb] = useState([
26
27
  {
@@ -32,6 +33,14 @@ function GroupSelection(props, ref) {
32
33
  const [checkAll, setCheckAll] = useState(false);
33
34
  const [selectList, setSelectList] = useState([]);
34
35
  const [selectedList, setSelectedList] = useState([...value]);
36
+ const [queryValue, setQueryValue] = useState(undefined);
37
+ const [total, setTotal] = useState(0);
38
+
39
+
40
+ const pageData = useRef(hasPagination ? {
41
+ pageSize: 10,
42
+ pageNum: 1
43
+ } : {});
35
44
 
36
45
  // 通过useImperativeHandle定义要抛出的值或方法
37
46
  useImperativeHandle(ref, () => ({
@@ -47,8 +56,9 @@ function GroupSelection(props, ref) {
47
56
  const getTreeData = (value?: string | number) => {
48
57
  setLoading(true);
49
58
  model &&
50
- model.getList({ [queryKey]: value }).then((res) => {
59
+ model.getList({ [queryKey]: value || queryValue, ...pageData.current }).then((res) => {
51
60
  setSelectList(res?.list || res || []);
61
+ setTotal(res?.pagination?.total||res?.total || 0);
52
62
  })
53
63
  .catch((err) => {
54
64
  message.error(err._message || "未知错误");
@@ -64,6 +74,15 @@ function GroupSelection(props, ref) {
64
74
  }, []);
65
75
 
66
76
 
77
+ const handleChangePage = (pageNum, pageSize) => {
78
+ const pages = {
79
+ pageNum: pageSize !== pageData.current?.pageSize ? 1 : pageNum,
80
+ pageSize
81
+ }
82
+ pageData.current = pages
83
+
84
+ getTreeData()
85
+ }
67
86
 
68
87
 
69
88
 
@@ -72,6 +91,7 @@ function GroupSelection(props, ref) {
72
91
  const arr = [...breadcrumb];
73
92
  arr.splice(index + 1);
74
93
  setBreadcrumb(arr);
94
+ setQueryValue(e[valueKey]);
75
95
  getTreeData(e[valueKey]);
76
96
  };
77
97
 
@@ -79,7 +99,7 @@ function GroupSelection(props, ref) {
79
99
  const arr = [...breadcrumb];
80
100
  arr.push(item);
81
101
  setBreadcrumb(arr);
82
-
102
+ setQueryValue(item[valueKey]);
83
103
  getTreeData(item[valueKey]);
84
104
  };
85
105
 
@@ -159,6 +179,9 @@ function GroupSelection(props, ref) {
159
179
  return Renter(item);
160
180
  })}
161
181
  </div>
182
+ {hasPagination ? <div>
183
+ <Pagination current={pageData.current?.pageNum} total={total} pageSize={pageData.current?.pageSize} onChange={handleChangePage} size="small" />
184
+ </div> : null}
162
185
  </div>
163
186
  <div className="group-selection-detail">
164
187
  <div className="group-selection-detail-list">