ztxkutils 2.10.59 → 2.10.60

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/index.js CHANGED
@@ -2,7 +2,7 @@ export { d as authority } from './authority-7a91cb9f.js';
2
2
  export { d as dataModel } from './dataModel-1fbaff40.js';
3
3
  export { t as tools } from './tools-16a7fb45.js';
4
4
  export { v as validate } from './validate-18e52490.js';
5
- export { r as request } from './request-3c906c2d.js';
5
+ export { r as request } from './request-dc69f021.js';
6
6
  export { r as reqUrl } from './reqUrl-22b880a4.js';
7
7
  import './tslib.es6-35653116.js';
8
8
  import 'dayjs';
@@ -2480,6 +2480,7 @@ var isNotFound = false; // 404弹框
2480
2480
  var isOffSite = false; // 501异地登录
2481
2481
  var isExpiration = false; // 401登录过期
2482
2482
  var catchPromiseObj = []; // 缓存当前宏任务下的缓存
2483
+ var autonomousCatchingPromiseObj = {}; // 自主缓存。可以自主清空。每个url只对应一个请求
2483
2484
  var __isTimeoutMessage = false; // 是否需要默认展示超时弹框
2484
2485
  var isFirstSet = false; // 首次初始化
2485
2486
  // 'Basic em1kbXM6em1kbXNfc2VjcmV0' 新的auth
@@ -2647,10 +2648,14 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
2647
2648
  params: error === null || error === void 0 ? void 0 : error.config.params,
2648
2649
  });
2649
2650
  });
2651
+ /** 如果接口出错了,清理掉这个错误的接口缓存 */
2652
+ if (autonomousCatchingPromiseObj[error === null || error === void 0 ? void 0 : error.config.url]) {
2653
+ autonomousCatchingPromiseObj[error === null || error === void 0 ? void 0 : error.config.url] = undefined;
2654
+ }
2650
2655
  if (item !== -1) {
2651
2656
  catchPromiseObj.splice(item, 1);
2652
2657
  }
2653
- console.log(error === null || error === void 0 ? void 0 : error.config, catchPromiseObj);
2658
+ // console.log(error?.config, catchPromiseObj);
2654
2659
  /** 如果接口出错了,那么清理掉这个错误的接口 */
2655
2660
  // 超时异常统一处理,超时的异常没有response值,只能通过toString处理
2656
2661
  if (!errRes && error.toString().indexOf(timeoutNum + "ms") !== -1) {
@@ -2766,14 +2771,14 @@ function transformObj(obj) {
2766
2771
  return obj;
2767
2772
  }
2768
2773
  function request(myOptions, jumpCallback, otherOptions) {
2769
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
2774
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
2770
2775
  var InnerAuthorization = (otherOptions || {}).InnerAuthorization;
2771
2776
  if (!isFirstSet) {
2772
2777
  setInterceptorsRequest();
2773
2778
  setInterceptorsResponse(jumpCallback, otherOptions);
2774
2779
  isFirstSet = true;
2775
2780
  }
2776
- var encryptionType = myOptions.encryptionType, isTimeoutMessage = myOptions.isTimeoutMessage, isForceRequest = myOptions.isForceRequest, _k = myOptions.noCatchUrl, noCatchUrl = _k === void 0 ? [] : _k, isCatch = myOptions.isCatch, mustCatch = myOptions.mustCatch, options = __rest(myOptions, ["encryptionType", "isTimeoutMessage", "isForceRequest", "noCatchUrl", "isCatch", "mustCatch"]);
2781
+ var encryptionType = myOptions.encryptionType, isTimeoutMessage = myOptions.isTimeoutMessage, isForceRequest = myOptions.isForceRequest, _m = myOptions.noCatchUrl, noCatchUrl = _m === void 0 ? [] : _m, isCatch = myOptions.isCatch, mustCatch = myOptions.mustCatch, isAutonomousCatch = myOptions.isAutonomousCatch, _o = myOptions.autonomousCount, autonomousCount = _o === void 0 ? 1 : _o, options = __rest(myOptions, ["encryptionType", "isTimeoutMessage", "isForceRequest", "noCatchUrl", "isCatch", "mustCatch", "isAutonomousCatch", "autonomousCount"]);
2777
2782
  timeoutNum =
2778
2783
  typeof myOptions.timeout === 'number' ? myOptions.timeout : timeoutNum;
2779
2784
  __isTimeoutMessage = isTimeoutMessage;
@@ -2806,10 +2811,6 @@ function request(myOptions, jumpCallback, otherOptions) {
2806
2811
  }
2807
2812
  // 将传入配置与默认配置混合
2808
2813
  var newOptions = __assign(__assign(__assign({}, defaultOptions), options), { headers: __assign(__assign({}, defaultOptions.headers), options.headers) });
2809
- // 湘钢国贸项目 除了登录接口外 去掉 Authorization认证头部
2810
- if (newOptions.url !== '/api/zmdms-auth/oauth/token') {
2811
- delete newOptions.headers.Authorization;
2812
- }
2813
2814
  // 特殊请求处理
2814
2815
  if (((_e = newOptions.method) === null || _e === void 0 ? void 0 : _e.toUpperCase()) === 'POST' ||
2815
2816
  ((_f = newOptions.method) === null || _f === void 0 ? void 0 : _f.toUpperCase()) === 'PUT' ||
@@ -2853,13 +2854,63 @@ function request(myOptions, jumpCallback, otherOptions) {
2853
2854
  };
2854
2855
  }
2855
2856
  }
2857
+ // 自主缓存请求。默认这个缓存只会针对一个url缓存一次请求
2858
+ if (isAutonomousCatch) {
2859
+ var item = autonomousCatchingPromiseObj[newOptions.url];
2860
+ // 如果当前接口没有缓存 缓存住,并且返回接口结果
2861
+ if (!item || !Array.isArray(item)) {
2862
+ var result = axios(newOptions);
2863
+ autonomousCatchingPromiseObj[newOptions.url] = [
2864
+ {
2865
+ params: newOptions.params,
2866
+ promiseObj: result,
2867
+ method: (_h = newOptions.method) === null || _h === void 0 ? void 0 : _h.toUpperCase(),
2868
+ },
2869
+ ];
2870
+ return result;
2871
+ }
2872
+ // 如果当前接口有缓存
2873
+ // 判断当前参数是否命中
2874
+ var index = item.findIndex(function (itemChild) {
2875
+ var _a, _b;
2876
+ return isEqual_1({
2877
+ method: (_a = itemChild.method) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
2878
+ params: itemChild.params,
2879
+ }, {
2880
+ method: (_b = newOptions.method) === null || _b === void 0 ? void 0 : _b.toUpperCase(),
2881
+ params: newOptions.params,
2882
+ });
2883
+ });
2884
+ // 如果缓存命中
2885
+ if (index !== -1) {
2886
+ // 最近使用优先
2887
+ var result = item[index];
2888
+ item.splice(index, 1);
2889
+ item.push(result);
2890
+ return result === null || result === void 0 ? void 0 : result.promiseObj;
2891
+ }
2892
+ else {
2893
+ var result = axios(newOptions);
2894
+ // 当前接口可以缓存几个结果 如果超过最大缓存数量 删除第一位
2895
+ if (item.length >= autonomousCount) {
2896
+ item.shift();
2897
+ }
2898
+ item.push({
2899
+ params: newOptions.params,
2900
+ promiseObj: result,
2901
+ method: (_j = newOptions.method) === null || _j === void 0 ? void 0 : _j.toUpperCase(),
2902
+ });
2903
+ return result;
2904
+ }
2905
+ }
2856
2906
  // 缓存本次宏任务下的GET请求,并且不是以/page结尾的列表分页接口
2857
2907
  // 并且不是强制请求,强制请求需要
2858
- if ((((_h = newOptions.method) === null || _h === void 0 ? void 0 : _h.toUpperCase()) === 'GET' &&
2859
- !((_j = newOptions.url) === null || _j === void 0 ? void 0 : _j.endsWith('/page')) &&
2908
+ if (((((_k = newOptions.method) === null || _k === void 0 ? void 0 : _k.toUpperCase()) === 'GET' &&
2909
+ !((_l = newOptions.url) === null || _l === void 0 ? void 0 : _l.endsWith('/page')) &&
2860
2910
  !noCatchUrl.find(function (item) { var _a; return (_a = newOptions.url) === null || _a === void 0 ? void 0 : _a.endsWith(item); }) &&
2861
2911
  isCatch) ||
2862
- mustCatch) {
2912
+ mustCatch) &&
2913
+ !isAutonomousCatch) {
2863
2914
  // 能不能找到,url与参数都一样得数据
2864
2915
  var index = catchPromiseObj.findIndex(function (item) {
2865
2916
  return isEqual_1({
@@ -2903,6 +2954,9 @@ function clearNoCompleteRequest() {
2903
2954
  }
2904
2955
  function clearCatch() {
2905
2956
  catchPromiseObj = [];
2957
+ }
2958
+ function clearAutonomousCatch(url) {
2959
+ autonomousCatchingPromiseObj[url] = undefined;
2906
2960
  }
2907
2961
 
2908
2962
  var request$1 = /*#__PURE__*/Object.freeze({
@@ -2911,7 +2965,8 @@ var request$1 = /*#__PURE__*/Object.freeze({
2911
2965
  NEW_AUTHORIZATION: NEW_AUTHORIZATION,
2912
2966
  'default': request,
2913
2967
  clearNoCompleteRequest: clearNoCompleteRequest,
2914
- clearCatch: clearCatch
2968
+ clearCatch: clearCatch,
2969
+ clearAutonomousCatch: clearAutonomousCatch
2915
2970
  });
2916
2971
 
2917
- export { NEW_AUTHORIZATION as N, OLD_AUTHORIZATION as O, request as a, clearCatch as b, clearNoCompleteRequest as c, request$1 as r };
2972
+ export { NEW_AUTHORIZATION as N, OLD_AUTHORIZATION as O, request as a, clearCatch as b, clearNoCompleteRequest as c, clearAutonomousCatch as d, request$1 as r };
package/dist/request.d.ts CHANGED
@@ -15,7 +15,10 @@ export interface IOptions extends AxiosRequestConfig {
15
15
  isCancelRepeat?: boolean;
16
16
  isCancelNoCompleteRequest?: boolean;
17
17
  noInterceptorsResponse?: boolean;
18
+ isAutonomousCatch?: boolean;
19
+ autonomousCount?: number;
18
20
  }
19
21
  export default function request(myOptions: IOptions, jumpCallback?: any, otherOptions?: any): any;
20
22
  export declare function clearNoCompleteRequest(): void;
21
23
  export declare function clearCatch(): void;
24
+ export declare function clearAutonomousCatch(url: any): void;
package/dist/request.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import './tslib.es6-35653116.js';
2
2
  import 'axios';
3
3
  import 'ztxkui';
4
- export { N as NEW_AUTHORIZATION, O as OLD_AUTHORIZATION, b as clearCatch, c as clearNoCompleteRequest, a as default } from './request-3c906c2d.js';
4
+ export { N as NEW_AUTHORIZATION, O as OLD_AUTHORIZATION, d as clearAutonomousCatch, b as clearCatch, c as clearNoCompleteRequest, a as default } from './request-dc69f021.js';
5
5
  import './authority-7a91cb9f.js';
6
6
  import './crypto-c481f616.js';
7
7
  import 'crypto';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "2.10.59",
3
+ "version": "2.10.60",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -72,4 +72,4 @@
72
72
  "zt-sockjs-client": ">=0.0.1",
73
73
  "zt-stompjs": ">=1.0.3"
74
74
  }
75
- }
75
+ }
@@ -1,82 +0,0 @@
1
- /**
2
- * @file 项目基本配置,包括各个环境的请求地址
3
- */
4
- // 环境变量
5
- function getReqUrl(processObj) {
6
- var ENV = processObj.REACT_APP_ENV;
7
- // api服务器各个环境地址
8
- var ZT_API_DEV = processObj.REACT_APP_ZT_API_DEV || 'http://192.168.0.83:8000'; // 开发环境
9
- var ZT_API_TEST = processObj.REACT_APP_ZT_API_TEST || window.location.origin; // 测试环境 https://192.168.0.135:8000
10
- var ZT_API_STAGE = processObj.REACT_APP_ZT_API_STAGE || window.location.origin; // 阶段性环境 http://192.168.0.134:8000
11
- var ZT_API_SIM = processObj.REACT_APP_ZT_API_SIM || window.location.origin; // 阶段性环境 http://192.168.0.134:8000
12
- var ZT_API_PRODUCT = processObj.REACT_APP_ZT_API_PRODUCT || window.location.origin; // 生产环境 http://dz.zmd.com.cn
13
- var ZT_API_PUBLIC_PRODUCT = processObj.REACT_APP_ZT_API_PUBLIC_PRODUCT ||
14
- 'https://nportal.zmd.com.cn:18998'; // 生产环境外网api地址 https://m-portal.zmd.com.cn:18998 http://dz.zmd.com.cn:48000
15
- // 文件服务器
16
- var ZT_FILE_PREVIEW_DEV = processObj.REACT_APP_ZT_FILE_PREVIEW_DEV || 'http://192.168.0.83:88'; // 开发环境
17
- var ZT_FILE_PREVIEW_TEST = processObj.REACT_APP_ZT_FILE_PREVIEW_TEST || 'http://172.55.5.101:33013'; // 测试环境 https://192.168.0.135:18012
18
- var ZT_FILE_PREVIEW_STAGE = processObj.REACT_APP_ZT_FILE_PREVIEW_STAGE ||
19
- 'https://dzfile-prod.zmd.com.cn/'; // 阶段性环境 http://192.168.0.134:8012
20
- var ZT_FILE_PREVIEW_SIM = processObj.REACT_APP_ZT_FILE_PREVIEW_SIM ||
21
- 'https://dzfile-data.zmd.com.cn/'; // 阶段性环境 http://192.168.0.134:8012
22
- var ZT_FILE_PREVIEW_PRODUCT = processObj.REACT_APP_ZT_FILE_PREVIEW_PRODUCT ||
23
- 'https://dzfile.zmd.com.cn:8012'; // 生产环境
24
- // 字体文件附件id
25
- var ZT_FONTFAMILY_DEV = '1551733945007517697';
26
- var ZT_FONTFAMILY_TEST = '1551836774183047169';
27
- var ZT_FONTFAMILY_STAGE = '1551837561144905730';
28
- var ZT_FONTFAMILY_SIM = '1562010976138207234';
29
- var ZT_FONTFAMILY_PRODUCT = '1552851055372992513';
30
- // 实际api请求地址
31
- var ZT_API_BASEURL = ZT_API_DEV;
32
- var ZT_API_PUBLICURL = ZT_API_PUBLIC_PRODUCT;
33
- var ZT_FILE_BASEURL = ZT_FILE_PREVIEW_DEV;
34
- var ZT_FONTFAMILY_BASEURL = ZT_FONTFAMILY_DEV;
35
- if (ENV) {
36
- switch (ENV.toLowerCase()) {
37
- case 'zt-dev':
38
- ZT_API_BASEURL = ZT_API_DEV;
39
- ZT_API_PUBLICURL = ZT_API_DEV;
40
- ZT_FILE_BASEURL = ZT_FILE_PREVIEW_DEV;
41
- ZT_FONTFAMILY_BASEURL = ZT_FONTFAMILY_DEV;
42
- break;
43
- case 'zt-test':
44
- ZT_API_BASEURL = ZT_API_TEST;
45
- ZT_API_PUBLICURL = ZT_API_TEST;
46
- ZT_FILE_BASEURL = ZT_FILE_PREVIEW_TEST;
47
- ZT_FONTFAMILY_BASEURL = ZT_FONTFAMILY_TEST;
48
- break;
49
- case 'zt-stage':
50
- ZT_API_BASEURL = ZT_API_STAGE;
51
- ZT_API_PUBLICURL = ZT_API_STAGE;
52
- ZT_FILE_BASEURL = ZT_FILE_PREVIEW_STAGE;
53
- ZT_FONTFAMILY_BASEURL = ZT_FONTFAMILY_STAGE;
54
- break;
55
- case 'zt-sim':
56
- ZT_API_BASEURL = ZT_API_SIM;
57
- ZT_API_PUBLICURL = ZT_API_SIM;
58
- ZT_FILE_BASEURL = ZT_FILE_PREVIEW_SIM;
59
- ZT_FONTFAMILY_BASEURL = ZT_FONTFAMILY_SIM;
60
- break;
61
- case 'zt-product':
62
- ZT_API_BASEURL = ZT_API_PRODUCT;
63
- ZT_API_PUBLICURL = ZT_API_PUBLIC_PRODUCT;
64
- ZT_FILE_BASEURL = ZT_FILE_PREVIEW_PRODUCT;
65
- ZT_FONTFAMILY_BASEURL = ZT_FONTFAMILY_PRODUCT;
66
- break;
67
- }
68
- }
69
- return {
70
- ZT_API_BASEURL: ZT_API_BASEURL,
71
- ZT_FILE_BASEURL: ZT_FILE_BASEURL,
72
- ZT_API_PUBLICURL: ZT_API_PUBLICURL,
73
- ZT_FONTFAMILY_BASEURL: ZT_FONTFAMILY_BASEURL,
74
- };
75
- }
76
-
77
- var reqUrl = /*#__PURE__*/Object.freeze({
78
- __proto__: null,
79
- getReqUrl: getReqUrl
80
- });
81
-
82
- export { getReqUrl as g, reqUrl as r };