ztxkui 3.0.1 → 3.0.2
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.
|
@@ -99,8 +99,9 @@ function EnhanceSelect(_a) {
|
|
|
99
99
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
100
100
|
}, [selectList]);
|
|
101
101
|
// 获取数据,并设置数据
|
|
102
|
-
var getDataHandle = useCallback(function (request, options,
|
|
102
|
+
var getDataHandle = useCallback(function (request, options, otherObj) {
|
|
103
103
|
var _a;
|
|
104
|
+
if (otherObj === void 0) { otherObj = {}; }
|
|
104
105
|
if (mustHasParams) {
|
|
105
106
|
var _params_1 = options.params || {};
|
|
106
107
|
if (typeof options.params === 'string') {
|
|
@@ -130,7 +131,8 @@ function EnhanceSelect(_a) {
|
|
|
130
131
|
var fetchIdClosure = fetchId.current;
|
|
131
132
|
getData(request, options)
|
|
132
133
|
.then(function (resData) {
|
|
133
|
-
var _a;
|
|
134
|
+
var _a, _b;
|
|
135
|
+
(_a = otherObj === null || otherObj === void 0 ? void 0 : otherObj.successCallback) === null || _a === void 0 ? void 0 : _a.call(otherObj);
|
|
134
136
|
if (fetchIdClosure < fetchId.current) {
|
|
135
137
|
return;
|
|
136
138
|
}
|
|
@@ -141,22 +143,24 @@ function EnhanceSelect(_a) {
|
|
|
141
143
|
result = res.data;
|
|
142
144
|
}
|
|
143
145
|
else {
|
|
144
|
-
result = ((
|
|
146
|
+
result = ((_b = res.data) === null || _b === void 0 ? void 0 : _b.data) || [];
|
|
145
147
|
}
|
|
146
148
|
setSelectList(result);
|
|
147
|
-
if (appointObj) {
|
|
148
|
-
var obj =
|
|
149
|
+
if (otherObj === null || otherObj === void 0 ? void 0 : otherObj.appointObj) {
|
|
150
|
+
var _c = otherObj === null || otherObj === void 0 ? void 0 : otherObj.appointObj, obj = _c.obj, key = _c.key;
|
|
149
151
|
obj[key] = result;
|
|
150
152
|
}
|
|
151
153
|
})
|
|
152
154
|
.catch(function (err) {
|
|
155
|
+
var _a;
|
|
156
|
+
(_a = otherObj === null || otherObj === void 0 ? void 0 : otherObj.errorCallback) === null || _a === void 0 ? void 0 : _a.call(otherObj);
|
|
153
157
|
setLoading(false);
|
|
154
158
|
console.log(err);
|
|
155
159
|
});
|
|
156
160
|
}, [setSelectList, setLoading, transformData, mustHasParams]);
|
|
157
161
|
// 远程搜索
|
|
158
|
-
var getRemoteDataHandle = useCallback(function (value, dataKeyValue,
|
|
159
|
-
if (
|
|
162
|
+
var getRemoteDataHandle = useCallback(function (value, dataKeyValue, otherObj) {
|
|
163
|
+
if (otherObj === void 0) { otherObj = {}; }
|
|
160
164
|
var searchKey = remoteSearchKey ? remoteSearchKey : titleKey;
|
|
161
165
|
var searchDataKey = remoteSearchDataKey ? remoteSearchDataKey : dataKey;
|
|
162
166
|
var outParams = params;
|
|
@@ -182,9 +186,10 @@ function EnhanceSelect(_a) {
|
|
|
182
186
|
getData(request, __assign({ url: url,
|
|
183
187
|
method: method, params: __assign(__assign({ size: Array.isArray(dataKeyValue) && dataKeyValue.length > 30
|
|
184
188
|
? dataKeyValue.length
|
|
185
|
-
: 30, page: 1 }, outParams), searchParams) }, options))
|
|
189
|
+
: 30, page: 1 }, outParams), searchParams) }, ((otherObj === null || otherObj === void 0 ? void 0 : otherObj.options) || {})))
|
|
186
190
|
.then(function (resData) {
|
|
187
|
-
var _a, _b, _c, _d;
|
|
191
|
+
var _a, _b, _c, _d, _e;
|
|
192
|
+
(_a = otherObj === null || otherObj === void 0 ? void 0 : otherObj.sucessCallback) === null || _a === void 0 ? void 0 : _a.call(otherObj);
|
|
188
193
|
if (fetchIdClosure < fetchId.current) {
|
|
189
194
|
return;
|
|
190
195
|
}
|
|
@@ -195,14 +200,14 @@ function EnhanceSelect(_a) {
|
|
|
195
200
|
result = res.data;
|
|
196
201
|
}
|
|
197
202
|
else {
|
|
198
|
-
if ((
|
|
203
|
+
if ((_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.records) {
|
|
199
204
|
result = res.data.records || [];
|
|
200
205
|
}
|
|
201
|
-
else if (Array.isArray((
|
|
206
|
+
else if (Array.isArray((_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.data)) {
|
|
202
207
|
result = res.data.data || [];
|
|
203
208
|
}
|
|
204
209
|
else {
|
|
205
|
-
result = ((
|
|
210
|
+
result = ((_e = (_d = res === null || res === void 0 ? void 0 : res.data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.records) || [];
|
|
206
211
|
}
|
|
207
212
|
}
|
|
208
213
|
// 如果根据id查过了,那么需要把这些数据添加到自定义合并数组中
|
|
@@ -217,6 +222,8 @@ function EnhanceSelect(_a) {
|
|
|
217
222
|
setSelectList(result);
|
|
218
223
|
})
|
|
219
224
|
.catch(function (err) {
|
|
225
|
+
var _a;
|
|
226
|
+
(_a = otherObj === null || otherObj === void 0 ? void 0 : otherObj.errorCallback) === null || _a === void 0 ? void 0 : _a.call(otherObj);
|
|
220
227
|
setLoading(false);
|
|
221
228
|
console.log(err);
|
|
222
229
|
});
|
|
@@ -273,8 +280,16 @@ function EnhanceSelect(_a) {
|
|
|
273
280
|
// 发送接口请求,并设置缓存数据
|
|
274
281
|
source = axios.CancelToken.source();
|
|
275
282
|
getDataHandle(request, { url: url, params: params, method: method, timeout: timeout, cancelToken: source.token }, {
|
|
276
|
-
|
|
277
|
-
|
|
283
|
+
appointObj: {
|
|
284
|
+
obj: catchData,
|
|
285
|
+
key: catchDataKey,
|
|
286
|
+
},
|
|
287
|
+
successCallback: function () {
|
|
288
|
+
source = null;
|
|
289
|
+
},
|
|
290
|
+
errorCallback: function () {
|
|
291
|
+
source = null;
|
|
292
|
+
},
|
|
278
293
|
});
|
|
279
294
|
}
|
|
280
295
|
}
|
|
@@ -288,6 +303,13 @@ function EnhanceSelect(_a) {
|
|
|
288
303
|
method: method,
|
|
289
304
|
timeout: timeout,
|
|
290
305
|
cancelToken: source.token,
|
|
306
|
+
}, {
|
|
307
|
+
successCallback: function () {
|
|
308
|
+
source = null;
|
|
309
|
+
},
|
|
310
|
+
errorCallback: function () {
|
|
311
|
+
source = null;
|
|
312
|
+
},
|
|
291
313
|
});
|
|
292
314
|
}
|
|
293
315
|
return function () {
|
|
@@ -329,7 +351,15 @@ function EnhanceSelect(_a) {
|
|
|
329
351
|
if (!restProps.value) {
|
|
330
352
|
// console.log('第一次请求数据');
|
|
331
353
|
source = axios.CancelToken.source();
|
|
332
|
-
getRemoteDataHandle('', '', {
|
|
354
|
+
getRemoteDataHandle('', '', {
|
|
355
|
+
options: { cancelToken: source.token },
|
|
356
|
+
successCallback: function () {
|
|
357
|
+
source = null;
|
|
358
|
+
},
|
|
359
|
+
errorCallback: function () {
|
|
360
|
+
source = null;
|
|
361
|
+
},
|
|
362
|
+
});
|
|
333
363
|
}
|
|
334
364
|
else {
|
|
335
365
|
if (typeof restProps.value === 'string' ||
|
|
@@ -337,7 +367,15 @@ function EnhanceSelect(_a) {
|
|
|
337
367
|
// console.log('第二次请求数据,默认为需要根据主键去请求', restProps.value);
|
|
338
368
|
setFirstLoading(true);
|
|
339
369
|
source = axios.CancelToken.source();
|
|
340
|
-
getRemoteDataHandle('', restProps.value, {
|
|
370
|
+
getRemoteDataHandle('', restProps.value, {
|
|
371
|
+
options: { cancelToken: source.token },
|
|
372
|
+
successCallback: function () {
|
|
373
|
+
source = null;
|
|
374
|
+
},
|
|
375
|
+
errorCallback: function () {
|
|
376
|
+
source = null;
|
|
377
|
+
},
|
|
378
|
+
});
|
|
341
379
|
}
|
|
342
380
|
}
|
|
343
381
|
return function () {
|
|
@@ -363,7 +401,15 @@ function EnhanceSelect(_a) {
|
|
|
363
401
|
// 这种情况不需要启用远程搜索key值
|
|
364
402
|
if (!isRemoteSearchDataKey) {
|
|
365
403
|
source = axios.CancelToken.source();
|
|
366
|
-
getRemoteDataHandle('', '', {
|
|
404
|
+
getRemoteDataHandle('', '', {
|
|
405
|
+
options: { cancelToken: source.token },
|
|
406
|
+
successCallback: function () {
|
|
407
|
+
source = null;
|
|
408
|
+
},
|
|
409
|
+
errorCallback: function () {
|
|
410
|
+
source = null;
|
|
411
|
+
},
|
|
412
|
+
});
|
|
367
413
|
setFirstLoading(true);
|
|
368
414
|
}
|
|
369
415
|
return function () {
|