tools-min-ns 1.18.8 → 1.18.10

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/README.md CHANGED
@@ -5,6 +5,8 @@ pnpm i tools-min-ns --save
5
5
  ```
6
6
 
7
7
  # updates
8
+ ## v1.18.9/10
9
+ fix: 修改RequestUtil.getAuthorization json排序问题
8
10
  ## v1.18.8
9
11
  fix: RequestUtil handleRequests并发请求优化
10
12
  ## v1.18.7
@@ -136,9 +136,11 @@ function exampleAsyncFunction() {
136
136
  /** POST请求参数 */
137
137
  data?: any;
138
138
  /** 前端传参方式(默认form)json => body; form=> query */
139
- requestType?: any;
139
+ requestType?: 'json' | 'form';
140
140
  /** 前端接受类型(默认json) */
141
- responseType?: any;
141
+ responseType?: 'json' | 'text' | 'blob' | 'arrayBuffer' | 'formData';
142
+ /** 打印 */
143
+ isLog: boolean;
142
144
  };
143
145
  export function getAuthorization(opt: RequestParam): string;
144
146
  export {};
@@ -156,6 +156,7 @@ import jsonpFn, { jsonpRquest as jsonpRquestFn } from './jsonp';
156
156
  import nsPromiseFn from './nsPromiseFn';
157
157
  import StringUtil from '../string/StringUtil';
158
158
  import PasswordUtil from '../pwd/PasswordUtil';
159
+ import DateUtil from '../date/DateUtil';
159
160
  var RequestUtil;
160
161
  (function (RequestUtil) {
161
162
  /** @name 浙里办请求工具设置默认请求头 */
@@ -368,31 +369,46 @@ var RequestUtil;
368
369
  */
369
370
  RequestUtil.nsPromise = nsPromiseFn;
370
371
  function getAuthorization(opt) {
372
+ var _a = opt.data,
373
+ data = _a === void 0 ? {} : _a,
374
+ url = opt.url,
375
+ _b = opt.requestType,
376
+ requestType = _b === void 0 ? 'form' : _b,
377
+ _c = opt.responseType,
378
+ responseType = _c === void 0 ? 'json' : _c,
379
+ _d = opt.isLog,
380
+ isLog = _d === void 0 ? false : _d;
371
381
  try {
372
382
  var uuid = StringUtil.getUuiD(16);
373
- var _a = opt.data,
374
- data_1 = _a === void 0 ? {} : _a,
375
- url = opt.url,
376
- _b = opt.requestType,
377
- requestType = _b === void 0 ? 'form' : _b,
378
- _c = opt.responseType,
379
- responseType = _c === void 0 ? 'json' : _c;
380
383
  var ts = new Date().getTime();
381
- var paramStr = JSON.stringify(data_1);
384
+ var paramStr = '{}';
382
385
  if (responseType === 'json') {
383
- if (requestType === 'form') {
386
+ if (['json', 'form'].includes(requestType)) {
384
387
  var _data_1 = {};
385
- var sortedKeys = Object.keys(data_1).sort(); // 对键进行排序
388
+ var sortedKeys = Object.keys(data).sort(function (a, b) {
389
+ return a.localeCompare(b);
390
+ }); // 对键进行排序
386
391
  sortedKeys.forEach(function (k) {
387
- if (!['null', 'undefined'].includes(String(data_1[k]))) _data_1[k] = String(data_1[k]);
392
+ if (!['null', 'undefined'].includes(String(data[k]))) _data_1[k] = requestType === 'json' ? data[k] : String(data[k]);
388
393
  });
389
394
  paramStr = JSON.stringify(_data_1);
390
395
  }
391
396
  }
392
397
  var str = url + paramStr + ts + uuid;
393
- return ts + PasswordUtil.str2MD5(str, uuid) + uuid;
398
+ if (isLog) console.info("[".concat(DateUtil.formatDate(), "]"), 'url + paramStr + ts + uuid ', {
399
+ url: url,
400
+ paramStr: paramStr,
401
+ ts: ts,
402
+ uuid: uuid
403
+ });
404
+ if (isLog) console.info("[".concat(DateUtil.formatDate(), "]"), '加密前 ', str);
405
+ var md5 = PasswordUtil.str2MD5(str, uuid);
406
+ if (isLog) console.info("[".concat(DateUtil.formatDate(), "]"), '加密后 ', md5);
407
+ var s = ts + md5 + uuid;
408
+ if (isLog) console.info("[".concat(DateUtil.formatDate(), "]"), '最终结果 ', s);
409
+ return s;
394
410
  } catch (error) {
395
- console.error(error);
411
+ if (isLog) console.error('getAuthorization error', error);
396
412
  return '';
397
413
  }
398
414
  }
@@ -136,9 +136,11 @@ function exampleAsyncFunction() {
136
136
  /** POST请求参数 */
137
137
  data?: any;
138
138
  /** 前端传参方式(默认form)json => body; form=> query */
139
- requestType?: any;
139
+ requestType?: 'json' | 'form';
140
140
  /** 前端接受类型(默认json) */
141
- responseType?: any;
141
+ responseType?: 'json' | 'text' | 'blob' | 'arrayBuffer' | 'formData';
142
+ /** 打印 */
143
+ isLog: boolean;
142
144
  };
143
145
  export function getAuthorization(opt: RequestParam): string;
144
146
  export {};
@@ -197,6 +197,7 @@ var jsonp_1 = __importStar(require("./jsonp"));
197
197
  var nsPromiseFn_1 = __importDefault(require("./nsPromiseFn"));
198
198
  var StringUtil_1 = __importDefault(require("../string/StringUtil"));
199
199
  var PasswordUtil_1 = __importDefault(require("../pwd/PasswordUtil"));
200
+ var DateUtil_1 = __importDefault(require("../date/DateUtil"));
200
201
  var RequestUtil;
201
202
  (function (RequestUtil) {
202
203
  /** @name 浙里办请求工具设置默认请求头 */
@@ -409,31 +410,46 @@ var RequestUtil;
409
410
  */
410
411
  RequestUtil.nsPromise = nsPromiseFn_1.default;
411
412
  function getAuthorization(opt) {
413
+ var _a = opt.data,
414
+ data = _a === void 0 ? {} : _a,
415
+ url = opt.url,
416
+ _b = opt.requestType,
417
+ requestType = _b === void 0 ? 'form' : _b,
418
+ _c = opt.responseType,
419
+ responseType = _c === void 0 ? 'json' : _c,
420
+ _d = opt.isLog,
421
+ isLog = _d === void 0 ? false : _d;
412
422
  try {
413
423
  var uuid = StringUtil_1.default.getUuiD(16);
414
- var _a = opt.data,
415
- data_1 = _a === void 0 ? {} : _a,
416
- url = opt.url,
417
- _b = opt.requestType,
418
- requestType = _b === void 0 ? 'form' : _b,
419
- _c = opt.responseType,
420
- responseType = _c === void 0 ? 'json' : _c;
421
424
  var ts = new Date().getTime();
422
- var paramStr = JSON.stringify(data_1);
425
+ var paramStr = '{}';
423
426
  if (responseType === 'json') {
424
- if (requestType === 'form') {
427
+ if (['json', 'form'].includes(requestType)) {
425
428
  var _data_1 = {};
426
- var sortedKeys = Object.keys(data_1).sort(); // 对键进行排序
429
+ var sortedKeys = Object.keys(data).sort(function (a, b) {
430
+ return a.localeCompare(b);
431
+ }); // 对键进行排序
427
432
  sortedKeys.forEach(function (k) {
428
- if (!['null', 'undefined'].includes(String(data_1[k]))) _data_1[k] = String(data_1[k]);
433
+ if (!['null', 'undefined'].includes(String(data[k]))) _data_1[k] = requestType === 'json' ? data[k] : String(data[k]);
429
434
  });
430
435
  paramStr = JSON.stringify(_data_1);
431
436
  }
432
437
  }
433
438
  var str = url + paramStr + ts + uuid;
434
- return ts + PasswordUtil_1.default.str2MD5(str, uuid) + uuid;
439
+ if (isLog) console.info("[".concat(DateUtil_1.default.formatDate(), "]"), 'url + paramStr + ts + uuid ', {
440
+ url: url,
441
+ paramStr: paramStr,
442
+ ts: ts,
443
+ uuid: uuid
444
+ });
445
+ if (isLog) console.info("[".concat(DateUtil_1.default.formatDate(), "]"), '加密前 ', str);
446
+ var md5 = PasswordUtil_1.default.str2MD5(str, uuid);
447
+ if (isLog) console.info("[".concat(DateUtil_1.default.formatDate(), "]"), '加密后 ', md5);
448
+ var s = ts + md5 + uuid;
449
+ if (isLog) console.info("[".concat(DateUtil_1.default.formatDate(), "]"), '最终结果 ', s);
450
+ return s;
435
451
  } catch (error) {
436
- console.error(error);
452
+ if (isLog) console.error('getAuthorization error', error);
437
453
  return '';
438
454
  }
439
455
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tools-min-ns",
3
3
  "description": "工具包适用于前端以及node",
4
- "version": "1.18.8",
4
+ "version": "1.18.10",
5
5
  "main": "lib/index.js",
6
6
  "license": "MIT",
7
7
  "author": "nanshen",