ztxkutils 2.10.66-4 → 2.10.66-41
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/businessTools.js +4 -3
- package/dist/{dataModel-1fbaff40.js → dataModel-f1ef06bc.js} +4 -2
- package/dist/dataModel.js +2 -1
- package/dist/fileOperation.d.ts +19 -0
- package/dist/fileOperation.js +55 -17
- package/dist/hooks.js +35 -23
- package/dist/i18next.d.ts +2 -0
- package/dist/i18next.js +2401 -0
- package/dist/index.js +6 -5
- package/dist/myIndexDb.d.ts +1 -1
- package/dist/print.d.ts +2 -4
- package/dist/print.js +60 -12
- package/dist/{reqUrl-22b880a4.js → reqUrl-ea7ef876.js} +3 -2
- package/dist/reqUrl.js +1 -1
- package/dist/request-3b358860.js +2988 -0
- package/dist/{request-87d93572.js → request-40e9ca7b.js} +16 -8
- package/dist/{request-dc69f021.js → request-7bcf02f4.js} +34 -20
- package/dist/{request-3c906c2d.js → request-e147d640.js} +98 -23
- package/dist/request.d.ts +4 -0
- package/dist/request.js +2 -1
- package/dist/stompClient.js +21 -8
- package/dist/{tools-16a7fb45.js → tools-47b9bee7.js} +53 -1
- package/dist/tools.js +1 -1
- package/dist/useFileIdToBase64.js +1 -1
- package/dist/useHistory.js +7 -0
- package/dist/{validate-18e52490.js → validate-2138d94a.js} +29 -15
- package/dist/validate.d.ts +1 -0
- package/dist/validate.js +2 -1
- package/dist/workflow.js +4 -6
- package/locales/en-US.json +64 -0
- package/locales/zh-CN.json +64 -0
- package/package.json +41 -4
- package/zti18n-cli/bin/index.js +3 -0
- package/zti18n-cli/index.js +23 -0
- package/zti18n-cli/src/command/collect.js +353 -0
- package/zti18n-cli/src/command/convert.js +17 -0
- package/zti18n-cli/src/command/convert2.js +35 -0
- package/zti18n-cli/src/command/initFileConf.js +133 -0
- package/zti18n-cli/src/command/publish.js +24 -0
- package/zti18n-cli/src/conf/BaseConf.js +21 -0
- package/zti18n-cli/src/conf/FileConf.js +116 -0
- package/zti18n-cli/src/index.js +75 -0
- package/zti18n-cli/src/translate/google.js +87 -0
- package/zti18n-cli/src/utils/isChinese.js +3 -0
- package/zti18n-cli/src/utils/log.js +8 -0
- package/zti18n-cli/src/utils/mergeOptions.js +45 -0
- package/zti18n-cli/src/utils/reactOptions.js +73 -0
- package/zti18n-cli/src/utils/vueOptions.js +69 -0
- package/zti18n-core/index.js +1 -0
- package/zti18n-core/src/index.js +5 -0
- package/zti18n-core/src/plugin/reactIntlToReactIntlUniversal.js +224 -0
- package/zti18n-core/src/plugin/reactIntlUniversalToDi18n.js +64 -0
- package/zti18n-core/src/transform/defaultPkMap.js +79 -0
- package/zti18n-core/src/transform/transformHtml.js +271 -0
- package/zti18n-core/src/transform/transformJs.js +489 -0
- package/zti18n-core/src/transform/transformPug.js +272 -0
- package/zti18n-core/src/transform/transformReactIntlToReactIntlUniversal.js +96 -0
- package/zti18n-core/src/transform/transformReactIntlUniveralToDi18n.js +90 -0
- package/zti18n-core/src/transform/transformToDi18n.js +22 -0
- package/zti18n-core/src/transform/transformTs.js +41 -0
- package/zti18n-core/src/transform/transformVue.js +126 -0
- package/zti18n-core/src/transform/transformZeroToDi18n.js +105 -0
- package/zti18n-core/src/translate/google.js +6 -0
- package/zti18n-core/src/utils/constants.js +3 -0
- package/zti18n-core/src/utils/getIgnoreLines.js +14 -0
- package/zti18n-core/src/utils/isChinese.js +3 -0
- package/zti18n-core/src/utils/log.js +8 -0
@@ -1,4 +1,5 @@
|
|
1
1
|
import { a as __rest, _ as __assign } from './tslib.es6-35653116.js';
|
2
|
+
import instance from './i18next.js';
|
2
3
|
import axios from 'axios';
|
3
4
|
import { Modal, message } from 'ztxkui';
|
4
5
|
import { c as commonjsGlobal, a as crypto } from './crypto-c481f616.js';
|
@@ -2452,7 +2453,7 @@ var AxiosCancel = /** @class */ (function () {
|
|
2452
2453
|
// 将token挂载到当前接口的请求头里面
|
2453
2454
|
config.cancelToken = cancelTokenObj.token;
|
2454
2455
|
if (this.pendingRequests.has(key)) {
|
2455
|
-
this.pendingRequests.get(key).cancel('拦截重复请求');
|
2456
|
+
this.pendingRequests.get(key).cancel(instance.t('拦截重复请求'));
|
2456
2457
|
this.pendingRequests.delete(key);
|
2457
2458
|
}
|
2458
2459
|
this.pendingRequests.set(key, {
|
@@ -2512,7 +2513,7 @@ function checkStatus(response, jumpCallback, otherOptions) {
|
|
2512
2513
|
refreshTokenRequst(jumpCallback, InnerAuthorization);
|
2513
2514
|
}
|
2514
2515
|
else {
|
2515
|
-
message.info(
|
2516
|
+
message.info(instance.t('刷新token遭到频繁调用,请联系管理员查看是否接口权限出现问题,可能是{{slot0}}接口出现问题', { slot0: response === null || response === void 0 ? void 0 : response.config.url }), 5);
|
2516
2517
|
requestTokenEndTime = 0;
|
2517
2518
|
}
|
2518
2519
|
}
|
@@ -2560,6 +2561,7 @@ function refreshTokenRequst(jumpCallback, Authorization) {
|
|
2560
2561
|
// 刷新成功 重置token 重置refresh-token
|
2561
2562
|
setToken(data === null || data === void 0 ? void 0 : data.access_token);
|
2562
2563
|
setRefreshToken(data === null || data === void 0 ? void 0 : data.refresh_token);
|
2564
|
+
message.info(instance.t('token已经刷新成功,请重新提交!', {}));
|
2563
2565
|
onAccessTokenFetched();
|
2564
2566
|
isRefreshing = true;
|
2565
2567
|
}
|
@@ -2573,7 +2575,7 @@ function refreshTokenRequst(jumpCallback, Authorization) {
|
|
2573
2575
|
jumpCallback(401);
|
2574
2576
|
}
|
2575
2577
|
else {
|
2576
|
-
message.info(
|
2578
|
+
message.info(instance.t('登录过期!', {}), 3.5, function () {
|
2577
2579
|
isExpiration = false;
|
2578
2580
|
});
|
2579
2581
|
window.location.href = '/login';
|
@@ -2589,7 +2591,7 @@ function refreshTokenRequst(jumpCallback, Authorization) {
|
|
2589
2591
|
jumpCallback(401);
|
2590
2592
|
}
|
2591
2593
|
else {
|
2592
|
-
message.info(
|
2594
|
+
message.info(instance.t('登录过期!', {}), 3.5, function () {
|
2593
2595
|
isExpiration = false;
|
2594
2596
|
});
|
2595
2597
|
window.location.href = '/login';
|
@@ -2665,7 +2667,11 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
|
|
2665
2667
|
__isTimeoutMessage) {
|
2666
2668
|
isMessage = true;
|
2667
2669
|
Modal.confirm({
|
2668
|
-
title:
|
2670
|
+
title: instance.t('请求超时,请稍后再试,请去列表确认数据是否插入成功,请勿重复提交! 接口地址:{{slot0}} 请求方式:{{slot1}} 请求超时时间:{{slot2}}', {
|
2671
|
+
slot0: (_d = error === null || error === void 0 ? void 0 : error.config) === null || _d === void 0 ? void 0 : _d.url,
|
2672
|
+
slot1: (_e = error === null || error === void 0 ? void 0 : error.config) === null || _e === void 0 ? void 0 : _e.method,
|
2673
|
+
slot2: (_f = error === null || error === void 0 ? void 0 : error.config) === null || _f === void 0 ? void 0 : _f.timeout,
|
2674
|
+
}),
|
2669
2675
|
okCancel: false,
|
2670
2676
|
onOk: function () {
|
2671
2677
|
isMessage = false;
|
@@ -2679,7 +2685,7 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
|
|
2679
2685
|
if ((errRes === null || errRes === void 0 ? void 0 : errRes.status) === 404) {
|
2680
2686
|
if (!isNotFound) {
|
2681
2687
|
isNotFound = true;
|
2682
|
-
message.info(
|
2688
|
+
message.info(instance.t('接口: {{slot0}} 未找到!', { slot0: errRes.config.url }), 3.5, function () {
|
2683
2689
|
isNotFound = false;
|
2684
2690
|
});
|
2685
2691
|
}
|
@@ -2695,7 +2701,7 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
|
|
2695
2701
|
jumpCallback(errRes === null || errRes === void 0 ? void 0 : errRes.status);
|
2696
2702
|
}
|
2697
2703
|
else {
|
2698
|
-
message.info(
|
2704
|
+
message.info(instance.t('你的账号已在其他地方登录!', {}), 3.5, function () {
|
2699
2705
|
isOffSite = false;
|
2700
2706
|
});
|
2701
2707
|
window.location.href = '/login';
|
@@ -2713,7 +2719,7 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
|
|
2713
2719
|
jumpCallback(errRes === null || errRes === void 0 ? void 0 : errRes.status);
|
2714
2720
|
}
|
2715
2721
|
else {
|
2716
|
-
message.info(
|
2722
|
+
message.info(instance.t('登录过期!', {}), 3.5, function () {
|
2717
2723
|
isExpiration = false;
|
2718
2724
|
});
|
2719
2725
|
window.location.href = '/login';
|
@@ -2793,6 +2799,8 @@ function request(myOptions, jumpCallback, otherOptions) {
|
|
2793
2799
|
'Zmdms-Auth': "bearer " + token,
|
2794
2800
|
'Tenant-Id': '000000',
|
2795
2801
|
Authorization: InnerAuthorization ? InnerAuthorization : Authorization,
|
2802
|
+
// 设置语言包请求头
|
2803
|
+
'Zmdms-Lang': window.localStorage.getItem('languageType') || 'zh_CN',
|
2796
2804
|
},
|
2797
2805
|
};
|
2798
2806
|
if ((_a = options.baseURL) === null || _a === void 0 ? void 0 : _a.endsWith('/')) {
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { a as __rest, _ as __assign } from './tslib.es6-35653116.js';
|
2
|
+
import instance from './i18next.js';
|
2
3
|
import axios from 'axios';
|
3
4
|
import { Modal, message } from 'ztxkui';
|
4
5
|
import { c as commonjsGlobal, a as crypto } from './crypto-c481f616.js';
|
@@ -2452,7 +2453,7 @@ var AxiosCancel = /** @class */ (function () {
|
|
2452
2453
|
// 将token挂载到当前接口的请求头里面
|
2453
2454
|
config.cancelToken = cancelTokenObj.token;
|
2454
2455
|
if (this.pendingRequests.has(key)) {
|
2455
|
-
this.pendingRequests.get(key).cancel('拦截重复请求');
|
2456
|
+
this.pendingRequests.get(key).cancel(instance.t('拦截重复请求'));
|
2456
2457
|
this.pendingRequests.delete(key);
|
2457
2458
|
}
|
2458
2459
|
this.pendingRequests.set(key, {
|
@@ -2505,14 +2506,16 @@ function loginRequest(params, InnerAuthorization) {
|
|
2505
2506
|
});
|
2506
2507
|
}
|
2507
2508
|
function checkStatus(response, jumpCallback, otherOptions) {
|
2508
|
-
var
|
2509
|
+
var _a = otherOptions || {}, InnerAuthorization = _a.InnerAuthorization, refreshTokenCallback = _a.refreshTokenCallback;
|
2509
2510
|
if ((response === null || response === void 0 ? void 0 : response.status) === 401) {
|
2510
2511
|
if (isRefreshing) {
|
2511
2512
|
if (Date.now() - requestTokenEndTime > reqTokenTimeInterval) {
|
2512
|
-
refreshTokenRequst(jumpCallback, InnerAuthorization
|
2513
|
+
refreshTokenRequst(jumpCallback, InnerAuthorization, {
|
2514
|
+
refreshTokenCallback: refreshTokenCallback,
|
2515
|
+
});
|
2513
2516
|
}
|
2514
2517
|
else {
|
2515
|
-
message.info(
|
2518
|
+
message.info(instance.t('刷新token遭到频繁调用,请联系管理员查看是否接口权限出现问题,可能是{{slot0}}接口出现问题', { slot0: response === null || response === void 0 ? void 0 : response.config.url }), 5);
|
2516
2519
|
requestTokenEndTime = 0;
|
2517
2520
|
}
|
2518
2521
|
}
|
@@ -2546,7 +2549,8 @@ function checkStatus(response, jumpCallback, otherOptions) {
|
|
2546
2549
|
// return retryOriginalRequest;
|
2547
2550
|
}
|
2548
2551
|
}
|
2549
|
-
function refreshTokenRequst(jumpCallback, Authorization) {
|
2552
|
+
function refreshTokenRequst(jumpCallback, Authorization, otherOptions) {
|
2553
|
+
var refreshTokenCallback = (otherOptions || {}).refreshTokenCallback;
|
2550
2554
|
loginRequest({
|
2551
2555
|
tenantId: '000000',
|
2552
2556
|
grant_type: 'refresh_token',
|
@@ -2560,7 +2564,9 @@ function refreshTokenRequst(jumpCallback, Authorization) {
|
|
2560
2564
|
// 刷新成功 重置token 重置refresh-token
|
2561
2565
|
setToken(data === null || data === void 0 ? void 0 : data.access_token);
|
2562
2566
|
setRefreshToken(data === null || data === void 0 ? void 0 : data.refresh_token);
|
2567
|
+
message.info(instance.t('token已经刷新成功,请重新提交!', {}));
|
2563
2568
|
onAccessTokenFetched();
|
2569
|
+
refreshTokenCallback === null || refreshTokenCallback === void 0 ? void 0 : refreshTokenCallback();
|
2564
2570
|
isRefreshing = true;
|
2565
2571
|
}
|
2566
2572
|
else {
|
@@ -2573,7 +2579,7 @@ function refreshTokenRequst(jumpCallback, Authorization) {
|
|
2573
2579
|
jumpCallback(401);
|
2574
2580
|
}
|
2575
2581
|
else {
|
2576
|
-
message.info(
|
2582
|
+
message.info(instance.t('登录过期!', {}), 3.5, function () {
|
2577
2583
|
isExpiration = false;
|
2578
2584
|
});
|
2579
2585
|
window.location.href = '/login';
|
@@ -2589,7 +2595,7 @@ function refreshTokenRequst(jumpCallback, Authorization) {
|
|
2589
2595
|
jumpCallback(401);
|
2590
2596
|
}
|
2591
2597
|
else {
|
2592
|
-
message.info(
|
2598
|
+
message.info(instance.t('登录过期!', {}), 3.5, function () {
|
2593
2599
|
isExpiration = false;
|
2594
2600
|
});
|
2595
2601
|
window.location.href = '/login';
|
@@ -2606,7 +2612,7 @@ function onAccessTokenFetched() {
|
|
2606
2612
|
}
|
2607
2613
|
function setInterceptorsResponse(jumpCallback, otherOptions) {
|
2608
2614
|
// 拦截器,拦截响应头信息
|
2609
|
-
var
|
2615
|
+
var _a = otherOptions || {}, isRefreshToken = _a.isRefreshToken; _a.refreshTokenCallback;
|
2610
2616
|
axios.interceptors.response.use(function (response) {
|
2611
2617
|
var _a, _b, _c;
|
2612
2618
|
// catchPromiseObj = [];
|
@@ -2634,7 +2640,7 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
|
|
2634
2640
|
return Promise.reject(response);
|
2635
2641
|
}
|
2636
2642
|
}, function (error) {
|
2637
|
-
var _a, _b, _c, _d, _e;
|
2643
|
+
var _a, _b, _c, _d, _e, _f;
|
2638
2644
|
// catchPromiseObj = [];
|
2639
2645
|
console.error(error);
|
2640
2646
|
var errRes = error === null || error === void 0 ? void 0 : error.response;
|
@@ -2649,8 +2655,9 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
|
|
2649
2655
|
});
|
2650
2656
|
});
|
2651
2657
|
/** 如果接口出错了,清理掉这个错误的接口缓存 */
|
2652
|
-
|
2653
|
-
|
2658
|
+
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);
|
2659
|
+
if (autonomousCatchingPromiseObj[autonomousCatchingKey]) {
|
2660
|
+
autonomousCatchingPromiseObj[autonomousCatchingKey] = undefined;
|
2654
2661
|
}
|
2655
2662
|
if (item !== -1) {
|
2656
2663
|
catchPromiseObj.splice(item, 1);
|
@@ -2660,11 +2667,15 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
|
|
2660
2667
|
// 超时异常统一处理,超时的异常没有response值,只能通过toString处理
|
2661
2668
|
if (!errRes && error.toString().indexOf(timeoutNum + "ms") !== -1) {
|
2662
2669
|
if (!isMessage) {
|
2663
|
-
if (((
|
2670
|
+
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' &&
|
2664
2671
|
__isTimeoutMessage) {
|
2665
2672
|
isMessage = true;
|
2666
2673
|
Modal.confirm({
|
2667
|
-
title:
|
2674
|
+
title: instance.t('请求超时,请稍后再试,请去列表确认数据是否插入成功,请勿重复提交! 接口地址:{{slot0}} 请求方式:{{slot1}} 请求超时时间:{{slot2}}', {
|
2675
|
+
slot0: (_d = error === null || error === void 0 ? void 0 : error.config) === null || _d === void 0 ? void 0 : _d.url,
|
2676
|
+
slot1: (_e = error === null || error === void 0 ? void 0 : error.config) === null || _e === void 0 ? void 0 : _e.method,
|
2677
|
+
slot2: (_f = error === null || error === void 0 ? void 0 : error.config) === null || _f === void 0 ? void 0 : _f.timeout,
|
2678
|
+
}),
|
2668
2679
|
okCancel: false,
|
2669
2680
|
onOk: function () {
|
2670
2681
|
isMessage = false;
|
@@ -2678,7 +2689,7 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
|
|
2678
2689
|
if ((errRes === null || errRes === void 0 ? void 0 : errRes.status) === 404) {
|
2679
2690
|
if (!isNotFound) {
|
2680
2691
|
isNotFound = true;
|
2681
|
-
message.info(
|
2692
|
+
message.info(instance.t('接口: {{slot0}} 未找到!', { slot0: errRes.config.url }), 3.5, function () {
|
2682
2693
|
isNotFound = false;
|
2683
2694
|
});
|
2684
2695
|
}
|
@@ -2694,7 +2705,7 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
|
|
2694
2705
|
jumpCallback(errRes === null || errRes === void 0 ? void 0 : errRes.status);
|
2695
2706
|
}
|
2696
2707
|
else {
|
2697
|
-
message.info(
|
2708
|
+
message.info(instance.t('你的账号已在其他地方登录!', {}), 3.5, function () {
|
2698
2709
|
isOffSite = false;
|
2699
2710
|
});
|
2700
2711
|
window.location.href = '/login';
|
@@ -2712,7 +2723,7 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
|
|
2712
2723
|
jumpCallback(errRes === null || errRes === void 0 ? void 0 : errRes.status);
|
2713
2724
|
}
|
2714
2725
|
else {
|
2715
|
-
message.info(
|
2726
|
+
message.info(instance.t('登录过期!', {}), 3.5, function () {
|
2716
2727
|
isExpiration = false;
|
2717
2728
|
});
|
2718
2729
|
window.location.href = '/login';
|
@@ -2778,7 +2789,7 @@ function request(myOptions, jumpCallback, otherOptions) {
|
|
2778
2789
|
setInterceptorsResponse(jumpCallback, otherOptions);
|
2779
2790
|
isFirstSet = true;
|
2780
2791
|
}
|
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"]);
|
2792
|
+
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"]);
|
2782
2793
|
timeoutNum =
|
2783
2794
|
typeof myOptions.timeout === 'number' ? myOptions.timeout : timeoutNum;
|
2784
2795
|
__isTimeoutMessage = isTimeoutMessage;
|
@@ -2792,6 +2803,8 @@ function request(myOptions, jumpCallback, otherOptions) {
|
|
2792
2803
|
'Zmdms-Auth': "bearer " + token,
|
2793
2804
|
'Tenant-Id': '000000',
|
2794
2805
|
Authorization: InnerAuthorization ? InnerAuthorization : Authorization,
|
2806
|
+
// 设置语言包请求头
|
2807
|
+
'Zmdms-Lang': window.localStorage.getItem('languageType') || 'zh_CN',
|
2795
2808
|
},
|
2796
2809
|
};
|
2797
2810
|
if ((_a = options.baseURL) === null || _a === void 0 ? void 0 : _a.endsWith('/')) {
|
@@ -2810,7 +2823,7 @@ function request(myOptions, jumpCallback, otherOptions) {
|
|
2810
2823
|
options.params = transformObj(options.params);
|
2811
2824
|
}
|
2812
2825
|
// 将传入配置与默认配置混合
|
2813
|
-
var newOptions = __assign(__assign(__assign({}, defaultOptions), options), { headers: __assign(__assign({}, defaultOptions.headers), options.headers) });
|
2826
|
+
var newOptions = __assign(__assign(__assign({}, defaultOptions), options), { autonomousKey: autonomousKey, headers: __assign(__assign({}, defaultOptions.headers), options.headers) });
|
2814
2827
|
// 特殊请求处理
|
2815
2828
|
if (((_e = newOptions.method) === null || _e === void 0 ? void 0 : _e.toUpperCase()) === 'POST' ||
|
2816
2829
|
((_f = newOptions.method) === null || _f === void 0 ? void 0 : _f.toUpperCase()) === 'PUT' ||
|
@@ -2856,11 +2869,12 @@ function request(myOptions, jumpCallback, otherOptions) {
|
|
2856
2869
|
}
|
2857
2870
|
// 自主缓存请求。默认这个缓存只会针对一个url缓存一次请求
|
2858
2871
|
if (isAutonomousCatch) {
|
2859
|
-
var
|
2872
|
+
var autonomousCatchingKey = autonomousKey || newOptions.url;
|
2873
|
+
var item = autonomousCatchingPromiseObj[autonomousCatchingKey];
|
2860
2874
|
// 如果当前接口没有缓存 缓存住,并且返回接口结果
|
2861
2875
|
if (!item || !Array.isArray(item)) {
|
2862
2876
|
var result = axios(newOptions);
|
2863
|
-
autonomousCatchingPromiseObj[
|
2877
|
+
autonomousCatchingPromiseObj[autonomousCatchingKey] = [
|
2864
2878
|
{
|
2865
2879
|
params: newOptions.params,
|
2866
2880
|
promiseObj: result,
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { a as __rest, _ as __assign } from './tslib.es6-35653116.js';
|
2
|
+
import instance from './i18next.js';
|
2
3
|
import axios from 'axios';
|
3
4
|
import { Modal, message } from 'ztxkui';
|
4
5
|
import { c as commonjsGlobal, a as crypto } from './crypto-c481f616.js';
|
@@ -2452,7 +2453,7 @@ var AxiosCancel = /** @class */ (function () {
|
|
2452
2453
|
// 将token挂载到当前接口的请求头里面
|
2453
2454
|
config.cancelToken = cancelTokenObj.token;
|
2454
2455
|
if (this.pendingRequests.has(key)) {
|
2455
|
-
this.pendingRequests.get(key).cancel('拦截重复请求');
|
2456
|
+
this.pendingRequests.get(key).cancel(instance.t('拦截重复请求'));
|
2456
2457
|
this.pendingRequests.delete(key);
|
2457
2458
|
}
|
2458
2459
|
this.pendingRequests.set(key, {
|
@@ -2480,6 +2481,7 @@ var isNotFound = false; // 404弹框
|
|
2480
2481
|
var isOffSite = false; // 501异地登录
|
2481
2482
|
var isExpiration = false; // 401登录过期
|
2482
2483
|
var catchPromiseObj = []; // 缓存当前宏任务下的缓存
|
2484
|
+
var autonomousCatchingPromiseObj = {}; // 自主缓存。可以自主清空。每个url只对应一个请求
|
2483
2485
|
var __isTimeoutMessage = false; // 是否需要默认展示超时弹框
|
2484
2486
|
var isFirstSet = false; // 首次初始化
|
2485
2487
|
// 'Basic em1kbXM6em1kbXNfc2VjcmV0' 新的auth
|
@@ -2504,14 +2506,16 @@ function loginRequest(params, InnerAuthorization) {
|
|
2504
2506
|
});
|
2505
2507
|
}
|
2506
2508
|
function checkStatus(response, jumpCallback, otherOptions) {
|
2507
|
-
var
|
2509
|
+
var _a = otherOptions || {}, InnerAuthorization = _a.InnerAuthorization, refreshTokenCallback = _a.refreshTokenCallback;
|
2508
2510
|
if ((response === null || response === void 0 ? void 0 : response.status) === 401) {
|
2509
2511
|
if (isRefreshing) {
|
2510
2512
|
if (Date.now() - requestTokenEndTime > reqTokenTimeInterval) {
|
2511
|
-
refreshTokenRequst(jumpCallback, InnerAuthorization
|
2513
|
+
refreshTokenRequst(jumpCallback, InnerAuthorization, {
|
2514
|
+
refreshTokenCallback: refreshTokenCallback,
|
2515
|
+
});
|
2512
2516
|
}
|
2513
2517
|
else {
|
2514
|
-
message.info(
|
2518
|
+
message.info(instance.t('刷新token遭到频繁调用,请联系管理员查看是否接口权限出现问题,可能是{{slot0}}接口出现问题', { slot0: response === null || response === void 0 ? void 0 : response.config.url }), 5);
|
2515
2519
|
requestTokenEndTime = 0;
|
2516
2520
|
}
|
2517
2521
|
}
|
@@ -2545,7 +2549,8 @@ function checkStatus(response, jumpCallback, otherOptions) {
|
|
2545
2549
|
// return retryOriginalRequest;
|
2546
2550
|
}
|
2547
2551
|
}
|
2548
|
-
function refreshTokenRequst(jumpCallback, Authorization) {
|
2552
|
+
function refreshTokenRequst(jumpCallback, Authorization, otherOptions) {
|
2553
|
+
var refreshTokenCallback = (otherOptions || {}).refreshTokenCallback;
|
2549
2554
|
loginRequest({
|
2550
2555
|
tenantId: '000000',
|
2551
2556
|
grant_type: 'refresh_token',
|
@@ -2559,7 +2564,11 @@ function refreshTokenRequst(jumpCallback, Authorization) {
|
|
2559
2564
|
// 刷新成功 重置token 重置refresh-token
|
2560
2565
|
setToken(data === null || data === void 0 ? void 0 : data.access_token);
|
2561
2566
|
setRefreshToken(data === null || data === void 0 ? void 0 : data.refresh_token);
|
2567
|
+
message.info(instance.t('token已经刷新成功,请重新提交!', {}));
|
2568
|
+
// 设置一个本地存储,用来告知这是刷新token 而不是被挤下线。
|
2569
|
+
localStorage.setItem('__unWsNeedReconnect__', 'true');
|
2562
2570
|
onAccessTokenFetched();
|
2571
|
+
refreshTokenCallback === null || refreshTokenCallback === void 0 ? void 0 : refreshTokenCallback();
|
2563
2572
|
isRefreshing = true;
|
2564
2573
|
}
|
2565
2574
|
else {
|
@@ -2572,7 +2581,7 @@ function refreshTokenRequst(jumpCallback, Authorization) {
|
|
2572
2581
|
jumpCallback(401);
|
2573
2582
|
}
|
2574
2583
|
else {
|
2575
|
-
message.info(
|
2584
|
+
message.info(instance.t('登录过期!', {}), 3.5, function () {
|
2576
2585
|
isExpiration = false;
|
2577
2586
|
});
|
2578
2587
|
window.location.href = '/login';
|
@@ -2588,7 +2597,7 @@ function refreshTokenRequst(jumpCallback, Authorization) {
|
|
2588
2597
|
jumpCallback(401);
|
2589
2598
|
}
|
2590
2599
|
else {
|
2591
|
-
message.info(
|
2600
|
+
message.info(instance.t('登录过期!', {}), 3.5, function () {
|
2592
2601
|
isExpiration = false;
|
2593
2602
|
});
|
2594
2603
|
window.location.href = '/login';
|
@@ -2605,7 +2614,7 @@ function onAccessTokenFetched() {
|
|
2605
2614
|
}
|
2606
2615
|
function setInterceptorsResponse(jumpCallback, otherOptions) {
|
2607
2616
|
// 拦截器,拦截响应头信息
|
2608
|
-
var
|
2617
|
+
var _a = otherOptions || {}, isRefreshToken = _a.isRefreshToken; _a.refreshTokenCallback;
|
2609
2618
|
axios.interceptors.response.use(function (response) {
|
2610
2619
|
var _a, _b, _c;
|
2611
2620
|
// catchPromiseObj = [];
|
@@ -2633,7 +2642,7 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
|
|
2633
2642
|
return Promise.reject(response);
|
2634
2643
|
}
|
2635
2644
|
}, function (error) {
|
2636
|
-
var _a, _b, _c, _d, _e;
|
2645
|
+
var _a, _b, _c, _d, _e, _f;
|
2637
2646
|
// catchPromiseObj = [];
|
2638
2647
|
console.error(error);
|
2639
2648
|
var errRes = error === null || error === void 0 ? void 0 : error.response;
|
@@ -2647,19 +2656,28 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
|
|
2647
2656
|
params: error === null || error === void 0 ? void 0 : error.config.params,
|
2648
2657
|
});
|
2649
2658
|
});
|
2659
|
+
/** 如果接口出错了,清理掉这个错误的接口缓存 */
|
2660
|
+
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);
|
2661
|
+
if (autonomousCatchingPromiseObj[autonomousCatchingKey]) {
|
2662
|
+
autonomousCatchingPromiseObj[autonomousCatchingKey] = undefined;
|
2663
|
+
}
|
2650
2664
|
if (item !== -1) {
|
2651
2665
|
catchPromiseObj.splice(item, 1);
|
2652
2666
|
}
|
2653
|
-
console.log(error
|
2667
|
+
// console.log(error?.config, catchPromiseObj);
|
2654
2668
|
/** 如果接口出错了,那么清理掉这个错误的接口 */
|
2655
2669
|
// 超时异常统一处理,超时的异常没有response值,只能通过toString处理
|
2656
2670
|
if (!errRes && error.toString().indexOf(timeoutNum + "ms") !== -1) {
|
2657
2671
|
if (!isMessage) {
|
2658
|
-
if (((
|
2672
|
+
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' &&
|
2659
2673
|
__isTimeoutMessage) {
|
2660
2674
|
isMessage = true;
|
2661
2675
|
Modal.confirm({
|
2662
|
-
title:
|
2676
|
+
title: instance.t('请求超时,请稍后再试,请去列表确认数据是否插入成功,请勿重复提交! 接口地址:{{slot0}} 请求方式:{{slot1}} 请求超时时间:{{slot2}}', {
|
2677
|
+
slot0: (_d = error === null || error === void 0 ? void 0 : error.config) === null || _d === void 0 ? void 0 : _d.url,
|
2678
|
+
slot1: (_e = error === null || error === void 0 ? void 0 : error.config) === null || _e === void 0 ? void 0 : _e.method,
|
2679
|
+
slot2: (_f = error === null || error === void 0 ? void 0 : error.config) === null || _f === void 0 ? void 0 : _f.timeout,
|
2680
|
+
}),
|
2663
2681
|
okCancel: false,
|
2664
2682
|
onOk: function () {
|
2665
2683
|
isMessage = false;
|
@@ -2673,7 +2691,7 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
|
|
2673
2691
|
if ((errRes === null || errRes === void 0 ? void 0 : errRes.status) === 404) {
|
2674
2692
|
if (!isNotFound) {
|
2675
2693
|
isNotFound = true;
|
2676
|
-
message.info(
|
2694
|
+
message.info(instance.t('接口: {{slot0}} 未找到!', { slot0: errRes.config.url }), 3.5, function () {
|
2677
2695
|
isNotFound = false;
|
2678
2696
|
});
|
2679
2697
|
}
|
@@ -2689,7 +2707,7 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
|
|
2689
2707
|
jumpCallback(errRes === null || errRes === void 0 ? void 0 : errRes.status);
|
2690
2708
|
}
|
2691
2709
|
else {
|
2692
|
-
message.info(
|
2710
|
+
message.info(instance.t('你的账号已在其他地方登录!', {}), 3.5, function () {
|
2693
2711
|
isOffSite = false;
|
2694
2712
|
});
|
2695
2713
|
window.location.href = '/login';
|
@@ -2707,7 +2725,7 @@ function setInterceptorsResponse(jumpCallback, otherOptions) {
|
|
2707
2725
|
jumpCallback(errRes === null || errRes === void 0 ? void 0 : errRes.status);
|
2708
2726
|
}
|
2709
2727
|
else {
|
2710
|
-
message.info(
|
2728
|
+
message.info(instance.t('登录过期!', {}), 3.5, function () {
|
2711
2729
|
isExpiration = false;
|
2712
2730
|
});
|
2713
2731
|
window.location.href = '/login';
|
@@ -2766,14 +2784,14 @@ function transformObj(obj) {
|
|
2766
2784
|
return obj;
|
2767
2785
|
}
|
2768
2786
|
function request(myOptions, jumpCallback, otherOptions) {
|
2769
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
2787
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
2770
2788
|
var InnerAuthorization = (otherOptions || {}).InnerAuthorization;
|
2771
2789
|
if (!isFirstSet) {
|
2772
2790
|
setInterceptorsRequest();
|
2773
2791
|
setInterceptorsResponse(jumpCallback, otherOptions);
|
2774
2792
|
isFirstSet = true;
|
2775
2793
|
}
|
2776
|
-
var encryptionType = myOptions.encryptionType, isTimeoutMessage = myOptions.isTimeoutMessage, isForceRequest = myOptions.isForceRequest,
|
2794
|
+
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"]);
|
2777
2795
|
timeoutNum =
|
2778
2796
|
typeof myOptions.timeout === 'number' ? myOptions.timeout : timeoutNum;
|
2779
2797
|
__isTimeoutMessage = isTimeoutMessage;
|
@@ -2787,6 +2805,8 @@ function request(myOptions, jumpCallback, otherOptions) {
|
|
2787
2805
|
'Zmdms-Auth': "bearer " + token,
|
2788
2806
|
'Tenant-Id': '000000',
|
2789
2807
|
Authorization: InnerAuthorization ? InnerAuthorization : Authorization,
|
2808
|
+
// 设置语言包请求头
|
2809
|
+
'Zmdms-Lang': window.localStorage.getItem('languageType') || 'zh_CN',
|
2790
2810
|
},
|
2791
2811
|
};
|
2792
2812
|
if ((_a = options.baseURL) === null || _a === void 0 ? void 0 : _a.endsWith('/')) {
|
@@ -2805,7 +2825,7 @@ function request(myOptions, jumpCallback, otherOptions) {
|
|
2805
2825
|
options.params = transformObj(options.params);
|
2806
2826
|
}
|
2807
2827
|
// 将传入配置与默认配置混合
|
2808
|
-
var newOptions = __assign(__assign(__assign({}, defaultOptions), options), { headers: __assign(__assign({}, defaultOptions.headers), options.headers) });
|
2828
|
+
var newOptions = __assign(__assign(__assign({}, defaultOptions), options), { autonomousKey: autonomousKey, headers: __assign(__assign({}, defaultOptions.headers), options.headers) });
|
2809
2829
|
// 特殊请求处理
|
2810
2830
|
if (((_e = newOptions.method) === null || _e === void 0 ? void 0 : _e.toUpperCase()) === 'POST' ||
|
2811
2831
|
((_f = newOptions.method) === null || _f === void 0 ? void 0 : _f.toUpperCase()) === 'PUT' ||
|
@@ -2849,13 +2869,64 @@ function request(myOptions, jumpCallback, otherOptions) {
|
|
2849
2869
|
};
|
2850
2870
|
}
|
2851
2871
|
}
|
2872
|
+
// 自主缓存请求。默认这个缓存只会针对一个url缓存一次请求
|
2873
|
+
if (isAutonomousCatch) {
|
2874
|
+
var autonomousCatchingKey = autonomousKey || newOptions.url;
|
2875
|
+
var item = autonomousCatchingPromiseObj[autonomousCatchingKey];
|
2876
|
+
// 如果当前接口没有缓存 缓存住,并且返回接口结果
|
2877
|
+
if (!item || !Array.isArray(item)) {
|
2878
|
+
var result = axios(newOptions);
|
2879
|
+
autonomousCatchingPromiseObj[autonomousCatchingKey] = [
|
2880
|
+
{
|
2881
|
+
params: newOptions.params,
|
2882
|
+
promiseObj: result,
|
2883
|
+
method: (_h = newOptions.method) === null || _h === void 0 ? void 0 : _h.toUpperCase(),
|
2884
|
+
},
|
2885
|
+
];
|
2886
|
+
return result;
|
2887
|
+
}
|
2888
|
+
// 如果当前接口有缓存
|
2889
|
+
// 判断当前参数是否命中
|
2890
|
+
var index = item.findIndex(function (itemChild) {
|
2891
|
+
var _a, _b;
|
2892
|
+
return isEqual_1({
|
2893
|
+
method: (_a = itemChild.method) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
|
2894
|
+
params: itemChild.params,
|
2895
|
+
}, {
|
2896
|
+
method: (_b = newOptions.method) === null || _b === void 0 ? void 0 : _b.toUpperCase(),
|
2897
|
+
params: newOptions.params,
|
2898
|
+
});
|
2899
|
+
});
|
2900
|
+
// 如果缓存命中
|
2901
|
+
if (index !== -1) {
|
2902
|
+
// 最近使用优先
|
2903
|
+
var result = item[index];
|
2904
|
+
item.splice(index, 1);
|
2905
|
+
item.push(result);
|
2906
|
+
return result === null || result === void 0 ? void 0 : result.promiseObj;
|
2907
|
+
}
|
2908
|
+
else {
|
2909
|
+
var result = axios(newOptions);
|
2910
|
+
// 当前接口可以缓存几个结果 如果超过最大缓存数量 删除第一位
|
2911
|
+
if (item.length >= autonomousCount) {
|
2912
|
+
item.shift();
|
2913
|
+
}
|
2914
|
+
item.push({
|
2915
|
+
params: newOptions.params,
|
2916
|
+
promiseObj: result,
|
2917
|
+
method: (_j = newOptions.method) === null || _j === void 0 ? void 0 : _j.toUpperCase(),
|
2918
|
+
});
|
2919
|
+
return result;
|
2920
|
+
}
|
2921
|
+
}
|
2852
2922
|
// 缓存本次宏任务下的GET请求,并且不是以/page结尾的列表分页接口
|
2853
2923
|
// 并且不是强制请求,强制请求需要
|
2854
|
-
if ((((
|
2855
|
-
!((
|
2924
|
+
if (((((_k = newOptions.method) === null || _k === void 0 ? void 0 : _k.toUpperCase()) === 'GET' &&
|
2925
|
+
!((_l = newOptions.url) === null || _l === void 0 ? void 0 : _l.endsWith('/page')) &&
|
2856
2926
|
!noCatchUrl.find(function (item) { var _a; return (_a = newOptions.url) === null || _a === void 0 ? void 0 : _a.endsWith(item); }) &&
|
2857
2927
|
isCatch) ||
|
2858
|
-
mustCatch)
|
2928
|
+
mustCatch) &&
|
2929
|
+
!isAutonomousCatch) {
|
2859
2930
|
// 能不能找到,url与参数都一样得数据
|
2860
2931
|
var index = catchPromiseObj.findIndex(function (item) {
|
2861
2932
|
return isEqual_1({
|
@@ -2899,6 +2970,9 @@ function clearNoCompleteRequest() {
|
|
2899
2970
|
}
|
2900
2971
|
function clearCatch() {
|
2901
2972
|
catchPromiseObj = [];
|
2973
|
+
}
|
2974
|
+
function clearAutonomousCatch(url) {
|
2975
|
+
autonomousCatchingPromiseObj[url] = undefined;
|
2902
2976
|
}
|
2903
2977
|
|
2904
2978
|
var request$1 = /*#__PURE__*/Object.freeze({
|
@@ -2907,7 +2981,8 @@ var request$1 = /*#__PURE__*/Object.freeze({
|
|
2907
2981
|
NEW_AUTHORIZATION: NEW_AUTHORIZATION,
|
2908
2982
|
'default': request,
|
2909
2983
|
clearNoCompleteRequest: clearNoCompleteRequest,
|
2910
|
-
clearCatch: clearCatch
|
2984
|
+
clearCatch: clearCatch,
|
2985
|
+
clearAutonomousCatch: clearAutonomousCatch
|
2911
2986
|
});
|
2912
2987
|
|
2913
|
-
export { NEW_AUTHORIZATION as N, OLD_AUTHORIZATION as O, request as a, clearCatch as b, clearNoCompleteRequest as c, request$1 as r };
|
2988
|
+
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
@@ -27,6 +27,10 @@ export interface IOptions extends AxiosRequestConfig {
|
|
27
27
|
* 自主缓存的key值,默认取url
|
28
28
|
*/
|
29
29
|
autonomousKey?: string;
|
30
|
+
/**
|
31
|
+
* 401时,是否需要刷新token
|
32
|
+
*/
|
33
|
+
isRefreshToken?: boolean;
|
30
34
|
}
|
31
35
|
export default function request(myOptions: IOptions, jumpCallback?: any, otherOptions?: any): any;
|
32
36
|
export declare function clearNoCompleteRequest(): void;
|
package/dist/request.js
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
import './tslib.es6-35653116.js';
|
2
|
+
import './i18next.js';
|
2
3
|
import 'axios';
|
3
4
|
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-
|
5
|
+
export { N as NEW_AUTHORIZATION, O as OLD_AUTHORIZATION, d as clearAutonomousCatch, b as clearCatch, c as clearNoCompleteRequest, a as default } from './request-3b358860.js';
|
5
6
|
import './authority-7a91cb9f.js';
|
6
7
|
import './crypto-c481f616.js';
|
7
8
|
import 'crypto';
|