@hzab/group-user-selector 0.0.9 → 0.0.10

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,3 +1,7 @@
1
+ # @hzab/group-user-selector@0.0.10
2
+
3
+ feat: 搜索情况下默认不展示下级
4
+
1
5
  # @hzab/group-user-selector@0.0.9
2
6
 
3
7
  feat: 增加一键清除 API
package/package.json CHANGED
@@ -1,52 +1,57 @@
1
- {
2
- "name": "@hzab/group-user-selector",
3
- "version": "0.0.9",
4
- "description": "",
5
- "main": "src",
6
- "scripts": {
7
- "dev": "webpack serve -c ./config/webpack.config.js --env local",
8
- "build": "webpack -c ./config/webpack.config.js --env production",
9
- "publish-patch": "npm version patch && npm publish --access public",
10
- "publish-minor": "npm version minor && npm publish --access public",
11
- "publish-major": "npm version major && npm publish --access public",
12
- "prepare": "husky install",
13
- "mac-chmod": "chmod +x .husky && chmod +x .husky/pre-commit",
14
- "docs": "typedoc"
15
- },
16
- "files": [
17
- "src",
18
- "CHANGELOG.md"
19
- ],
20
- "keywords": [],
21
- "author": "CaiYansong",
22
- "license": "ISC",
23
- "devDependencies": {
24
- "@hzab/permissions": "^1.0.0",
25
- "@hzab/webpack-config": "^1.0.0",
26
- "@types/react": "^17.0.62",
27
- "@types/react-dom": "^17.0.20",
28
- "antd": "^4.14.0",
29
- "axios": "^1.4.0",
30
- "eslint": "^8.30.0",
31
- "less": "^4.1.3",
32
- "mobx": "^6.7.0",
33
- "mobx-react": "^7.6.0",
34
- "react": "^17.0.2",
35
- "react-dom": "^17.0.2",
36
- "react-router-dom": "^6.14.1",
37
- "typedoc": "^0.24.8",
38
- "typescript": "^4.9.4"
39
- },
40
- "directories": {
41
- "src": "src"
42
- },
43
- "lint-staged": {
44
- "**.{js,jsx,ts,tsx,css,scss,less,json,html}": [
45
- "prettier --write"
46
- ]
47
- },
48
- "dependencies": {
49
- "@hzab/data-model": "^1.7.0",
50
- "lodash": "^4.17.21"
51
- }
52
- }
1
+ {
2
+ "name": "@hzab/group-user-selector",
3
+ "version": "0.0.10",
4
+ "description": "",
5
+ "main": "src",
6
+ "scripts": {
7
+ "dev": "webpack serve -c ./config/webpack.config.js --env local",
8
+ "build": "webpack -c ./config/webpack.config.js --env production",
9
+ "version:alpha": "npm version prerelease --preid=alpha",
10
+ "publish:alpha": "npm publish --tag alpha",
11
+ "version:beta": "npm version prerelease --preid=beta",
12
+ "publish:beta": "npm publish --tag beta",
13
+ "version:patch": "npm version patch",
14
+ "version:minior": "npm version minor",
15
+ "version:major": "npm version major",
16
+ "publish:stable": "npm publish --access public",
17
+ "prepare": "husky install",
18
+ "mac-chmod": "chmod +x .husky && chmod +x .husky/pre-commit",
19
+ "docs": "typedoc"
20
+ },
21
+ "files": [
22
+ "src",
23
+ "CHANGELOG.md"
24
+ ],
25
+ "keywords": [],
26
+ "author": "CaiYansong",
27
+ "license": "ISC",
28
+ "devDependencies": {
29
+ "@hzab/permissions": "^1.0.0",
30
+ "@hzab/webpack-config": "^1.0.0",
31
+ "@types/react": "^17.0.62",
32
+ "@types/react-dom": "^17.0.20",
33
+ "antd": "^4.14.0",
34
+ "axios": "^1.4.0",
35
+ "eslint": "^8.30.0",
36
+ "less": "^4.1.3",
37
+ "mobx": "^6.7.0",
38
+ "mobx-react": "^7.6.0",
39
+ "react": "^17.0.2",
40
+ "react-dom": "^17.0.2",
41
+ "react-router-dom": "^6.14.1",
42
+ "typedoc": "^0.24.8",
43
+ "typescript": "^4.9.4"
44
+ },
45
+ "directories": {
46
+ "src": "src"
47
+ },
48
+ "lint-staged": {
49
+ "**.{js,jsx,ts,tsx,css,scss,less,json,html}": [
50
+ "prettier --write"
51
+ ]
52
+ },
53
+ "dependencies": {
54
+ "@hzab/data-model": "^1.7.0",
55
+ "lodash": "^4.17.21"
56
+ }
57
+ }
@@ -1,46 +1,47 @@
1
- import { forwardRef } from "react";
2
- import { Checkbox } from "antd";
3
-
4
- import defaultAvatar from "../../assets/imgs/defaultAvatar.png";
5
- import department from "../../assets/imgs/department.png";
6
-
7
- import "./index.less";
8
-
9
- function ItemRenter(props, ref) {
10
- const {
11
- labelKey = "label",
12
- valueKey = "value",
13
- isUserKey = "isUser",
14
- imgKey = "img",
15
- isCheck = false,
16
- item,
17
- handleClickItem,
18
- handleCheckItem
19
- } = props;
20
-
21
-
22
- return (
23
- <>
24
- <div className="group-selection-list-item" key={item[valueKey]}>
25
- <div className="avatar" onClick={() => handleCheckItem(item)}>
26
- <Checkbox checked={isCheck} />
27
- <img src={item[imgKey] ? item[imgKey] : item[isUserKey] ? defaultAvatar : department} />
28
- <div className="label">{item[labelKey]}</div>
29
- </div>
30
- {item[isUserKey] ? null : <div
31
- className={`next ${isCheck ? "noNext" : ""}`}
32
- onClick={() => {
33
- if (isCheck) {
34
- return;
35
- }
36
- handleClickItem(item);
37
- }}
38
- >
39
- 下级
40
- </div>}
41
- </div>
42
- </>
43
- );
44
- }
45
-
46
- export default forwardRef(ItemRenter);
1
+ import { forwardRef } from "react";
2
+ import { Checkbox } from "antd";
3
+
4
+ import defaultAvatar from "../../assets/imgs/defaultAvatar.png";
5
+ import department from "../../assets/imgs/department.png";
6
+
7
+ import "./index.less";
8
+
9
+ function ItemRenter(props, ref) {
10
+ const {
11
+ labelKey = "label",
12
+ valueKey = "value",
13
+ isUserKey = "isUser",
14
+ imgKey = "img",
15
+ isCheck = false,
16
+ item,
17
+ handleClickItem,
18
+ handleCheckItem,
19
+ noNextLevel = false
20
+ } = props;
21
+
22
+
23
+ return (
24
+ <>
25
+ <div className="group-selection-list-item" key={item[valueKey]}>
26
+ <div className="avatar" onClick={() => handleCheckItem(item)}>
27
+ <Checkbox checked={isCheck} />
28
+ <img src={item[imgKey] ? item[imgKey] : item[isUserKey] ? defaultAvatar : department} />
29
+ <div className="label">{item[labelKey]}</div>
30
+ </div>
31
+ {(item[isUserKey] || noNextLevel) ? null : <div
32
+ className={`next ${isCheck ? "noNext" : ""}`}
33
+ onClick={() => {
34
+ if (isCheck) {
35
+ return;
36
+ }
37
+ handleClickItem(item);
38
+ }}
39
+ >
40
+ 下级
41
+ </div>}
42
+ </div>
43
+ </>
44
+ );
45
+ }
46
+
47
+ export default forwardRef(ItemRenter);
@@ -1,108 +1,108 @@
1
- import { useEffect, useState, forwardRef } from "react";
2
- import { Input, message, Pagination } from "antd";
3
-
4
- import "./index.less";
5
-
6
- function SearchRenter(props, ref) {
7
- const {
8
- searchModel,
9
- searchQueryKey = "search",
10
- searchPlaceholder = "搜索成员",
11
- hasSearchPagination = true,
12
- hasSearch = true,
13
- ItemRenter,
14
- setLoading = () => {},
15
- } = props;
16
-
17
- const [search, setSearch] = useState("");
18
- const [searchList, setSearchList] = useState([]);
19
- const [total, setTotal] = useState(0);
20
- const [pageData, setPageData] = useState(
21
- hasSearchPagination
22
- ? {
23
- pageSize: 10,
24
- pageNum: 1,
25
- }
26
- : {},
27
- );
28
-
29
- const handleSearch = (data) => {
30
- setLoading && setLoading(true);
31
- searchModel &&
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
- })
41
- .finally(() => {
42
- setLoading && setLoading(false);
43
- });
44
- };
45
-
46
- const handleChangePage = (pageNum, pageSize) => {
47
- const pages = {
48
- pageNum: pageSize !== pageData?.pageSize ? 1 : pageNum,
49
- pageSize,
50
- };
51
- setPageData({
52
- ...pages,
53
- });
54
- handleSearch({
55
- [searchQueryKey]: search,
56
- ...pages,
57
- });
58
- };
59
-
60
- const onSearch = (value) => {
61
- setSearch(value);
62
- if (!value) {
63
- setPageData({
64
- pageSize: 10,
65
- pageNum: 1,
66
- });
67
- return;
68
- }
69
- const data = {
70
- pageSize: pageData?.pageSize || 10,
71
- pageNum: 1,
72
- };
73
- setPageData(data);
74
- handleSearch({
75
- [searchQueryKey]: value,
76
- ...data,
77
- });
78
- };
79
-
80
- return (
81
- <>
82
- {hasSearch ? <Input.Search onSearch={onSearch} enterButton placeholder={searchPlaceholder} allowClear /> : null}
83
- {search ? (
84
- <div className="group-selection-search-view">
85
- <div className="group-selection-search-list">
86
- {searchList.map((item, index) => {
87
- return ItemRenter(item);
88
- })}
89
- </div>
90
-
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}
102
- </div>
103
- ) : null}
104
- </>
105
- );
106
- }
107
-
108
- export default forwardRef(SearchRenter);
1
+ import { useEffect, useState, forwardRef } from "react";
2
+ import { Input, message, Pagination } from "antd";
3
+
4
+ import "./index.less";
5
+
6
+ function SearchRenter(props, ref) {
7
+ const {
8
+ searchModel,
9
+ searchQueryKey = "search",
10
+ searchPlaceholder = "搜索成员",
11
+ hasSearchPagination = true,
12
+ hasSearch = true,
13
+ ItemRenter,
14
+ setLoading = () => {},
15
+ } = props;
16
+
17
+ const [search, setSearch] = useState("");
18
+ const [searchList, setSearchList] = useState([]);
19
+ const [total, setTotal] = useState(0);
20
+ const [pageData, setPageData] = useState(
21
+ hasSearchPagination
22
+ ? {
23
+ pageSize: 10,
24
+ pageNum: 1,
25
+ }
26
+ : {},
27
+ );
28
+
29
+ const handleSearch = (data) => {
30
+ setLoading && setLoading(true);
31
+ searchModel &&
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
+ })
41
+ .finally(() => {
42
+ setLoading && setLoading(false);
43
+ });
44
+ };
45
+
46
+ const handleChangePage = (pageNum, pageSize) => {
47
+ const pages = {
48
+ pageNum: pageSize !== pageData?.pageSize ? 1 : pageNum,
49
+ pageSize,
50
+ };
51
+ setPageData({
52
+ ...pages,
53
+ });
54
+ handleSearch({
55
+ [searchQueryKey]: search,
56
+ ...pages,
57
+ });
58
+ };
59
+
60
+ const onSearch = (value) => {
61
+ setSearch(value);
62
+ if (!value) {
63
+ setPageData({
64
+ pageSize: 10,
65
+ pageNum: 1,
66
+ });
67
+ return;
68
+ }
69
+ const data = {
70
+ pageSize: pageData?.pageSize || 10,
71
+ pageNum: 1,
72
+ };
73
+ setPageData(data);
74
+ handleSearch({
75
+ [searchQueryKey]: value,
76
+ ...data,
77
+ });
78
+ };
79
+
80
+ return (
81
+ <>
82
+ {hasSearch ? <Input.Search onSearch={onSearch} enterButton placeholder={searchPlaceholder} allowClear /> : null}
83
+ {search ? (
84
+ <div className="group-selection-search-view">
85
+ <div className="group-selection-search-list">
86
+ {searchList.map((item, index) => {
87
+ return ItemRenter(item, true);
88
+ })}
89
+ </div>
90
+
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}
102
+ </div>
103
+ ) : null}
104
+ </>
105
+ );
106
+ }
107
+
108
+ export default forwardRef(SearchRenter);
package/src/index.tsx CHANGED
@@ -149,7 +149,7 @@ function GroupSelection(props, ref) {
149
149
  return is;
150
150
  };
151
151
 
152
- const Renter = (item) => {
152
+ const Renter = (item, noNextLevel) => {
153
153
  const isCheck = handleCheck(item);
154
154
  return (
155
155
  <ItemRenter
@@ -159,6 +159,7 @@ function GroupSelection(props, ref) {
159
159
  handleCheckItem={handleCheckItem}
160
160
  handleCheckDelete={handleCheckDelete}
161
161
  handleClickItem={handleClickItem}
162
+ noNextLevel={noNextLevel}
162
163
  />
163
164
  );
164
165
  };
@@ -191,7 +192,7 @@ function GroupSelection(props, ref) {
191
192
  </div>
192
193
  <div className="group-selection-list-view">
193
194
  {selectList.map((item, index) => {
194
- return Renter(item);
195
+ return Renter(item, false);
195
196
  })}
196
197
  </div>
197
198
  {hasPagination ? (