ztxkui 3.0.0 → 3.0.1

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.
@@ -28,6 +28,7 @@ import React, { useCallback, useEffect, memo, useRef, useState } from 'react';
28
28
  import { Select } from 'antd';
29
29
  import { useFetchState } from 'ztxkutils/dist/hooks';
30
30
  import debounce from 'lodash/debounce';
31
+ import axios from 'axios';
31
32
  /**
32
33
  * 组件缓存的数据格式,在当前浏览器运行内,能保证是唯一的引用,用来缓存数据用
33
34
  * {
@@ -154,7 +155,8 @@ function EnhanceSelect(_a) {
154
155
  });
155
156
  }, [setSelectList, setLoading, transformData, mustHasParams]);
156
157
  // 远程搜索
157
- var getRemoteDataHandle = useCallback(function (value, dataKeyValue) {
158
+ var getRemoteDataHandle = useCallback(function (value, dataKeyValue, options) {
159
+ if (options === void 0) { options = {}; }
158
160
  var searchKey = remoteSearchKey ? remoteSearchKey : titleKey;
159
161
  var searchDataKey = remoteSearchDataKey ? remoteSearchDataKey : dataKey;
160
162
  var outParams = params;
@@ -177,13 +179,10 @@ function EnhanceSelect(_a) {
177
179
  if (dataKeyValue) {
178
180
  searchParams[searchDataKey] = dataKeyValue + '';
179
181
  }
180
- getData(request, {
181
- url: url,
182
- method: method,
183
- params: __assign(__assign({ size: Array.isArray(dataKeyValue) && dataKeyValue.length > 30
182
+ getData(request, __assign({ url: url,
183
+ method: method, params: __assign(__assign({ size: Array.isArray(dataKeyValue) && dataKeyValue.length > 30
184
184
  ? dataKeyValue.length
185
- : 30, page: 1 }, outParams), searchParams),
186
- })
185
+ : 30, page: 1 }, outParams), searchParams) }, options))
187
186
  .then(function (resData) {
188
187
  var _a, _b, _c, _d;
189
188
  if (fetchIdClosure < fetchId.current) {
@@ -256,6 +255,7 @@ function EnhanceSelect(_a) {
256
255
  if (!url || remoteSearch) {
257
256
  return;
258
257
  }
258
+ var source = null;
259
259
  // console.log('TEST: 异步获取');
260
260
  if (isCatch) {
261
261
  // 如果是走缓存的话,那么先往缓存数据中取,有没有当前数据,如果没有就发请求
@@ -271,7 +271,8 @@ function EnhanceSelect(_a) {
271
271
  }
272
272
  else {
273
273
  // 发送接口请求,并设置缓存数据
274
- getDataHandle(request, { url: url, params: params, method: method, timeout: timeout }, {
274
+ source = axios.CancelToken.source();
275
+ getDataHandle(request, { url: url, params: params, method: method, timeout: timeout, cancelToken: source.token }, {
275
276
  obj: catchData,
276
277
  key: catchDataKey,
277
278
  });
@@ -280,8 +281,20 @@ function EnhanceSelect(_a) {
280
281
  }
281
282
  else {
282
283
  // 直接发送接口请求
283
- getDataHandle(request, { url: url, params: params, method: method, timeout: timeout });
284
+ source = axios.CancelToken.source();
285
+ getDataHandle(request, {
286
+ url: url,
287
+ params: params,
288
+ method: method,
289
+ timeout: timeout,
290
+ cancelToken: source.token,
291
+ });
284
292
  }
293
+ return function () {
294
+ if (source) {
295
+ source.cancel();
296
+ }
297
+ };
285
298
  }, [
286
299
  url,
287
300
  params,
@@ -300,6 +313,7 @@ function EnhanceSelect(_a) {
300
313
  if (!url || !remoteSearch) {
301
314
  return;
302
315
  }
316
+ var source = null;
303
317
  // console.log('TEST: 远程搜索');
304
318
  // 如果初始化请求已经做过了,那么这个副作用直接返回
305
319
  if (firstLoading) {
@@ -314,16 +328,23 @@ function EnhanceSelect(_a) {
314
328
  }
315
329
  if (!restProps.value) {
316
330
  // console.log('第一次请求数据');
317
- getRemoteDataHandle('', '');
331
+ source = axios.CancelToken.source();
332
+ getRemoteDataHandle('', '', { cancelToken: source.token });
318
333
  }
319
334
  else {
320
335
  if (typeof restProps.value === 'string' ||
321
336
  (Array.isArray(restProps.value) && restProps.value.length > 0)) {
322
337
  // console.log('第二次请求数据,默认为需要根据主键去请求', restProps.value);
323
338
  setFirstLoading(true);
324
- getRemoteDataHandle('', restProps.value);
339
+ source = axios.CancelToken.source();
340
+ getRemoteDataHandle('', restProps.value, { cancelToken: source.token });
325
341
  }
326
342
  }
343
+ return function () {
344
+ if (source) {
345
+ source.cancel();
346
+ }
347
+ };
327
348
  }, [
328
349
  url,
329
350
  remoteSearch,
@@ -337,13 +358,19 @@ function EnhanceSelect(_a) {
337
358
  if (!url || !remoteSearch) {
338
359
  return;
339
360
  }
361
+ var source = null;
340
362
  // console.log('TEST: 远程搜索');
341
363
  // 这种情况不需要启用远程搜索key值
342
364
  if (!isRemoteSearchDataKey) {
343
- getRemoteDataHandle('', '');
365
+ source = axios.CancelToken.source();
366
+ getRemoteDataHandle('', '', { cancelToken: source.token });
344
367
  setFirstLoading(true);
345
- return;
346
368
  }
369
+ return function () {
370
+ if (source) {
371
+ source.cancel();
372
+ }
373
+ };
347
374
  }, [
348
375
  url,
349
376
  remoteSearch,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkui",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "private": false,
5
5
  "description": "React components library",
6
6
  "author": "zt-front-end",