ztxkui 1.8.0 → 1.8.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/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,6 +74,8 @@ 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) {
|
|
@@ -82,9 +84,17 @@ function EnhanceSelect(_a) {
|
|
|
82
84
|
}, [selectList, onCompleted]);
|
|
83
85
|
// 获取数据,并设置数据
|
|
84
86
|
var getDataHandle = useCallback(function (request, options, appointObj) {
|
|
87
|
+
setLoading(true);
|
|
88
|
+
// 利用闭包,存到当前请求的id
|
|
89
|
+
fetchId.current++;
|
|
90
|
+
var fetchIdClosure = fetchId.current;
|
|
85
91
|
getData(request, options)
|
|
86
92
|
.then(function (resData) {
|
|
87
93
|
var _a;
|
|
94
|
+
if (fetchIdClosure < fetchId.current) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
setLoading(false);
|
|
88
98
|
var res = transformData ? transformData(resData) : resData;
|
|
89
99
|
var result;
|
|
90
100
|
if (Array.isArray(res.data)) {
|
|
@@ -100,9 +110,10 @@ function EnhanceSelect(_a) {
|
|
|
100
110
|
}
|
|
101
111
|
})
|
|
102
112
|
.catch(function (err) {
|
|
113
|
+
setLoading(false);
|
|
103
114
|
console.log(err);
|
|
104
115
|
});
|
|
105
|
-
}, [setSelectList, transformData]);
|
|
116
|
+
}, [setSelectList, setLoading, transformData]);
|
|
106
117
|
// 远程搜索
|
|
107
118
|
var getRemoteDataHandle = useCallback(function (value) {
|
|
108
119
|
var _a;
|
|
@@ -112,6 +123,10 @@ function EnhanceSelect(_a) {
|
|
|
112
123
|
outParams = JSON.parse(params);
|
|
113
124
|
}
|
|
114
125
|
catch (err) { }
|
|
126
|
+
setLoading(true);
|
|
127
|
+
// 利用闭包,存到当前请求的id
|
|
128
|
+
fetchId.current++;
|
|
129
|
+
var fetchIdClosure = fetchId.current;
|
|
115
130
|
getData(request, {
|
|
116
131
|
url: url,
|
|
117
132
|
method: method,
|
|
@@ -119,6 +134,10 @@ function EnhanceSelect(_a) {
|
|
|
119
134
|
})
|
|
120
135
|
.then(function (resData) {
|
|
121
136
|
var _a, _b, _c;
|
|
137
|
+
if (fetchIdClosure < fetchId.current) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
setLoading(false);
|
|
122
141
|
var res = transformData ? transformData(resData) : resData;
|
|
123
142
|
var result;
|
|
124
143
|
if (Array.isArray(res.data)) {
|
|
@@ -135,6 +154,7 @@ function EnhanceSelect(_a) {
|
|
|
135
154
|
setSelectList(result);
|
|
136
155
|
})
|
|
137
156
|
.catch(function (err) {
|
|
157
|
+
setLoading(false);
|
|
138
158
|
console.log(err);
|
|
139
159
|
});
|
|
140
160
|
}, [
|
|
@@ -146,6 +166,7 @@ function EnhanceSelect(_a) {
|
|
|
146
166
|
titleKey,
|
|
147
167
|
setSelectList,
|
|
148
168
|
transformData,
|
|
169
|
+
setLoading,
|
|
149
170
|
]);
|
|
150
171
|
var searchHandle = function (value) {
|
|
151
172
|
// 当value有值时才进行搜索
|
|
@@ -214,7 +235,7 @@ function EnhanceSelect(_a) {
|
|
|
214
235
|
function renderSelectOption() {
|
|
215
236
|
var _defaultList = Array.isArray(defaultList) ? defaultList : [];
|
|
216
237
|
return (React.createElement(React.Fragment, null,
|
|
217
|
-
showAll && React.createElement(Select.Option, { value: "" }, "\u5168\u90E8"),
|
|
238
|
+
showAll && (React.createElement(Select.Option, { title: "\u5168\u90E8", value: "" }, "\u5168\u90E8")),
|
|
218
239
|
Array.isArray(selectList) &&
|
|
219
240
|
selectList.concat(_defaultList).map(function (item) {
|
|
220
241
|
var key = componentKey ? item[componentKey] : item[dataKey];
|
|
@@ -262,6 +283,6 @@ function EnhanceSelect(_a) {
|
|
|
262
283
|
onChange && onChange(value, option);
|
|
263
284
|
}
|
|
264
285
|
};
|
|
265
|
-
return (React.createElement(Select, __assign({ allowClear: true, showSearch: true, filterOption: remoteSearch ? false : filterOptionHandle, onSearch: remoteSearch ? onSearchHandle : undefined, onChange: onChangeHandle, optionLabelProp: "title" }, restProps), renderSelectOption()));
|
|
286
|
+
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
287
|
}
|
|
267
288
|
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)) {
|