ztxkutils 2.10.66-15 → 2.10.66-16

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.
Files changed (79) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/{request-ba8abf99.js → request-588c90ec.js} +92 -18
  3. package/dist/{request-0cc024b1.js → request-dc69f021.js} +68 -13
  4. package/dist/request.js +1 -1
  5. package/package.json +1 -1
  6. package/zti18n-cli/bin/index.js +3 -3
  7. package/zti18n-cli/index.js +23 -23
  8. package/zti18n-cli/src/command/convert.js +17 -17
  9. package/zti18n-cli/src/command/convert2.js +35 -35
  10. package/zti18n-cli/src/command/initFileConf.js +133 -133
  11. package/zti18n-cli/src/command/publish.js +24 -24
  12. package/zti18n-cli/src/conf/BaseConf.js +21 -21
  13. package/zti18n-cli/src/conf/FileConf.js +116 -116
  14. package/zti18n-cli/src/index.js +75 -75
  15. package/zti18n-cli/src/translate/google.js +6 -6
  16. package/zti18n-cli/src/utils/isChinese.js +3 -3
  17. package/zti18n-cli/src/utils/log.js +8 -8
  18. package/zti18n-cli/src/utils/mergeOptions.js +45 -45
  19. package/zti18n-cli/src/utils/reactOptions.js +73 -73
  20. package/zti18n-cli/src/utils/vueOptions.js +69 -69
  21. package/zti18n-core/index.js +1 -1
  22. package/zti18n-core/src/index.js +5 -5
  23. package/zti18n-core/src/plugin/reactIntlToReactIntlUniversal.js +224 -224
  24. package/zti18n-core/src/plugin/reactIntlUniversalToDi18n.js +64 -64
  25. package/zti18n-core/src/transform/defaultPkMap.js +79 -79
  26. package/zti18n-core/src/transform/transformHtml.js +271 -271
  27. package/zti18n-core/src/transform/transformPug.js +272 -272
  28. package/zti18n-core/src/transform/transformReactIntlToReactIntlUniversal.js +96 -96
  29. package/zti18n-core/src/transform/transformReactIntlUniveralToDi18n.js +90 -90
  30. package/zti18n-core/src/transform/transformToDi18n.js +22 -22
  31. package/zti18n-core/src/transform/transformTs.js +41 -41
  32. package/zti18n-core/src/transform/transformVue.js +126 -126
  33. package/zti18n-core/src/translate/google.js +6 -6
  34. package/zti18n-core/src/utils/constants.js +3 -3
  35. package/zti18n-core/src/utils/getIgnoreLines.js +14 -14
  36. package/zti18n-core/src/utils/isChinese.js +3 -3
  37. package/zti18n-core/src/utils/log.js +8 -8
  38. package/dist/authority-e6bde99f.js +0 -423
  39. package/dist/reqUrl-3792afcd.js +0 -82
  40. package/dist/reqUrl-787dd9e5.js +0 -82
  41. package/dist/request-ef290b9a.js +0 -2838
  42. package/dist/tools-09a4d620.js +0 -2445
  43. package/dist/tools-0ca888cd.js +0 -2473
  44. package/dist/validate-6e735536.js +0 -79
  45. package/dist/zti18n-cli/bin/index.d.ts +0 -2
  46. package/dist/zti18n-cli/index.d.ts +0 -1
  47. package/dist/zti18n-cli/src/command/collect.d.ts +0 -2
  48. package/dist/zti18n-cli/src/command/convert.d.ts +0 -2
  49. package/dist/zti18n-cli/src/command/convert2.d.ts +0 -2
  50. package/dist/zti18n-cli/src/command/initFileConf.d.ts +0 -2
  51. package/dist/zti18n-cli/src/command/publish.d.ts +0 -2
  52. package/dist/zti18n-cli/src/conf/BaseConf.d.ts +0 -8
  53. package/dist/zti18n-cli/src/conf/FileConf.d.ts +0 -6
  54. package/dist/zti18n-cli/src/index.d.ts +0 -1
  55. package/dist/zti18n-cli/src/translate/google.d.ts +0 -2
  56. package/dist/zti18n-cli/src/utils/isChinese.d.ts +0 -2
  57. package/dist/zti18n-cli/src/utils/log.d.ts +0 -4
  58. package/dist/zti18n-cli/src/utils/mergeOptions.d.ts +0 -24
  59. package/dist/zti18n-cli/src/utils/reactOptions.d.ts +0 -21
  60. package/dist/zti18n-cli/src/utils/vueOptions.d.ts +0 -17
  61. package/dist/zti18n-core/index.d.ts +0 -2
  62. package/dist/zti18n-core/src/index.d.ts +0 -8
  63. package/dist/zti18n-core/src/plugin/reactIntlToReactIntlUniversal.d.ts +0 -19
  64. package/dist/zti18n-core/src/plugin/reactIntlUniversalToDi18n.d.ts +0 -9
  65. package/dist/zti18n-core/src/transform/defaultPkMap.d.ts +0 -75
  66. package/dist/zti18n-core/src/transform/transformHtml.d.ts +0 -5
  67. package/dist/zti18n-core/src/transform/transformJs.d.ts +0 -5
  68. package/dist/zti18n-core/src/transform/transformPug.d.ts +0 -5
  69. package/dist/zti18n-core/src/transform/transformReactIntlToReactIntlUniversal.d.ts +0 -2
  70. package/dist/zti18n-core/src/transform/transformReactIntlUniveralToDi18n.d.ts +0 -2
  71. package/dist/zti18n-core/src/transform/transformToDi18n.d.ts +0 -5
  72. package/dist/zti18n-core/src/transform/transformTs.d.ts +0 -5
  73. package/dist/zti18n-core/src/transform/transformVue.d.ts +0 -5
  74. package/dist/zti18n-core/src/transform/transformZeroToDi18n.d.ts +0 -2
  75. package/dist/zti18n-core/src/translate/google.d.ts +0 -2
  76. package/dist/zti18n-core/src/utils/constants.d.ts +0 -3
  77. package/dist/zti18n-core/src/utils/getIgnoreLines.d.ts +0 -2
  78. package/dist/zti18n-core/src/utils/isChinese.d.ts +0 -2
  79. package/dist/zti18n-core/src/utils/log.d.ts +0 -4
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-390e3466.js';
4
4
  export { v as validate } from './validate-18e52490.js';
5
- export { r as request } from './request-87d93572.js';
5
+ export { r as request } from './request-588c90ec.js';
6
6
  export { r as reqUrl } from './reqUrl-22b880a4.js';
7
7
  import './tslib.es6-35653116.js';
8
8
  import 'dayjs';
@@ -2,7 +2,7 @@ import { a as __rest, _ as __assign } from './tslib.es6-35653116.js';
2
2
  import axios from 'axios';
3
3
  import { Modal, message } from 'ztxkui';
4
4
  import { c as commonjsGlobal, a as crypto } from './crypto-c481f616.js';
5
- import { g as getToken, a as getRefreshToken, s as setToken, b as setRefreshToken } from './authority-e6bde99f.js';
5
+ import { g as getToken, r as removeToken, a as removeRefreshToken, b as getRefreshToken, s as setToken, c as setRefreshToken } from './authority-7a91cb9f.js';
6
6
 
7
7
  /**
8
8
  * Removes all key-value entries from the list cache.
@@ -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
@@ -2566,6 +2567,8 @@ function refreshTokenRequst(jumpCallback, Authorization) {
2566
2567
  requestTokenEndTime = 0;
2567
2568
  if (!isExpiration) {
2568
2569
  isExpiration = true;
2570
+ removeToken();
2571
+ removeRefreshToken();
2569
2572
  if (jumpCallback) {
2570
2573
  jumpCallback(401);
2571
2574
  }
@@ -2605,12 +2608,15 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
2605
2608
  // 拦截器,拦截响应头信息
2606
2609
  var isRefreshToken = (otherOptions || {}).isRefreshToken;
2607
2610
  axios.interceptors.response.use(function (response) {
2608
- var _a, _b;
2611
+ var _a, _b, _c;
2609
2612
  // catchPromiseObj = [];
2610
2613
  axiosCancel.clearPendingRequest(response);
2614
+ if ((_a = response.config) === null || _a === void 0 ? void 0 : _a.noInterceptorsResponse) {
2615
+ return Promise.resolve(response);
2616
+ }
2611
2617
  if (response.status === 200) {
2612
- if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.code) {
2613
- if (((_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.code) === 200) {
2618
+ if ((_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.code) {
2619
+ if (((_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.code) === 200) {
2614
2620
  return Promise.resolve(response);
2615
2621
  }
2616
2622
  else {
@@ -2628,7 +2634,7 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
2628
2634
  return Promise.reject(response);
2629
2635
  }
2630
2636
  }, function (error) {
2631
- var _a, _b, _c, _d, _e;
2637
+ var _a, _b, _c, _d, _e, _f;
2632
2638
  // catchPromiseObj = [];
2633
2639
  console.error(error);
2634
2640
  var errRes = error === null || error === void 0 ? void 0 : error.response;
@@ -2642,19 +2648,24 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
2642
2648
  params: error === null || error === void 0 ? void 0 : error.config.params,
2643
2649
  });
2644
2650
  });
2651
+ /** 如果接口出错了,清理掉这个错误的接口缓存 */
2652
+ var autonomousCatchingKey = ((_a = error === null || error === void 0 ? void 0 : error.config) === null || _a === void 0 ? void 0 : _a.autonomousKey) || (error === null || error === void 0 ? void 0 : error.config.url);
2653
+ if (autonomousCatchingPromiseObj[autonomousCatchingKey]) {
2654
+ autonomousCatchingPromiseObj[autonomousCatchingKey] = undefined;
2655
+ }
2645
2656
  if (item !== -1) {
2646
2657
  catchPromiseObj.splice(item, 1);
2647
2658
  }
2648
- console.log(error === null || error === void 0 ? void 0 : error.config, catchPromiseObj);
2659
+ // console.log(error?.config, catchPromiseObj);
2649
2660
  /** 如果接口出错了,那么清理掉这个错误的接口 */
2650
2661
  // 超时异常统一处理,超时的异常没有response值,只能通过toString处理
2651
2662
  if (!errRes && error.toString().indexOf(timeoutNum + "ms") !== -1) {
2652
2663
  if (!isMessage) {
2653
- if (((_b = (_a = error === null || error === void 0 ? void 0 : error.config) === null || _a === void 0 ? void 0 : _a.method) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === 'POST' &&
2664
+ if (((_c = (_b = error === null || error === void 0 ? void 0 : error.config) === null || _b === void 0 ? void 0 : _b.method) === null || _c === void 0 ? void 0 : _c.toUpperCase()) === 'POST' &&
2654
2665
  __isTimeoutMessage) {
2655
2666
  isMessage = true;
2656
2667
  Modal.confirm({
2657
- title: "\u8BF7\u6C42\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\uFF0C\u8BF7\u53BB\u5217\u8868\u786E\u8BA4\u6570\u636E\u662F\u5426\u63D2\u5165\u6210\u529F\uFF0C\u8BF7\u52FF\u91CD\u590D\u63D0\u4EA4\uFF01\n\u63A5\u53E3\u5730\u5740:" + ((_c = error === null || error === void 0 ? void 0 : error.config) === null || _c === void 0 ? void 0 : _c.url) + "\n\u8BF7\u6C42\u65B9\u5F0F:" + ((_d = error === null || error === void 0 ? void 0 : error.config) === null || _d === void 0 ? void 0 : _d.method) + "\n\u8BF7\u6C42\u8D85\u65F6\u65F6\u95F4:" + ((_e = error === null || error === void 0 ? void 0 : error.config) === null || _e === void 0 ? void 0 : _e.timeout),
2668
+ title: "\u8BF7\u6C42\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\uFF0C\u8BF7\u53BB\u5217\u8868\u786E\u8BA4\u6570\u636E\u662F\u5426\u63D2\u5165\u6210\u529F\uFF0C\u8BF7\u52FF\u91CD\u590D\u63D0\u4EA4\uFF01\n\u63A5\u53E3\u5730\u5740:" + ((_d = error === null || error === void 0 ? void 0 : error.config) === null || _d === void 0 ? void 0 : _d.url) + "\n\u8BF7\u6C42\u65B9\u5F0F:" + ((_e = error === null || error === void 0 ? void 0 : error.config) === null || _e === void 0 ? void 0 : _e.method) + "\n\u8BF7\u6C42\u8D85\u65F6\u65F6\u95F4:" + ((_f = error === null || error === void 0 ? void 0 : error.config) === null || _f === void 0 ? void 0 : _f.timeout),
2658
2669
  okCancel: false,
2659
2670
  onOk: function () {
2660
2671
  isMessage = false;
@@ -2678,6 +2689,8 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
2678
2689
  if ((errRes === null || errRes === void 0 ? void 0 : errRes.status) === 501) {
2679
2690
  if (!isOffSite) {
2680
2691
  isOffSite = true;
2692
+ removeToken();
2693
+ removeRefreshToken();
2681
2694
  if (jumpCallback) {
2682
2695
  jumpCallback(errRes === null || errRes === void 0 ? void 0 : errRes.status);
2683
2696
  }
@@ -2694,6 +2707,8 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
2694
2707
  if ((errRes === null || errRes === void 0 ? void 0 : errRes.status) === 401 && !isRefreshToken) {
2695
2708
  if (!isExpiration) {
2696
2709
  isExpiration = true;
2710
+ removeToken();
2711
+ removeRefreshToken();
2697
2712
  if (jumpCallback) {
2698
2713
  jumpCallback(errRes === null || errRes === void 0 ? void 0 : errRes.status);
2699
2714
  }
@@ -2714,14 +2729,15 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
2714
2729
  function setInterceptorsRequest() {
2715
2730
  // 拦截器,拦截响应头信息
2716
2731
  axios.interceptors.request.use(function (config) {
2717
- var _a;
2732
+ var _a, _b, _c;
2718
2733
  if (config.isCancelRepeat) {
2719
2734
  axiosCancel.pendingRequestCancel(config);
2720
2735
  }
2721
2736
  // 如果需要清除未完成的请求 2023-05-15
2722
2737
  if (config.isCancelNoCompleteRequest &&
2723
2738
  !config.cancelToken &&
2724
- ((_a = config.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== 'POST') {
2739
+ ((_a = config.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== 'POST' &&
2740
+ !((_c = (_b = config.url) === null || _b === void 0 ? void 0 : _b.includes) === null || _c === void 0 ? void 0 : _c.call(_b, 'zmdms-resource'))) {
2725
2741
  var cancelTokenObj = axios.CancelToken.source();
2726
2742
  config.cancelToken = cancelTokenObj.token;
2727
2743
  pendingRequest.push(cancelTokenObj.cancel);
@@ -2756,14 +2772,14 @@ function transformObj(obj) {
2756
2772
  return obj;
2757
2773
  }
2758
2774
  function request(myOptions, jumpCallback, otherOptions) {
2759
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
2775
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
2760
2776
  var InnerAuthorization = (otherOptions || {}).InnerAuthorization;
2761
2777
  if (!isFirstSet) {
2762
2778
  setInterceptorsRequest();
2763
2779
  setInterceptorsResponse(jumpCallback, otherOptions);
2764
2780
  isFirstSet = true;
2765
2781
  }
2766
- var encryptionType = myOptions.encryptionType, isTimeoutMessage = myOptions.isTimeoutMessage, isForceRequest = myOptions.isForceRequest, _k = myOptions.noCatchUrl, noCatchUrl = _k === void 0 ? [] : _k, isCatch = myOptions.isCatch, options = __rest(myOptions, ["encryptionType", "isTimeoutMessage", "isForceRequest", "noCatchUrl", "isCatch"]);
2782
+ 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, autonomousKey = myOptions.autonomousKey, options = __rest(myOptions, ["encryptionType", "isTimeoutMessage", "isForceRequest", "noCatchUrl", "isCatch", "mustCatch", "isAutonomousCatch", "autonomousCount", "autonomousKey"]);
2767
2783
  timeoutNum =
2768
2784
  typeof myOptions.timeout === 'number' ? myOptions.timeout : timeoutNum;
2769
2785
  __isTimeoutMessage = isTimeoutMessage;
@@ -2777,6 +2793,8 @@ function request(myOptions, jumpCallback, otherOptions) {
2777
2793
  'Zmdms-Auth': "bearer " + token,
2778
2794
  'Tenant-Id': '000000',
2779
2795
  Authorization: InnerAuthorization ? InnerAuthorization : Authorization,
2796
+ // 设置语言包请求头
2797
+ 'Zmdms-Lang': window.localStorage.getItem('languageType') || 'zh_CN',
2780
2798
  },
2781
2799
  };
2782
2800
  if ((_a = options.baseURL) === null || _a === void 0 ? void 0 : _a.endsWith('/')) {
@@ -2795,7 +2813,7 @@ function request(myOptions, jumpCallback, otherOptions) {
2795
2813
  options.params = transformObj(options.params);
2796
2814
  }
2797
2815
  // 将传入配置与默认配置混合
2798
- var newOptions = __assign(__assign(__assign({}, defaultOptions), options), { headers: __assign(__assign({}, defaultOptions.headers), options.headers) });
2816
+ var newOptions = __assign(__assign(__assign({}, defaultOptions), options), { autonomousKey: autonomousKey, headers: __assign(__assign({}, defaultOptions.headers), options.headers) });
2799
2817
  // 特殊请求处理
2800
2818
  if (((_e = newOptions.method) === null || _e === void 0 ? void 0 : _e.toUpperCase()) === 'POST' ||
2801
2819
  ((_f = newOptions.method) === null || _f === void 0 ? void 0 : _f.toUpperCase()) === 'PUT' ||
@@ -2839,12 +2857,64 @@ function request(myOptions, jumpCallback, otherOptions) {
2839
2857
  };
2840
2858
  }
2841
2859
  }
2860
+ // 自主缓存请求。默认这个缓存只会针对一个url缓存一次请求
2861
+ if (isAutonomousCatch) {
2862
+ var autonomousCatchingKey = autonomousKey || newOptions.url;
2863
+ var item = autonomousCatchingPromiseObj[autonomousCatchingKey];
2864
+ // 如果当前接口没有缓存 缓存住,并且返回接口结果
2865
+ if (!item || !Array.isArray(item)) {
2866
+ var result = axios(newOptions);
2867
+ autonomousCatchingPromiseObj[autonomousCatchingKey] = [
2868
+ {
2869
+ params: newOptions.params,
2870
+ promiseObj: result,
2871
+ method: (_h = newOptions.method) === null || _h === void 0 ? void 0 : _h.toUpperCase(),
2872
+ },
2873
+ ];
2874
+ return result;
2875
+ }
2876
+ // 如果当前接口有缓存
2877
+ // 判断当前参数是否命中
2878
+ var index = item.findIndex(function (itemChild) {
2879
+ var _a, _b;
2880
+ return isEqual_1({
2881
+ method: (_a = itemChild.method) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
2882
+ params: itemChild.params,
2883
+ }, {
2884
+ method: (_b = newOptions.method) === null || _b === void 0 ? void 0 : _b.toUpperCase(),
2885
+ params: newOptions.params,
2886
+ });
2887
+ });
2888
+ // 如果缓存命中
2889
+ if (index !== -1) {
2890
+ // 最近使用优先
2891
+ var result = item[index];
2892
+ item.splice(index, 1);
2893
+ item.push(result);
2894
+ return result === null || result === void 0 ? void 0 : result.promiseObj;
2895
+ }
2896
+ else {
2897
+ var result = axios(newOptions);
2898
+ // 当前接口可以缓存几个结果 如果超过最大缓存数量 删除第一位
2899
+ if (item.length >= autonomousCount) {
2900
+ item.shift();
2901
+ }
2902
+ item.push({
2903
+ params: newOptions.params,
2904
+ promiseObj: result,
2905
+ method: (_j = newOptions.method) === null || _j === void 0 ? void 0 : _j.toUpperCase(),
2906
+ });
2907
+ return result;
2908
+ }
2909
+ }
2842
2910
  // 缓存本次宏任务下的GET请求,并且不是以/page结尾的列表分页接口
2843
2911
  // 并且不是强制请求,强制请求需要
2844
- if (((_h = newOptions.method) === null || _h === void 0 ? void 0 : _h.toUpperCase()) === 'GET' &&
2845
- !((_j = newOptions.url) === null || _j === void 0 ? void 0 : _j.endsWith('/page')) &&
2912
+ if (((((_k = newOptions.method) === null || _k === void 0 ? void 0 : _k.toUpperCase()) === 'GET' &&
2913
+ !((_l = newOptions.url) === null || _l === void 0 ? void 0 : _l.endsWith('/page')) &&
2846
2914
  !noCatchUrl.find(function (item) { var _a; return (_a = newOptions.url) === null || _a === void 0 ? void 0 : _a.endsWith(item); }) &&
2847
- isCatch) {
2915
+ isCatch) ||
2916
+ mustCatch) &&
2917
+ !isAutonomousCatch) {
2848
2918
  // 能不能找到,url与参数都一样得数据
2849
2919
  var index = catchPromiseObj.findIndex(function (item) {
2850
2920
  return isEqual_1({
@@ -2888,6 +2958,9 @@ function clearNoCompleteRequest() {
2888
2958
  }
2889
2959
  function clearCatch() {
2890
2960
  catchPromiseObj = [];
2961
+ }
2962
+ function clearAutonomousCatch(url) {
2963
+ autonomousCatchingPromiseObj[url] = undefined;
2891
2964
  }
2892
2965
 
2893
2966
  var request$1 = /*#__PURE__*/Object.freeze({
@@ -2896,7 +2969,8 @@ var request$1 = /*#__PURE__*/Object.freeze({
2896
2969
  NEW_AUTHORIZATION: NEW_AUTHORIZATION,
2897
2970
  'default': request,
2898
2971
  clearNoCompleteRequest: clearNoCompleteRequest,
2899
- clearCatch: clearCatch
2972
+ clearCatch: clearCatch,
2973
+ clearAutonomousCatch: clearAutonomousCatch
2900
2974
  });
2901
2975
 
2902
- export { NEW_AUTHORIZATION as N, OLD_AUTHORIZATION as O, request as a, clearCatch as b, clearNoCompleteRequest as c, request$1 as r };
2976
+ 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 };
@@ -2470,7 +2470,7 @@ var AxiosCancel = /** @class */ (function () {
2470
2470
  }());
2471
2471
  var axiosCancel = new AxiosCancel();
2472
2472
 
2473
- var timeoutNum = 60000 * 5;
2473
+ var timeoutNum = 60000;
2474
2474
  var isRefreshing = true; // 是否需要刷新
2475
2475
  var subscribers = []; // 缓存需要帮助请求的接口
2476
2476
  var requestTokenEndTime = 0; // token调用结束时间
@@ -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.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, d as clearAutonomousCatch, b as clearCatch, c as clearNoCompleteRequest, a as default } from './request-87d93572.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-588c90ec.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.66-15",
3
+ "version": "2.10.66-16",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env node
2
-
3
- require('../');
1
+ #!/usr/bin/env node
2
+
3
+ require('../');
@@ -1,23 +1,23 @@
1
- const program = require('./src');
2
- const initFileConf = require('./src/command/initFileConf');
3
-
4
- program
5
- .command('init')
6
- .alias('i')
7
- .description('init locales conf')
8
- .option('--vue', 'init for vue project')
9
- .action(function (options) {
10
- initFileConf(options.vue);
11
- })
12
- .on('--help', function () {
13
- console.log(' Examples:');
14
- console.log();
15
- console.log(' $ zti18n init -c ./config/prod.config.js');
16
- console.log();
17
- });
18
-
19
- program.command('*').action(function (cmd) {
20
- console.log('unknown command "%s"', cmd);
21
- });
22
-
23
- program.parse(process.argv);
1
+ const program = require('./src');
2
+ const initFileConf = require('./src/command/initFileConf');
3
+
4
+ program
5
+ .command('init')
6
+ .alias('i')
7
+ .description('init locales conf')
8
+ .option('--vue', 'init for vue project')
9
+ .action(function (options) {
10
+ initFileConf(options.vue);
11
+ })
12
+ .on('--help', function () {
13
+ console.log(' Examples:');
14
+ console.log();
15
+ console.log(' $ zti18n init -c ./config/prod.config.js');
16
+ console.log();
17
+ });
18
+
19
+ program.command('*').action(function (cmd) {
20
+ console.log('unknown command "%s"', cmd);
21
+ });
22
+
23
+ program.parse(process.argv);
@@ -1,17 +1,17 @@
1
- const {
2
- transformReactIntlToReactIntlUniversal,
3
- } = require('../../../zti18n-core');
4
- const mergeOptions = require('../utils/mergeOptions');
5
- const log = require('../utils/log');
6
-
7
- module.exports = function doConvertToReactIntlUniversal(programOption) {
8
- const options = mergeOptions(programOption, ['entry', 'exclude', 'locales']);
9
-
10
- if (!options.entry) {
11
- log.error('\n · 使用 -e [path] 或 --entry [path] 命令增加待转换的源码目录');
12
- log.error(" · 或在配置文件中设置 'entry' 字段\n");
13
- process.exit(2);
14
- }
15
-
16
- transformReactIntlToReactIntlUniversal(options);
17
- };
1
+ const {
2
+ transformReactIntlToReactIntlUniversal,
3
+ } = require('../../../zti18n-core');
4
+ const mergeOptions = require('../utils/mergeOptions');
5
+ const log = require('../utils/log');
6
+
7
+ module.exports = function doConvertToReactIntlUniversal(programOption) {
8
+ const options = mergeOptions(programOption, ['entry', 'exclude', 'locales']);
9
+
10
+ if (!options.entry) {
11
+ log.error('\n · 使用 -e [path] 或 --entry [path] 命令增加待转换的源码目录');
12
+ log.error(" · 或在配置文件中设置 'entry' 字段\n");
13
+ process.exit(2);
14
+ }
15
+
16
+ transformReactIntlToReactIntlUniversal(options);
17
+ };
@@ -1,35 +1,35 @@
1
- const fs = require('fs');
2
- const { transformReactIntlUniveralToDi18n } = require('../../../zti18n-core');
3
- const mergeOptions = require('../utils/mergeOptions');
4
- const log = require('../utils/log');
5
-
6
- module.exports = function doConvert(programOption) {
7
- const options = mergeOptions(programOption, ['entry', 'exclude', 'locales']);
8
-
9
- if (!options.entry) {
10
- log.error('no entry is specified');
11
- process.exit(2);
12
- }
13
-
14
- if (Array.isArray(options.entry)) {
15
- if (!Array.isArray(options.output)) {
16
- log.error('output should be array too, since entry is array');
17
- process.exit(2);
18
- }
19
-
20
- if (options.output.length !== options.entry.length) {
21
- log.error('output length are not equal to entry length');
22
- process.exit(2);
23
- }
24
- }
25
-
26
- if (options.output) {
27
- [].concat(options.output).forEach((outputDir) => {
28
- if (!fs.existsSync(outputDir)) {
29
- fs.mkdirSync(outputDir);
30
- }
31
- });
32
- }
33
-
34
- return transformReactIntlUniveralToDi18n(options);
35
- };
1
+ const fs = require('fs');
2
+ const { transformReactIntlUniveralToDi18n } = require('../../../zti18n-core');
3
+ const mergeOptions = require('../utils/mergeOptions');
4
+ const log = require('../utils/log');
5
+
6
+ module.exports = function doConvert(programOption) {
7
+ const options = mergeOptions(programOption, ['entry', 'exclude', 'locales']);
8
+
9
+ if (!options.entry) {
10
+ log.error('no entry is specified');
11
+ process.exit(2);
12
+ }
13
+
14
+ if (Array.isArray(options.entry)) {
15
+ if (!Array.isArray(options.output)) {
16
+ log.error('output should be array too, since entry is array');
17
+ process.exit(2);
18
+ }
19
+
20
+ if (options.output.length !== options.entry.length) {
21
+ log.error('output length are not equal to entry length');
22
+ process.exit(2);
23
+ }
24
+ }
25
+
26
+ if (options.output) {
27
+ [].concat(options.output).forEach((outputDir) => {
28
+ if (!fs.existsSync(outputDir)) {
29
+ fs.mkdirSync(outputDir);
30
+ }
31
+ });
32
+ }
33
+
34
+ return transformReactIntlUniveralToDi18n(options);
35
+ };