ztxkutils 2.10.64 → 2.10.65

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.
@@ -1,7 +1,9 @@
1
1
  import { g as getToken } from './authority-7a91cb9f.js';
2
2
  import { d as dangerouslySetXss } from './tools-390e3466.js';
3
+ import { a as crypto } from './crypto-c481f616.js';
3
4
  import './tslib.es6-35653116.js';
4
5
  import 'dayjs';
6
+ import 'crypto';
5
7
 
6
8
  /**
7
9
  * @author cyx
@@ -187,6 +189,8 @@ function createPublicDownloadUrl(apiUrl, fileId) {
187
189
  * @param {string} fileName 文件名
188
190
  */
189
191
  function previewFile(fileUrl, fileId, otherOption) {
192
+ // 给附件id加密
193
+ fileId = crypto.encrypt_des(fileId);
190
194
  var token = '';
191
195
  if (typeof otherOption === 'object') {
192
196
  token = getToken() || (otherOption === null || otherOption === void 0 ? void 0 : otherOption.authToken);
@@ -225,6 +229,8 @@ function previewFile(fileUrl, fileId, otherOption) {
225
229
  * @param {string} fileName 文件名
226
230
  */
227
231
  function batchPreviewFile(fileUrl, fileId, otherOption) {
232
+ // 给附件id加密
233
+ fileId = crypto.encrypt_des(fileId);
228
234
  var token = '';
229
235
  if (typeof otherOption === 'object') {
230
236
  token = getToken() || (otherOption === null || otherOption === void 0 ? void 0 : otherOption.authToken);
package/dist/hooks.js CHANGED
@@ -7,6 +7,8 @@ import './fileOperation.js';
7
7
  import './authority-7a91cb9f.js';
8
8
  import './tools-390e3466.js';
9
9
  import 'dayjs';
10
+ import './crypto-c481f616.js';
11
+ import 'crypto';
10
12
 
11
13
  function useTableLinkage(_a) {
12
14
  var records = _a.records, callbackPromise = _a.callbackPromise, dependencies = _a.dependencies, devDependencies = _a.devDependencies;
package/dist/print.d.ts CHANGED
@@ -31,7 +31,7 @@ export declare function htmlToPdf({ pageClassName, dom, pdfName, isShowPage, noW
31
31
  imgPositionX?: number;
32
32
  waterText?: string;
33
33
  }): Promise<jsPDF>;
34
- export declare function htmlToPdfUseCanvas({ pageClassName, dom, pdfName, isShowPage, isOnlyOne, noWater, pdfOptions, imgPositionX, isDownload, }: {
34
+ export declare function htmlToPdfUseCanvas({ pageClassName, dom, pdfName, isShowPage, isOnlyOne, noWater, pdfOptions, imgPositionX, isDownload, isAutoPageCount, }: {
35
35
  pageClassName?: string;
36
36
  dom: HTMLElement;
37
37
  pdfName: string;
@@ -41,6 +41,7 @@ export declare function htmlToPdfUseCanvas({ pageClassName, dom, pdfName, isShow
41
41
  pdfOptions?: any;
42
42
  imgPositionX?: number;
43
43
  isDownload?: boolean;
44
+ isAutoPageCount?: boolean;
44
45
  }): Promise<{
45
46
  pdfs: any;
46
47
  pdfBase64: any;
package/dist/print.js CHANGED
@@ -232,7 +232,7 @@ function htmlToPdf(_a) {
232
232
  }
233
233
  }
234
234
  function htmlToPdfUseCanvas(_a) {
235
- var pageClassName = _a.pageClassName, dom = _a.dom, pdfName = _a.pdfName, isShowPage = _a.isShowPage, isOnlyOne = _a.isOnlyOne, noWater = _a.noWater, pdfOptions = _a.pdfOptions, imgPositionX = _a.imgPositionX, isDownload = _a.isDownload;
235
+ var pageClassName = _a.pageClassName, dom = _a.dom, pdfName = _a.pdfName, isShowPage = _a.isShowPage, isOnlyOne = _a.isOnlyOne, noWater = _a.noWater, pdfOptions = _a.pdfOptions, imgPositionX = _a.imgPositionX, isDownload = _a.isDownload; _a.isAutoPageCount;
236
236
  var allDom = document.querySelectorAll(pageClassName ? pageClassName : '.html2canvas-container-page');
237
237
  var format = (pdfOptions === null || pdfOptions === void 0 ? void 0 : pdfOptions.format) || [632.28, 841.89];
238
238
  var _pdfOptions = __assign({ unit: 'pt', format: format }, (pdfOptions || {}));
@@ -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 };
@@ -4,6 +4,8 @@ import './authority-7a91cb9f.js';
4
4
  import './tools-390e3466.js';
5
5
  import './tslib.es6-35653116.js';
6
6
  import 'dayjs';
7
+ import './crypto-c481f616.js';
8
+ import 'crypto';
7
9
 
8
10
  /**
9
11
  * 图片附件id转base64字符串
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "2.10.64",
3
+ "version": "2.10.65",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -1,423 +0,0 @@
1
- /**
2
- * base64.ts
3
- *
4
- * Licensed under the BSD 3-Clause License.
5
- * http://opensource.org/licenses/BSD-3-Clause
6
- *
7
- * References:
8
- * http://en.wikipedia.org/wiki/Base64
9
- *
10
- * @author Dan Kogai (https://github.com/dankogai)
11
- */
12
- const _hasatob = typeof atob === 'function';
13
- const _hasbtoa = typeof btoa === 'function';
14
- const _hasBuffer = typeof Buffer === 'function';
15
- const _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined;
16
- const _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;
17
- const b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
18
- const b64chs = [...b64ch];
19
- const b64tab = ((a) => {
20
- let tab = {};
21
- a.forEach((c, i) => tab[c] = i);
22
- return tab;
23
- })(b64chs);
24
- const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
25
- const _fromCC = String.fromCharCode.bind(String);
26
- const _U8Afrom = typeof Uint8Array.from === 'function'
27
- ? Uint8Array.from.bind(Uint8Array)
28
- : (it, fn = (x) => x) => new Uint8Array(Array.prototype.slice.call(it, 0).map(fn));
29
- const _mkUriSafe = (src) => src
30
- .replace(/[+\/]/g, (m0) => m0 == '+' ? '-' : '_')
31
- .replace(/=+$/m, '');
32
- const _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, '');
33
- /**
34
- * polyfill version of `btoa`
35
- */
36
- const btoaPolyfill = (bin) => {
37
- // console.log('polyfilled');
38
- let u32, c0, c1, c2, asc = '';
39
- const pad = bin.length % 3;
40
- for (let i = 0; i < bin.length;) {
41
- if ((c0 = bin.charCodeAt(i++)) > 255 ||
42
- (c1 = bin.charCodeAt(i++)) > 255 ||
43
- (c2 = bin.charCodeAt(i++)) > 255)
44
- throw new TypeError('invalid character found');
45
- u32 = (c0 << 16) | (c1 << 8) | c2;
46
- asc += b64chs[u32 >> 18 & 63]
47
- + b64chs[u32 >> 12 & 63]
48
- + b64chs[u32 >> 6 & 63]
49
- + b64chs[u32 & 63];
50
- }
51
- return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc;
52
- };
53
- /**
54
- * does what `window.btoa` of web browsers do.
55
- * @param {String} bin binary string
56
- * @returns {string} Base64-encoded string
57
- */
58
- const _btoa = _hasbtoa ? (bin) => btoa(bin)
59
- : _hasBuffer ? (bin) => Buffer.from(bin, 'binary').toString('base64')
60
- : btoaPolyfill;
61
- const _fromUint8Array = _hasBuffer
62
- ? (u8a) => Buffer.from(u8a).toString('base64')
63
- : (u8a) => {
64
- // cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
65
- const maxargs = 0x1000;
66
- let strs = [];
67
- for (let i = 0, l = u8a.length; i < l; i += maxargs) {
68
- strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
69
- }
70
- return _btoa(strs.join(''));
71
- };
72
- // This trick is found broken https://github.com/dankogai/js-base64/issues/130
73
- // const utob = (src: string) => unescape(encodeURIComponent(src));
74
- // reverting good old fationed regexp
75
- const cb_utob = (c) => {
76
- if (c.length < 2) {
77
- var cc = c.charCodeAt(0);
78
- return cc < 0x80 ? c
79
- : cc < 0x800 ? (_fromCC(0xc0 | (cc >>> 6))
80
- + _fromCC(0x80 | (cc & 0x3f)))
81
- : (_fromCC(0xe0 | ((cc >>> 12) & 0x0f))
82
- + _fromCC(0x80 | ((cc >>> 6) & 0x3f))
83
- + _fromCC(0x80 | (cc & 0x3f)));
84
- }
85
- else {
86
- var cc = 0x10000
87
- + (c.charCodeAt(0) - 0xD800) * 0x400
88
- + (c.charCodeAt(1) - 0xDC00);
89
- return (_fromCC(0xf0 | ((cc >>> 18) & 0x07))
90
- + _fromCC(0x80 | ((cc >>> 12) & 0x3f))
91
- + _fromCC(0x80 | ((cc >>> 6) & 0x3f))
92
- + _fromCC(0x80 | (cc & 0x3f)));
93
- }
94
- };
95
- const re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
96
- /**
97
- * @deprecated should have been internal use only.
98
- * @param {string} src UTF-8 string
99
- * @returns {string} UTF-16 string
100
- */
101
- const utob = (u) => u.replace(re_utob, cb_utob);
102
- //
103
- const _encode = _hasBuffer
104
- ? (s) => Buffer.from(s, 'utf8').toString('base64')
105
- : _TE
106
- ? (s) => _fromUint8Array(_TE.encode(s))
107
- : (s) => _btoa(utob(s));
108
- /**
109
- * converts a UTF-8-encoded string to a Base64 string.
110
- * @param {boolean} [urlsafe] if `true` make the result URL-safe
111
- * @returns {string} Base64 string
112
- */
113
- const encode = (src, urlsafe = false) => urlsafe
114
- ? _mkUriSafe(_encode(src))
115
- : _encode(src);
116
- // This trick is found broken https://github.com/dankogai/js-base64/issues/130
117
- // const btou = (src: string) => decodeURIComponent(escape(src));
118
- // reverting good old fationed regexp
119
- const re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
120
- const cb_btou = (cccc) => {
121
- switch (cccc.length) {
122
- case 4:
123
- var cp = ((0x07 & cccc.charCodeAt(0)) << 18)
124
- | ((0x3f & cccc.charCodeAt(1)) << 12)
125
- | ((0x3f & cccc.charCodeAt(2)) << 6)
126
- | (0x3f & cccc.charCodeAt(3)), offset = cp - 0x10000;
127
- return (_fromCC((offset >>> 10) + 0xD800)
128
- + _fromCC((offset & 0x3FF) + 0xDC00));
129
- case 3:
130
- return _fromCC(((0x0f & cccc.charCodeAt(0)) << 12)
131
- | ((0x3f & cccc.charCodeAt(1)) << 6)
132
- | (0x3f & cccc.charCodeAt(2)));
133
- default:
134
- return _fromCC(((0x1f & cccc.charCodeAt(0)) << 6)
135
- | (0x3f & cccc.charCodeAt(1)));
136
- }
137
- };
138
- /**
139
- * @deprecated should have been internal use only.
140
- * @param {string} src UTF-16 string
141
- * @returns {string} UTF-8 string
142
- */
143
- const btou = (b) => b.replace(re_btou, cb_btou);
144
- /**
145
- * polyfill version of `atob`
146
- */
147
- const atobPolyfill = (asc) => {
148
- // console.log('polyfilled');
149
- asc = asc.replace(/\s+/g, '');
150
- if (!b64re.test(asc))
151
- throw new TypeError('malformed base64.');
152
- asc += '=='.slice(2 - (asc.length & 3));
153
- let u24, bin = '', r1, r2;
154
- for (let i = 0; i < asc.length;) {
155
- u24 = b64tab[asc.charAt(i++)] << 18
156
- | b64tab[asc.charAt(i++)] << 12
157
- | (r1 = b64tab[asc.charAt(i++)]) << 6
158
- | (r2 = b64tab[asc.charAt(i++)]);
159
- bin += r1 === 64 ? _fromCC(u24 >> 16 & 255)
160
- : r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255)
161
- : _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255);
162
- }
163
- return bin;
164
- };
165
- /**
166
- * does what `window.atob` of web browsers do.
167
- * @param {String} asc Base64-encoded string
168
- * @returns {string} binary string
169
- */
170
- const _atob = _hasatob ? (asc) => atob(_tidyB64(asc))
171
- : _hasBuffer ? (asc) => Buffer.from(asc, 'base64').toString('binary')
172
- : atobPolyfill;
173
- //
174
- const _toUint8Array = _hasBuffer
175
- ? (a) => _U8Afrom(Buffer.from(a, 'base64'))
176
- : (a) => _U8Afrom(_atob(a), c => c.charCodeAt(0));
177
- //
178
- const _decode = _hasBuffer
179
- ? (a) => Buffer.from(a, 'base64').toString('utf8')
180
- : _TD
181
- ? (a) => _TD.decode(_toUint8Array(a))
182
- : (a) => btou(_atob(a));
183
- const _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == '-' ? '+' : '/'));
184
- /**
185
- * converts a Base64 string to a UTF-8 string.
186
- * @param {String} src Base64 string. Both normal and URL-safe are supported
187
- * @returns {string} UTF-8 string
188
- */
189
- const decode = (src) => _decode(_unURI(src));
190
-
191
- function e(e){this.message=e;}e.prototype=new Error,e.prototype.name="InvalidCharacterError";var r="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(r){var t=String(r).replace(/=+$/,"");if(t.length%4==1)throw new e("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,a=0,i=0,c="";o=t.charAt(i++);~o&&(n=a%4?64*n+o:o,a++%4)?c+=String.fromCharCode(255&n>>(-2*a&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return c};function t(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw "Illegal base64url string!"}try{return function(e){return decodeURIComponent(r(e).replace(/(.)/g,(function(e,r){var t=r.charCodeAt(0).toString(16).toUpperCase();return t.length<2&&(t="0"+t),"%"+t})))}(t)}catch(e){return r(t)}}function n(e){this.message=e;}function o(e,r){if("string"!=typeof e)throw new n("Invalid token specified");var o=!0===(r=r||{}).header?0:1;try{return JSON.parse(t(e.split(".")[o]))}catch(e){throw new n("Invalid token specified: "+e.message)}}n.prototype=new Error,n.prototype.name="InvalidTokenError";
192
-
193
- /**
194
- * @description 权限相关操作
195
- */
196
- // 获取token
197
- var getToken = function () {
198
- try {
199
- if (window.localStorage.getItem('system-token')) {
200
- return window.localStorage.getItem('system-token');
201
- }
202
- else {
203
- return false;
204
- }
205
- }
206
- catch (err) {
207
- return false;
208
- }
209
- };
210
- // 获取refreshToken
211
- var getRefreshToken = function () {
212
- try {
213
- if (window.localStorage.getItem('system-refresh-token')) {
214
- return window.localStorage.getItem('system-refresh-token');
215
- }
216
- else {
217
- return false;
218
- }
219
- }
220
- catch (err) {
221
- return false;
222
- }
223
- };
224
- // 获取是否第三方登录
225
- var getOAuth2 = function () {
226
- try {
227
- if (window.localStorage.getItem('system-oauth2')) {
228
- return window.localStorage.getItem('system-oauth2');
229
- }
230
- else {
231
- return false;
232
- }
233
- }
234
- catch (err) {
235
- return false;
236
- }
237
- };
238
- // 设置token
239
- var setToken = function (token) {
240
- try {
241
- window.localStorage.setItem('system-token', token);
242
- }
243
- catch (err) {
244
- return false;
245
- }
246
- };
247
- var removeToken = function () {
248
- try {
249
- window.localStorage.removeItem('system-token');
250
- }
251
- catch (err) {
252
- return false;
253
- }
254
- };
255
- // 设置refreshToken
256
- var setRefreshToken = function (token) {
257
- try {
258
- window.localStorage.setItem('system-refresh-token', token);
259
- }
260
- catch (err) {
261
- return false;
262
- }
263
- };
264
- var removeRefreshToken = function () {
265
- try {
266
- window.localStorage.removeItem('system-refresh-token');
267
- }
268
- catch (err) {
269
- return false;
270
- }
271
- };
272
- // 设置第三方登录
273
- var setOAuth2 = function () {
274
- try {
275
- window.localStorage.setItem('system-oauth2', '1');
276
- }
277
- catch (err) {
278
- return false;
279
- }
280
- };
281
- var removeOAuth2 = function () {
282
- try {
283
- window.localStorage.removeItem('system-oauth2');
284
- }
285
- catch (err) {
286
- return false;
287
- }
288
- };
289
- // 对用户名密码进行加密/解密处理
290
- var aesEncrypt = function (str) {
291
- return encode(str);
292
- };
293
- var aesDecrypt = function (str) {
294
- if (str) {
295
- return decode(str);
296
- }
297
- else {
298
- return str;
299
- }
300
- };
301
- /**按钮权限级别 */
302
- var BTN_AUTHS = {
303
- add: 'add',
304
- update: 'update',
305
- check: 'check',
306
- detail: 'detail',
307
- unfreeze: 'unfreeze',
308
- frozen: 'frozen',
309
- cancelLation: 'cancelLation',
310
- cancelSubmit: 'cancelSubmit',
311
- submitApprove: 'submitApprove', // 提交审核
312
- };
313
- /**判断是否有当前按钮的权限 */
314
- var isBtnAuth = function (userBtns, code) {
315
- if (typeof code === 'boolean') {
316
- return code;
317
- }
318
- if (!Array.isArray(userBtns)) {
319
- return false;
320
- }
321
- return userBtns.some(function (userBtn) { return (userBtn === null || userBtn === void 0 ? void 0 : userBtn.code) === code; });
322
- };
323
- /**设置最后一次访问的路由 */
324
- var setLastUrlPath = function (pathname) {
325
- try {
326
- window.localStorage.setItem('last-url-path', pathname);
327
- }
328
- catch (err) {
329
- return false;
330
- }
331
- };
332
- var getLastUrlPath = function () {
333
- try {
334
- if (window.localStorage.getItem('last-url-path')) {
335
- return window.localStorage.getItem('last-url-path');
336
- }
337
- else {
338
- return false;
339
- }
340
- }
341
- catch (err) {
342
- return false;
343
- }
344
- };
345
- /**返回是否在乾坤下启动 */
346
- var isQiankun = function () { return window.__POWERED_BY_QIANKUN__; };
347
- /** jwt解析 */
348
- var jwtDecode = function (str) {
349
- try {
350
- return o(str);
351
- }
352
- catch (err) {
353
- //
354
- }
355
- };
356
- /**
357
- * 设置菜单id
358
- * menuId: 菜单id
359
- * menuPath:菜单对应的路由
360
- */
361
- var setMenuId = function (menuId, menuPath) {
362
- try {
363
- window.sessionStorage.setItem('CURRENT_MENU_ID', menuId);
364
- window.sessionStorage.setItem('CURRENT_MENU_PATH', menuPath);
365
- }
366
- catch (err) {
367
- //
368
- }
369
- };
370
- var getMenuIdInfo = function () {
371
- var _a, _b, _c;
372
- var obj = {};
373
- try {
374
- var pathname = window.location.pathname;
375
- obj.CURRENT_MENU_ID = window.sessionStorage.getItem('CURRENT_MENU_ID');
376
- obj.CURRENT_MENU_PATH = window.sessionStorage.getItem('CURRENT_MENU_PATH');
377
- if (pathname === obj.CURRENT_MENU_PATH) {
378
- obj.IS_CURRENT_MENU = true;
379
- }
380
- else {
381
- var firstIndex = (_b = (_a = obj.CURRENT_MENU_PATH) === null || _a === void 0 ? void 0 : _a.indexOf) === null || _b === void 0 ? void 0 : _b.call(_a, ':');
382
- var resultPathname = obj.CURRENT_MENU_PATH;
383
- if (firstIndex !== -1) {
384
- resultPathname = (_c = obj.CURRENT_MENU_PATH) === null || _c === void 0 ? void 0 : _c.substr(0, firstIndex);
385
- }
386
- if (pathname.indexOf(resultPathname) !== -1) {
387
- obj.IS_CURRENT_MENU = true;
388
- }
389
- else {
390
- obj.IS_CURRENT_MENU = false;
391
- }
392
- }
393
- }
394
- catch (err) {
395
- //
396
- }
397
- return obj;
398
- };
399
-
400
- var authority = /*#__PURE__*/Object.freeze({
401
- __proto__: null,
402
- getToken: getToken,
403
- getRefreshToken: getRefreshToken,
404
- getOAuth2: getOAuth2,
405
- setToken: setToken,
406
- removeToken: removeToken,
407
- setRefreshToken: setRefreshToken,
408
- removeRefreshToken: removeRefreshToken,
409
- setOAuth2: setOAuth2,
410
- removeOAuth2: removeOAuth2,
411
- aesEncrypt: aesEncrypt,
412
- aesDecrypt: aesDecrypt,
413
- BTN_AUTHS: BTN_AUTHS,
414
- isBtnAuth: isBtnAuth,
415
- setLastUrlPath: setLastUrlPath,
416
- getLastUrlPath: getLastUrlPath,
417
- isQiankun: isQiankun,
418
- jwtDecode: jwtDecode,
419
- setMenuId: setMenuId,
420
- getMenuIdInfo: getMenuIdInfo
421
- });
422
-
423
- export { BTN_AUTHS as B, getRefreshToken as a, setRefreshToken as b, authority as c, getOAuth2 as d, removeRefreshToken as e, setOAuth2 as f, getToken as g, removeOAuth2 as h, isQiankun as i, aesEncrypt as j, aesDecrypt as k, isBtnAuth as l, setLastUrlPath as m, getLastUrlPath as n, jwtDecode as o, setMenuId as p, getMenuIdInfo as q, removeToken as r, setToken as s };