ls-pro-common 3.1.22 → 3.1.24

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.
@@ -71,4 +71,16 @@ export declare function getDict(dictCodes: string, showValue?: boolean, needGate
71
71
  */
72
72
  export declare function fetchOptions(url: string, param: any, valueField: string, labelField: string, showValue?: boolean, needGateWay?: boolean, timeout?: number, isGet?: boolean, valueIsNumber?: boolean): Promise<any>;
73
73
  export declare const checkResourceRight: (ids: string[]) => Promise<any>;
74
+ /**
75
+ * 分批获取数据,当一次性取大于2000条,且是第一页时,分多次去取,避免一次性取太多数据导致后端工程压力过大
76
+ *
77
+ * 注意:如果pageSize小于等于2000,或不是取第一页数据时,直接使用普通请求
78
+ *
79
+ * @param url
80
+ * @param params
81
+ * @param needGateWay
82
+ * @param timeout
83
+ * @returns
84
+ */
85
+ export declare const httpBatchGet: (url: string, params?: Record<string, any>, needGateWay?: boolean, timeout?: number) => Promise<any>;
74
86
  export default request;
package/lib/http/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
1
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
3
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
@@ -91,6 +92,8 @@ request.interceptors.request.use(function (url, options) {
91
92
  // @ts-ignore
92
93
  options.headers['x-asm-prefer-tag'] = tag; //灰度发版标识
93
94
  }
95
+ // @ts-ignore
96
+ options.headers['terminal'] = 'PC';
94
97
  // wms 提示,是否排班标识
95
98
  var expireWarnFlag = getCache('expireWarnFlag', true);
96
99
  // @ts-ignore
@@ -406,7 +409,7 @@ export function fetchOptions(_x3, _x4, _x5, _x6) {
406
409
  return _fetchOptions.apply(this, arguments);
407
410
  }
408
411
  function _fetchOptions() {
409
- _fetchOptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(url, param, valueField, labelField) {
412
+ _fetchOptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(url, param, valueField, labelField) {
410
413
  var showValue,
411
414
  needGateWay,
412
415
  timeout,
@@ -414,44 +417,44 @@ function _fetchOptions() {
414
417
  valueIsNumber,
415
418
  rows,
416
419
  data,
417
- _args2 = arguments;
418
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
419
- while (1) switch (_context2.prev = _context2.next) {
420
+ _args3 = arguments;
421
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
422
+ while (1) switch (_context3.prev = _context3.next) {
420
423
  case 0:
421
- showValue = _args2.length > 4 && _args2[4] !== undefined ? _args2[4] : true;
422
- needGateWay = _args2.length > 5 && _args2[5] !== undefined ? _args2[5] : true;
423
- timeout = _args2.length > 6 && _args2[6] !== undefined ? _args2[6] : 60000;
424
- isGet = _args2.length > 7 && _args2[7] !== undefined ? _args2[7] : true;
425
- valueIsNumber = _args2.length > 8 && _args2[8] !== undefined ? _args2[8] : false;
424
+ showValue = _args3.length > 4 && _args3[4] !== undefined ? _args3[4] : true;
425
+ needGateWay = _args3.length > 5 && _args3[5] !== undefined ? _args3[5] : true;
426
+ timeout = _args3.length > 6 && _args3[6] !== undefined ? _args3[6] : 60000;
427
+ isGet = _args3.length > 7 && _args3[7] !== undefined ? _args3[7] : true;
428
+ valueIsNumber = _args3.length > 8 && _args3[8] !== undefined ? _args3[8] : false;
426
429
  if (!isGet) {
427
- _context2.next = 14;
430
+ _context3.next = 14;
428
431
  break;
429
432
  }
430
- _context2.next = 8;
433
+ _context3.next = 8;
431
434
  return httpGet(url, param, needGateWay, timeout);
432
435
  case 8:
433
- _context2.t0 = _context2.sent.rows;
434
- if (_context2.t0) {
435
- _context2.next = 11;
436
+ _context3.t0 = _context3.sent.rows;
437
+ if (_context3.t0) {
438
+ _context3.next = 11;
436
439
  break;
437
440
  }
438
- _context2.t0 = [];
441
+ _context3.t0 = [];
439
442
  case 11:
440
- rows = _context2.t0;
441
- _context2.next = 20;
443
+ rows = _context3.t0;
444
+ _context3.next = 20;
442
445
  break;
443
446
  case 14:
444
- _context2.next = 16;
447
+ _context3.next = 16;
445
448
  return httpPost(url, param, true, needGateWay, timeout);
446
449
  case 16:
447
- _context2.t1 = _context2.sent.rows;
448
- if (_context2.t1) {
449
- _context2.next = 19;
450
+ _context3.t1 = _context3.sent.rows;
451
+ if (_context3.t1) {
452
+ _context3.next = 19;
450
453
  break;
451
454
  }
452
- _context2.t1 = [];
455
+ _context3.t1 = [];
453
456
  case 19:
454
- rows = _context2.t1;
457
+ rows = _context3.t1;
455
458
  case 20:
456
459
  data = (rows || []).map(function (o) {
457
460
  return _objectSpread(_objectSpread({}, o), {}, {
@@ -460,12 +463,12 @@ function _fetchOptions() {
460
463
  label: (showValue ? o[valueField] + '→' : '') + o[labelField]
461
464
  });
462
465
  });
463
- return _context2.abrupt("return", data);
466
+ return _context3.abrupt("return", data);
464
467
  case 22:
465
468
  case "end":
466
- return _context2.stop();
469
+ return _context3.stop();
467
470
  }
468
- }, _callee2);
471
+ }, _callee3);
469
472
  }));
470
473
  return _fetchOptions.apply(this, arguments);
471
474
  }
@@ -475,4 +478,172 @@ export var checkResourceRight = function checkResourceRight(ids) {
475
478
  resourceIds: ids
476
479
  }, true, false);
477
480
  };
481
+ /**
482
+ * 分批获取数据,当一次性取大于2000条,且是第一页时,分多次去取,避免一次性取太多数据导致后端工程压力过大
483
+ *
484
+ * 注意:如果pageSize小于等于2000,或不是取第一页数据时,直接使用普通请求
485
+ *
486
+ * @param url
487
+ * @param params
488
+ * @param needGateWay
489
+ * @param timeout
490
+ * @returns
491
+ */
492
+ export var httpBatchGet = /*#__PURE__*/function () {
493
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(url) {
494
+ var params,
495
+ needGateWay,
496
+ timeout,
497
+ urlPageSize,
498
+ urlPageNum,
499
+ pageSize,
500
+ pageNum,
501
+ cleanUrl,
502
+ batchSize,
503
+ allRows,
504
+ total,
505
+ currentPage,
506
+ firstParams,
507
+ firstResponse,
508
+ firstData,
509
+ actualPageSize,
510
+ totalPages,
511
+ maxConcurrent,
512
+ remainingPages,
513
+ i,
514
+ _i,
515
+ batchPages,
516
+ batchRequests,
517
+ batchResponses,
518
+ _args2 = arguments;
519
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
520
+ while (1) switch (_context2.prev = _context2.next) {
521
+ case 0:
522
+ params = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
523
+ needGateWay = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : true;
524
+ timeout = _args2.length > 3 && _args2[3] !== undefined ? _args2[3] : 60000;
525
+ // 从URL中获取pageSize和page参数
526
+ urlPageSize = getUrlQuery('pageSize', url);
527
+ urlPageNum = getUrlQuery('page', url) || '1'; // 获取pageSize值,优先使用params中的,其次使用URL中的
528
+ pageSize = params.pageSize || (urlPageSize ? parseInt(urlPageSize) : 2000);
529
+ pageNum = params.page || (urlPageNum ? parseInt(urlPageNum) : 1); // 如果pageSize小于等于2000,或不是取第一页数据时,直接使用普通请求
530
+ if (!(pageSize <= 2000 || pageNum !== 1)) {
531
+ _context2.next = 9;
532
+ break;
533
+ }
534
+ return _context2.abrupt("return", ajax(url, params, 'get', needGateWay, true, timeout));
535
+ case 9:
536
+ // 分批获取数据时,需要从URL中移除原有的pageSize和page参数
537
+ cleanUrl = url;
538
+ if (urlPageSize) {
539
+ cleanUrl = setUrlQuery(cleanUrl, {
540
+ pageSize: ''
541
+ }).replace('&pageSize=', '').replace('pageSize=', '');
542
+ }
543
+ if (urlPageNum) {
544
+ cleanUrl = setUrlQuery(cleanUrl, {
545
+ page: ''
546
+ }).replace('&page=', '').replace('page=', '');
547
+ }
548
+ // 分批获取数据
549
+ batchSize = 2000;
550
+ allRows = [];
551
+ total = 0;
552
+ currentPage = pageNum;
553
+ _context2.prev = 16;
554
+ // 第一次请求,获取总数
555
+ firstParams = _objectSpread(_objectSpread({}, params), {}, {
556
+ pageSize: batchSize,
557
+ page: currentPage
558
+ });
559
+ _context2.next = 20;
560
+ return ajax(cleanUrl, firstParams, 'get', needGateWay, true, timeout);
561
+ case 20:
562
+ firstResponse = _context2.sent;
563
+ firstData = firstResponse;
564
+ if (firstData.rows) {
565
+ allRows.push.apply(allRows, _toConsumableArray(firstData.rows));
566
+ total = firstData.total || 0;
567
+ }
568
+ // 如果total小于等于2000,不需要分批获取,直接返回
569
+ if (!(total <= 2000)) {
570
+ _context2.next = 25;
571
+ break;
572
+ }
573
+ return _context2.abrupt("return", firstResponse);
574
+ case 25:
575
+ // 计算实际需要获取的数据量(不超过用户传入的pageSize)
576
+ actualPageSize = Math.min(pageSize, total); // 计算需要请求的总页数(基于实际需要的数据量)
577
+ totalPages = Math.ceil(actualPageSize / batchSize); // 如果还有更多数据需要获取
578
+ if (!(totalPages > 1)) {
579
+ _context2.next = 42;
580
+ break;
581
+ }
582
+ // 分批并发请求,每次最多6个并发
583
+ maxConcurrent = 6;
584
+ remainingPages = []; // 准备所有需要请求的页码
585
+ for (i = currentPage + 1; i <= totalPages; i++) {
586
+ remainingPages.push(i);
587
+ }
588
+ // 分批处理请求
589
+ _i = 0;
590
+ case 32:
591
+ if (!(_i < remainingPages.length)) {
592
+ _context2.next = 42;
593
+ break;
594
+ }
595
+ batchPages = remainingPages.slice(_i, _i + maxConcurrent);
596
+ batchRequests = batchPages.map(function (pageNum) {
597
+ // 计算当前页应该获取的数据量
598
+ var currentPageSize = batchSize;
599
+ // 如果是最后一页,计算实际需要的数据量
600
+ if (pageNum === totalPages) {
601
+ var remainingData = actualPageSize - (pageNum - 1) * batchSize;
602
+ currentPageSize = Math.max(0, remainingData);
603
+ }
604
+ var requestParams = _objectSpread(_objectSpread({}, params), {}, {
605
+ pageSize: currentPageSize,
606
+ page: pageNum
607
+ });
608
+ return ajax(cleanUrl, requestParams, 'get', needGateWay, true, timeout);
609
+ }); // 并发执行当前批次的请求
610
+ _context2.next = 37;
611
+ return Promise.all(batchRequests);
612
+ case 37:
613
+ batchResponses = _context2.sent;
614
+ // 合并当前批次的响应数据
615
+ batchResponses.forEach(function (response) {
616
+ var data = response;
617
+ if (data.rows) {
618
+ allRows.push.apply(allRows, _toConsumableArray(data.rows));
619
+ }
620
+ });
621
+ case 39:
622
+ _i += maxConcurrent;
623
+ _context2.next = 32;
624
+ break;
625
+ case 42:
626
+ // 如果获取的数据超过了用户要求的pageSize,进行截取
627
+ if (allRows.length > actualPageSize) {
628
+ allRows.splice(actualPageSize);
629
+ }
630
+ // 返回合并后的数据,保持与原始响应格式一致
631
+ return _context2.abrupt("return", _objectSpread(_objectSpread({}, firstResponse), {}, {
632
+ rows: allRows,
633
+ total: total // 保持原始的total值
634
+ }));
635
+ case 46:
636
+ _context2.prev = 46;
637
+ _context2.t0 = _context2["catch"](16);
638
+ throw _context2.t0;
639
+ case 49:
640
+ case "end":
641
+ return _context2.stop();
642
+ }
643
+ }, _callee2, null, [[16, 46]]);
644
+ }));
645
+ return function httpBatchGet(_x7) {
646
+ return _ref2.apply(this, arguments);
647
+ };
648
+ }();
478
649
  export default request;
package/lib/index.d.ts CHANGED
@@ -19,7 +19,7 @@ import TagCheck from './components/TagCheck';
19
19
  import ViewOffice from './components/ViewOffice';
20
20
  import ProButton from './components/ProButton';
21
21
  import RecordLog from './components/RecordLog';
22
- import request, { httpGet, httpPut, httpPost, httpDelete, getDict, fetchOptions } from './http';
22
+ import request, { httpGet, httpPut, httpPost, httpDelete, getDict, fetchOptions, httpBatchGet } from './http';
23
23
  import BaseService from './service/BaseService';
24
24
  import * as mdmRequest from './http/mdmRequest';
25
25
  import * as utils from './utils';
@@ -43,4 +43,4 @@ import type { DescritionCardProps } from './components/DescritionCard';
43
43
  import type { PermissionProps } from './components/Permission';
44
44
  import type { TDict } from './hooks/useDict';
45
45
  export type { ApiResponse, TableToolbar, BaseApiType, MethodType, DtlLyaoutProps, DescritionCardProps, PermissionProps, TDict, };
46
- export { DtlLayout, InputTable, Page404, Loading, IconSelector, ImageSelector, InputMultiLine, AreaCascader, AreaCascaderPanel, DescritionCard, Permission, GroupTip, ViewOffice, IconBack, IconText, IconBell, IconQuestion, IconSearch, TagCheck, BaseService, request, httpDelete, httpGet, httpPost, httpPut, getDict, fetchOptions, utils, useSingle, useDtl, usePermission, useGetState, useFilterLocal, useQueue, useBaseDict, useSelectOptions, useDict, useMdm, showConfirmFun, exportProcess, mdmRequest, ProButton, RecordLog, };
46
+ export { DtlLayout, InputTable, Page404, Loading, IconSelector, ImageSelector, InputMultiLine, AreaCascader, AreaCascaderPanel, DescritionCard, Permission, GroupTip, ViewOffice, IconBack, IconText, IconBell, IconQuestion, IconSearch, TagCheck, BaseService, request, httpDelete, httpGet, httpPost, httpPut, getDict, fetchOptions, httpBatchGet, utils, useSingle, useDtl, usePermission, useGetState, useFilterLocal, useQueue, useBaseDict, useSelectOptions, useDict, useMdm, showConfirmFun, exportProcess, mdmRequest, ProButton, RecordLog, };
package/lib/index.js CHANGED
@@ -19,7 +19,7 @@ import TagCheck from './components/TagCheck';
19
19
  import ViewOffice from './components/ViewOffice';
20
20
  import ProButton from './components/ProButton';
21
21
  import RecordLog from './components/RecordLog';
22
- import request, { httpGet, httpPut, httpPost, httpDelete, getDict, fetchOptions } from './http';
22
+ import request, { httpGet, httpPut, httpPost, httpDelete, getDict, fetchOptions, httpBatchGet } from './http';
23
23
  import BaseService from './service/BaseService';
24
24
  import * as mdmRequest from './http/mdmRequest';
25
25
  import * as utils from './utils';
@@ -36,4 +36,4 @@ import showConfirmFun from './hooks/useShowConfirm';
36
36
  import useQueue from './hooks/useQueue';
37
37
  import { useDict } from './hooks/useDict';
38
38
  import useMdm from './hooks/useMdm';
39
- export { DtlLayout, InputTable, Page404, Loading, IconSelector, ImageSelector, InputMultiLine, AreaCascader, AreaCascaderPanel, DescritionCard, Permission, GroupTip, ViewOffice, IconBack, IconText, IconBell, IconQuestion, IconSearch, TagCheck, BaseService, request, httpDelete, httpGet, httpPost, httpPut, getDict, fetchOptions, utils, useSingle, useDtl, usePermission, useGetState, useFilterLocal, useQueue, useBaseDict, useSelectOptions, useDict, useMdm, showConfirmFun, exportProcess, mdmRequest, ProButton, RecordLog };
39
+ export { DtlLayout, InputTable, Page404, Loading, IconSelector, ImageSelector, InputMultiLine, AreaCascader, AreaCascaderPanel, DescritionCard, Permission, GroupTip, ViewOffice, IconBack, IconText, IconBell, IconQuestion, IconSearch, TagCheck, BaseService, request, httpDelete, httpGet, httpPost, httpPut, getDict, fetchOptions, httpBatchGet, utils, useSingle, useDtl, usePermission, useGetState, useFilterLocal, useQueue, useBaseDict, useSelectOptions, useDict, useMdm, showConfirmFun, exportProcess, mdmRequest, ProButton, RecordLog };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Add 加法函数,val1参数一,val2参数二
3
+ *
4
+ * @param val1
5
+ * @param val2
6
+ * @returns
7
+ */
8
+ export declare const add: (val1: number | string, val2: number | string) => number;
9
+ /**
10
+ * Sub 减法函数,val1参数一,val2参数二
11
+ *
12
+ * @param val1
13
+ * @param val2
14
+ * @returns
15
+ */
16
+ export declare const sub: (val1: number | string, val2: number | string) => number;
17
+ /**
18
+ * Mul 乘法函数,val1参数一,val2参数二
19
+ *
20
+ * @param val1
21
+ * @param val2
22
+ * @returns
23
+ */
24
+ export declare const mul: (val1: number | string, val2: number | string) => number;
25
+ /**
26
+ * Div 除法函数,val1参数一,val2参数二
27
+ *
28
+ * @param val1
29
+ * @param val2
30
+ * @returns
31
+ */
32
+ export declare const div: (val1: number | string, val2: number | string) => number;
@@ -0,0 +1,41 @@
1
+ import Big from 'big.js';
2
+ /**
3
+ * Add 加法函数,val1参数一,val2参数二
4
+ *
5
+ * @param val1
6
+ * @param val2
7
+ * @returns
8
+ */
9
+ export var add = function add(val1, val2) {
10
+ return Number(new Big(Number(val1)).plus(Number(val2)).toString());
11
+ };
12
+ /**
13
+ * Sub 减法函数,val1参数一,val2参数二
14
+ *
15
+ * @param val1
16
+ * @param val2
17
+ * @returns
18
+ */
19
+ export var sub = function sub(val1, val2) {
20
+ return Number(new Big(Number(val1)).minus(Number(val2)).toString());
21
+ };
22
+ /**
23
+ * Mul 乘法函数,val1参数一,val2参数二
24
+ *
25
+ * @param val1
26
+ * @param val2
27
+ * @returns
28
+ */
29
+ export var mul = function mul(val1, val2) {
30
+ return Number(new Big(Number(val1)).times(Number(val2)).toString());
31
+ };
32
+ /**
33
+ * Div 除法函数,val1参数一,val2参数二
34
+ *
35
+ * @param val1
36
+ * @param val2
37
+ * @returns
38
+ */
39
+ export var div = function div(val1, val2) {
40
+ return Number(new Big(Number(val1)).div(Number(val2)).toString());
41
+ };
@@ -4,6 +4,7 @@ export * from './array';
4
4
  export * from './format';
5
5
  export * from './size';
6
6
  export * from './promise';
7
+ export * from './clac';
7
8
  export { getBrowserId } from 'ls-pro-tools';
8
9
  /**
9
10
  * 获取 url 参数
@@ -7,6 +7,7 @@ export * from './array';
7
7
  export * from './format';
8
8
  export * from './size';
9
9
  export * from './promise';
10
+ export * from './clac';
10
11
  export { getBrowserId } from 'ls-pro-tools';
11
12
  /**
12
13
  * 获取 url 参数
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ls-pro-common",
3
- "version": "3.1.22",
3
+ "version": "3.1.24",
4
4
  "description": "ls-pro-common",
5
5
  "license": "MIT",
6
6
  "sideEffects": [
@@ -34,7 +34,8 @@
34
34
  "rc-util": "^5.0.6",
35
35
  "react-sortable-hoc": "^2.0.0",
36
36
  "swr": "1.1.0",
37
- "@fingerprintjs/fingerprintjs": "^4.6.1"
37
+ "@fingerprintjs/fingerprintjs": "^4.6.1",
38
+ "big.js": "^6.2.1"
38
39
  },
39
40
  "peerDependencies": {
40
41
  "antd": "4.x",