ztxkui 1.8.1 → 1.8.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/dist/Demo.js
CHANGED
|
@@ -57,7 +57,9 @@ function Demo() {
|
|
|
57
57
|
React.createElement(Link, { to: "/test" }, "test"),
|
|
58
58
|
React.createElement("h1", null, "\u4F5C\u4E3A\u6F14\u793A\u4F7F\u7528"),
|
|
59
59
|
React.createElement("h2", null, "\u5982\u679C\u6570\u636E\u662F\u901A\u8FC7\u5916\u90E8\u83B7\u53D6\u7684\uFF0C\u53EF\u4EE5\u901A\u8FC7\u4F20\u9012list\u5C5E\u6027"),
|
|
60
|
-
React.createElement(EnhanceSelect, { style: selectStyle, list: list, showAll: true, joinKey: "test1"
|
|
60
|
+
React.createElement(EnhanceSelect, { style: selectStyle, list: list, showAll: true, joinKey: "test1", onChange: function (value, option, fullData) {
|
|
61
|
+
console.log(value, option, fullData);
|
|
62
|
+
} }),
|
|
61
63
|
React.createElement("h2", null, "\u5F02\u6B65\u83B7\u53D6\u6570\u636E"),
|
|
62
64
|
React.createElement(EnhanceSelect, { style: selectStyle, url: "http://192.168.0.83:8000/api/zmdms-user/list", params: JSON.stringify({
|
|
63
65
|
status: 50,
|
|
@@ -24,7 +24,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
24
24
|
* @author cyx
|
|
25
25
|
* @description 增强下拉框功能
|
|
26
26
|
*/
|
|
27
|
-
import React, { useCallback, useEffect, memo } from 'react';
|
|
27
|
+
import React, { useCallback, useEffect, memo, useRef } from 'react';
|
|
28
28
|
import { Select } from 'antd';
|
|
29
29
|
import { useFetchState } from 'ztxkutils/dist/hooks';
|
|
30
30
|
import debounce from 'lodash/debounce';
|
|
@@ -74,17 +74,28 @@ function EnhanceSelect(_a) {
|
|
|
74
74
|
var list = _a.list, defaultList = _a.defaultList, params = _a.params, url = _a.url, _b = _a.method, method = _b === void 0 ? 'GET' : _b, _c = _a.dataKey, dataKey = _c === void 0 ? 'id' : _c, componentKey = _a.componentKey, _d = _a.titleKey, titleKey = _d === void 0 ? 'name' : _d, showAll = _a.showAll, isCatch = _a.isCatch, onCompleted = _a.onCompleted, onChange = _a.onChange, request = _a.request, remoteSearch = _a.remoteSearch, remoteSearchKey = _a.remoteSearchKey, transformData = _a.transformData, joinKey = _a.joinKey, _e = _a.joinStr, joinStr = _e === void 0 ? '-' : _e, restProps = __rest(_a, ["list", "defaultList", "params", "url", "method", "dataKey", "componentKey", "titleKey", "showAll", "isCatch", "onCompleted", "onChange", "request", "remoteSearch", "remoteSearchKey", "transformData", "joinKey", "joinStr"]);
|
|
75
75
|
// 下拉数据源
|
|
76
76
|
var _f = useFetchState([]), selectList = _f[0], setSelectList = _f[1];
|
|
77
|
+
var _g = useFetchState(false), loading = _g[0], setLoading = _g[1];
|
|
78
|
+
var fetchId = useRef(0); // 请求Id,每次请求都会加1
|
|
77
79
|
// 如果selectList 发生改变,那么触发onCompleted事件
|
|
78
80
|
useEffect(function () {
|
|
79
81
|
if (Array.isArray(selectList) && onCompleted) {
|
|
80
82
|
onCompleted(selectList);
|
|
81
83
|
}
|
|
82
|
-
|
|
84
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
85
|
+
}, [selectList]);
|
|
83
86
|
// 获取数据,并设置数据
|
|
84
87
|
var getDataHandle = useCallback(function (request, options, appointObj) {
|
|
88
|
+
setLoading(true);
|
|
89
|
+
// 利用闭包,存到当前请求的id
|
|
90
|
+
fetchId.current++;
|
|
91
|
+
var fetchIdClosure = fetchId.current;
|
|
85
92
|
getData(request, options)
|
|
86
93
|
.then(function (resData) {
|
|
87
94
|
var _a;
|
|
95
|
+
if (fetchIdClosure < fetchId.current) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
setLoading(false);
|
|
88
99
|
var res = transformData ? transformData(resData) : resData;
|
|
89
100
|
var result;
|
|
90
101
|
if (Array.isArray(res.data)) {
|
|
@@ -100,9 +111,10 @@ function EnhanceSelect(_a) {
|
|
|
100
111
|
}
|
|
101
112
|
})
|
|
102
113
|
.catch(function (err) {
|
|
114
|
+
setLoading(false);
|
|
103
115
|
console.log(err);
|
|
104
116
|
});
|
|
105
|
-
}, [setSelectList, transformData]);
|
|
117
|
+
}, [setSelectList, setLoading, transformData]);
|
|
106
118
|
// 远程搜索
|
|
107
119
|
var getRemoteDataHandle = useCallback(function (value) {
|
|
108
120
|
var _a;
|
|
@@ -112,6 +124,10 @@ function EnhanceSelect(_a) {
|
|
|
112
124
|
outParams = JSON.parse(params);
|
|
113
125
|
}
|
|
114
126
|
catch (err) { }
|
|
127
|
+
setLoading(true);
|
|
128
|
+
// 利用闭包,存到当前请求的id
|
|
129
|
+
fetchId.current++;
|
|
130
|
+
var fetchIdClosure = fetchId.current;
|
|
115
131
|
getData(request, {
|
|
116
132
|
url: url,
|
|
117
133
|
method: method,
|
|
@@ -119,6 +135,10 @@ function EnhanceSelect(_a) {
|
|
|
119
135
|
})
|
|
120
136
|
.then(function (resData) {
|
|
121
137
|
var _a, _b, _c;
|
|
138
|
+
if (fetchIdClosure < fetchId.current) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
setLoading(false);
|
|
122
142
|
var res = transformData ? transformData(resData) : resData;
|
|
123
143
|
var result;
|
|
124
144
|
if (Array.isArray(res.data)) {
|
|
@@ -135,6 +155,7 @@ function EnhanceSelect(_a) {
|
|
|
135
155
|
setSelectList(result);
|
|
136
156
|
})
|
|
137
157
|
.catch(function (err) {
|
|
158
|
+
setLoading(false);
|
|
138
159
|
console.log(err);
|
|
139
160
|
});
|
|
140
161
|
}, [
|
|
@@ -146,6 +167,7 @@ function EnhanceSelect(_a) {
|
|
|
146
167
|
titleKey,
|
|
147
168
|
setSelectList,
|
|
148
169
|
transformData,
|
|
170
|
+
setLoading,
|
|
149
171
|
]);
|
|
150
172
|
var searchHandle = function (value) {
|
|
151
173
|
// 当value有值时才进行搜索
|
|
@@ -214,7 +236,7 @@ function EnhanceSelect(_a) {
|
|
|
214
236
|
function renderSelectOption() {
|
|
215
237
|
var _defaultList = Array.isArray(defaultList) ? defaultList : [];
|
|
216
238
|
return (React.createElement(React.Fragment, null,
|
|
217
|
-
showAll && (React.createElement(Select.Option, {
|
|
239
|
+
showAll && (React.createElement(Select.Option, { title: "\u5168\u90E8", value: "" }, "\u5168\u90E8")),
|
|
218
240
|
Array.isArray(selectList) &&
|
|
219
241
|
selectList.concat(_defaultList).map(function (item) {
|
|
220
242
|
var key = componentKey ? item[componentKey] : item[dataKey];
|
|
@@ -262,6 +284,6 @@ function EnhanceSelect(_a) {
|
|
|
262
284
|
onChange && onChange(value, option);
|
|
263
285
|
}
|
|
264
286
|
};
|
|
265
|
-
return (React.createElement(Select, __assign({ defaultValue: showAll ? '' : undefined, allowClear: true, showSearch: true, filterOption: remoteSearch ? false : filterOptionHandle, onSearch: remoteSearch ? onSearchHandle : undefined, onChange: onChangeHandle, optionLabelProp: "title" }, restProps), renderSelectOption()));
|
|
287
|
+
return (React.createElement(Select, __assign({ defaultValue: showAll ? '' : undefined, allowClear: true, showSearch: true, filterOption: remoteSearch ? false : filterOptionHandle, onSearch: remoteSearch ? onSearchHandle : undefined, onChange: onChangeHandle, optionLabelProp: "title", loading: loading }, restProps), renderSelectOption()));
|
|
266
288
|
}
|
|
267
289
|
export default memo(EnhanceSelect);
|
|
@@ -20,7 +20,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
}
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
|
-
import React, { useEffect, useCallback } from 'react';
|
|
23
|
+
import React, { useEffect, useCallback, useRef } from 'react';
|
|
24
24
|
import { TreeSelect } from 'antd';
|
|
25
25
|
import { useFetchState } from 'ztxkutils/dist/hooks';
|
|
26
26
|
// 获取接口数据
|
|
@@ -53,6 +53,7 @@ function EnhanceTreeSelect(_a) {
|
|
|
53
53
|
* 保证数据源唯一
|
|
54
54
|
*/
|
|
55
55
|
var _d = useFetchState([]), treeData = _d[0], setTreeData = _d[1];
|
|
56
|
+
var fetchId = useRef(0); // 请求Id,每次请求都会加1
|
|
56
57
|
// 如果selectList 发生改变,那么触发onCompleted事件
|
|
57
58
|
useEffect(function () {
|
|
58
59
|
if (Array.isArray(treeData) && onCompleted) {
|
|
@@ -61,9 +62,15 @@ function EnhanceTreeSelect(_a) {
|
|
|
61
62
|
}, [treeData, onCompleted]);
|
|
62
63
|
// 获取数据,并设置数据
|
|
63
64
|
var getDataHandle = useCallback(function (request, options, isConcat) {
|
|
65
|
+
// 利用闭包,存到当前请求的id
|
|
66
|
+
fetchId.current++;
|
|
67
|
+
var fetchIdClosure = fetchId.current;
|
|
64
68
|
return getData(request, options)
|
|
65
69
|
.then(function (resData) {
|
|
66
70
|
var _a;
|
|
71
|
+
if (fetchIdClosure < fetchId.current) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
67
74
|
var res = transformData ? transformData(resData) : resData;
|
|
68
75
|
var result;
|
|
69
76
|
if (Array.isArray(res.data)) {
|