ls-pro-common 3.1.49 → 3.1.51

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/lib/http/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
4
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
6
  import { extend } from 'umi-request';
@@ -359,116 +359,6 @@ export function httpDelete(url, data) {
359
359
  var timeout = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 60000;
360
360
  return ajax(url, data, 'delete', needGateWay, true, timeout);
361
361
  }
362
- /**
363
- * 读取数据字典
364
- *
365
- * @param dictCode 字典编码
366
- * @param showValue 是否显示值
367
- * @param needGateWay 是否需要网关 默认为true
368
- * @param timeout 超时时间,默认60000毫秒
369
- * @param isGet 是否Get请求
370
- * @param valueIsNumber 返回值是否为数字,默认false
371
- * @returns Promise<Record<string,string>[]>
372
- */
373
- export function getDict(dictCodes) {
374
- var showValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
375
- var needGateWay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
376
- var timeout = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 60000;
377
- var isGet = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
378
- var valueIsNumber = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
379
- var api = '/lesoon-petrel-integration-api/sysDictDtl/listByProperties';
380
- var param = {
381
- dictCodes: (dictCodes || '').split(',')
382
- };
383
- return fetchOptions(api, param, 'dictValue', 'displayName', showValue, needGateWay, timeout, isGet, valueIsNumber);
384
- }
385
- /**
386
- * 加载下拉框的数据源
387
- *
388
- * @param url 后端接口
389
- * @param param 请求参数
390
- * @param valueField 值字段
391
- * @param labelField 显示字段
392
- * @param showValue 显示值
393
- * @param needGateWay 是否需要网关 默认为true
394
- * @param timeout
395
- * @param isGet = true 是否get请求,默认true
396
- * @param valueIsNumber 返回值是否为数字,默认false
397
- * @returns
398
- */
399
- export function fetchOptions(_x3, _x4, _x5, _x6) {
400
- return _fetchOptions.apply(this, arguments);
401
- }
402
- function _fetchOptions() {
403
- _fetchOptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(url, param, valueField, labelField) {
404
- var showValue,
405
- needGateWay,
406
- timeout,
407
- isGet,
408
- valueIsNumber,
409
- rows,
410
- data,
411
- _args4 = arguments;
412
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
413
- while (1) switch (_context4.prev = _context4.next) {
414
- case 0:
415
- showValue = _args4.length > 4 && _args4[4] !== undefined ? _args4[4] : true;
416
- needGateWay = _args4.length > 5 && _args4[5] !== undefined ? _args4[5] : true;
417
- timeout = _args4.length > 6 && _args4[6] !== undefined ? _args4[6] : 60000;
418
- isGet = _args4.length > 7 && _args4[7] !== undefined ? _args4[7] : true;
419
- valueIsNumber = _args4.length > 8 && _args4[8] !== undefined ? _args4[8] : false;
420
- if (!isGet) {
421
- _context4.next = 14;
422
- break;
423
- }
424
- _context4.next = 8;
425
- return httpBatchGet(url, param, needGateWay, timeout);
426
- case 8:
427
- _context4.t0 = _context4.sent.rows;
428
- if (_context4.t0) {
429
- _context4.next = 11;
430
- break;
431
- }
432
- _context4.t0 = [];
433
- case 11:
434
- rows = _context4.t0;
435
- _context4.next = 20;
436
- break;
437
- case 14:
438
- _context4.next = 16;
439
- return httpBatchPost(url, param, needGateWay, timeout);
440
- case 16:
441
- _context4.t1 = _context4.sent.rows;
442
- if (_context4.t1) {
443
- _context4.next = 19;
444
- break;
445
- }
446
- _context4.t1 = [];
447
- case 19:
448
- rows = _context4.t1;
449
- case 20:
450
- data = (rows || []).map(function (o) {
451
- return _objectSpread(_objectSpread({}, o), {}, {
452
- value: valueIsNumber && !isNaN(o[valueField]) ? Number(o[valueField]) : o[valueField],
453
- text: o[labelField],
454
- label: (showValue ? o[valueField] + '→' : '') + o[labelField]
455
- });
456
- });
457
- return _context4.abrupt("return", data);
458
- case 22:
459
- case "end":
460
- return _context4.stop();
461
- }
462
- }, _callee4);
463
- }));
464
- return _fetchOptions.apply(this, arguments);
465
- }
466
- export var getResourceRight = function getResourceRight(ids) {
467
- var url = '/lesoon/lesoon-petrel-permission-api/sysUserRole/selectResourceIds';
468
- return httpPost(url, {
469
- resourceIds: ids
470
- }, true, false);
471
- };
472
362
  /**
473
363
  * 上传文件,因fetch不支持进度回调,使用XMLHttpRequest实现上传文件
474
364
  *
@@ -725,7 +615,7 @@ var defaultPageSize = 2000;
725
615
  * @param timeout
726
616
  * @returns
727
617
  */
728
- function httpBatchRequest(_x7) {
618
+ function httpBatchRequest(_x3) {
729
619
  return _httpBatchRequest.apply(this, arguments);
730
620
  }
731
621
  /**
@@ -740,7 +630,7 @@ function httpBatchRequest(_x7) {
740
630
  * @returns
741
631
  */
742
632
  function _httpBatchRequest() {
743
- _httpBatchRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(url) {
633
+ _httpBatchRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(url) {
744
634
  var params,
745
635
  method,
746
636
  needGateWay,
@@ -772,24 +662,24 @@ function _httpBatchRequest() {
772
662
  batchPages,
773
663
  batchRequests,
774
664
  batchResponses,
775
- _args5 = arguments;
776
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
777
- while (1) switch (_context5.prev = _context5.next) {
665
+ _args4 = arguments;
666
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
667
+ while (1) switch (_context4.prev = _context4.next) {
778
668
  case 0:
779
- params = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
780
- method = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : 'get';
781
- needGateWay = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : true;
782
- timeout = _args5.length > 4 && _args5[4] !== undefined ? _args5[4] : 60000;
669
+ params = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
670
+ method = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : 'get';
671
+ needGateWay = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : true;
672
+ timeout = _args4.length > 4 && _args4[4] !== undefined ? _args4[4] : 60000;
783
673
  // 从URL中获取pageSize和page参数
784
674
  urlPageSize = getUrlQuery('pageSize', url) || getUrlQuery('page.size', url);
785
675
  urlPageNum = getUrlQuery('page', url) || getUrlQuery('page.pn', url) || '1'; // 优先使用params中的分页参数,其次使用URL中的分页参数
786
676
  pageSize = (params === null || params === void 0 ? void 0 : params.pageSize) || (params === null || params === void 0 ? void 0 : params['page.size']) || (urlPageSize ? parseInt(urlPageSize) : defaultPageSize);
787
677
  pageNum = (params === null || params === void 0 ? void 0 : params.page) || (params === null || params === void 0 ? void 0 : params['page.pn']) || parseInt(urlPageNum); // 如果pageSize小于等于defaultPageSize,或不是取第一页数据时,直接使用普通请求
788
678
  if (!(pageSize <= defaultPageSize || pageNum !== 1)) {
789
- _context5.next = 10;
679
+ _context4.next = 10;
790
680
  break;
791
681
  }
792
- return _context5.abrupt("return", ajax(url, params, method, needGateWay, true, timeout));
682
+ return _context4.abrupt("return", ajax(url, params, method, needGateWay, true, timeout));
793
683
  case 10:
794
684
  // 是否为 2.0版本的api。
795
685
  isV2 = url.includes('page.size') || (params === null || params === void 0 ? void 0 : params['page.size']) ? true : false; // 不同版本api的请求分页关键字处理,
@@ -807,23 +697,23 @@ function _httpBatchRequest() {
807
697
  allRows = [];
808
698
  total = 0;
809
699
  currentPage = pageNum;
810
- _context5.prev = 20;
700
+ _context4.prev = 20;
811
701
  // 第一次请求,获取总数
812
702
  firstParams = _objectSpread(_objectSpread({}, params), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, PAGE_SIZE, batchSize), _defineProperty(_objectSpread2, PAGE_NUM, currentPage), _objectSpread2)); // 如果是 post 请求,body 和 query 里都传入分页参数
813
703
  api = cleanUrl;
814
704
  if (method === 'post') {
815
705
  api = setUrlQuery(cleanUrl, (_setUrlQuery3 = {}, _defineProperty(_setUrlQuery3, PAGE_SIZE, batchSize), _defineProperty(_setUrlQuery3, PAGE_NUM, currentPage), _setUrlQuery3));
816
706
  }
817
- _context5.next = 26;
707
+ _context4.next = 26;
818
708
  return ajax(api, firstParams, method, needGateWay, true, timeout);
819
709
  case 26:
820
- firstResponse = _context5.sent;
710
+ firstResponse = _context4.sent;
821
711
  firstData = firstResponse; // 如果返回值没有 rows 或 total,直接返回普通请求
822
712
  if (!(!('rows' in firstData) || !('total' in firstData))) {
823
- _context5.next = 30;
713
+ _context4.next = 30;
824
714
  break;
825
715
  }
826
- return _context5.abrupt("return", ajax(url, params, method, needGateWay, true, timeout));
716
+ return _context4.abrupt("return", ajax(url, params, method, needGateWay, true, timeout));
827
717
  case 30:
828
718
  if (firstData.rows) {
829
719
  allRows.push.apply(allRows, _toConsumableArray(firstData.rows));
@@ -831,16 +721,16 @@ function _httpBatchRequest() {
831
721
  }
832
722
  // 如果total小于等于defaultPageSize,不需要分批获取,直接返回
833
723
  if (!(total <= defaultPageSize)) {
834
- _context5.next = 33;
724
+ _context4.next = 33;
835
725
  break;
836
726
  }
837
- return _context5.abrupt("return", firstResponse);
727
+ return _context4.abrupt("return", firstResponse);
838
728
  case 33:
839
729
  // 计算实际需要获取的数据量(不超过用户传入的pageSize)
840
730
  actualPageSize = Math.min(pageSize, total); // 计算需要请求的总页数(基于实际需要的数据量)
841
731
  totalPages = Math.ceil(actualPageSize / batchSize); // 如果还有更多数据需要获取
842
732
  if (!(totalPages > 1)) {
843
- _context5.next = 50;
733
+ _context4.next = 50;
844
734
  break;
845
735
  }
846
736
  // 分批并发请求,每次最多6个并发
@@ -853,30 +743,24 @@ function _httpBatchRequest() {
853
743
  _i = 0;
854
744
  case 40:
855
745
  if (!(_i < remainingPages.length)) {
856
- _context5.next = 50;
746
+ _context4.next = 50;
857
747
  break;
858
748
  }
859
749
  batchPages = remainingPages.slice(_i, _i + maxConcurrent);
860
- batchRequests = batchPages.map(function (pageNum) {
750
+ batchRequests = batchPages.map(function (page) {
861
751
  var _objectSpread3;
862
- // 计算当前页应该获取的数据量
863
- var currentPageSize = batchSize;
864
- // 如果是最后一页,计算实际需要的数据量
865
- if (pageNum === totalPages) {
866
- var remainingData = actualPageSize - (pageNum - 1) * batchSize;
867
- currentPageSize = Math.max(0, remainingData);
868
- }
869
- var requestParams = _objectSpread(_objectSpread({}, params), {}, (_objectSpread3 = {}, _defineProperty(_objectSpread3, PAGE_SIZE, currentPageSize), _defineProperty(_objectSpread3, PAGE_NUM, pageNum), _objectSpread3));
752
+ var requestParams = _objectSpread(_objectSpread({}, params), {}, (_objectSpread3 = {}, _defineProperty(_objectSpread3, PAGE_SIZE, batchSize), _defineProperty(_objectSpread3, PAGE_NUM, page), _objectSpread3));
753
+ var requestApi = cleanUrl;
870
754
  if (method === 'post') {
871
755
  var _setUrlQuery4;
872
- api = setUrlQuery(cleanUrl, (_setUrlQuery4 = {}, _defineProperty(_setUrlQuery4, PAGE_SIZE, currentPageSize), _defineProperty(_setUrlQuery4, PAGE_NUM, pageNum), _setUrlQuery4));
756
+ requestApi = setUrlQuery(cleanUrl, (_setUrlQuery4 = {}, _defineProperty(_setUrlQuery4, PAGE_SIZE, batchSize), _defineProperty(_setUrlQuery4, PAGE_NUM, page), _setUrlQuery4));
873
757
  }
874
- return ajax(api, requestParams, method, needGateWay, true, timeout);
758
+ return ajax(requestApi, requestParams, method, needGateWay, true, timeout);
875
759
  }); // 并发执行当前批次的请求
876
- _context5.next = 45;
760
+ _context4.next = 45;
877
761
  return Promise.all(batchRequests);
878
762
  case 45:
879
- batchResponses = _context5.sent;
763
+ batchResponses = _context4.sent;
880
764
  // 合并当前批次的响应数据
881
765
  batchResponses.forEach(function (response) {
882
766
  var data = response;
@@ -886,7 +770,7 @@ function _httpBatchRequest() {
886
770
  });
887
771
  case 47:
888
772
  _i += maxConcurrent;
889
- _context5.next = 40;
773
+ _context4.next = 40;
890
774
  break;
891
775
  case 50:
892
776
  // 如果获取的数据超过了用户要求的pageSize,进行截取
@@ -894,19 +778,19 @@ function _httpBatchRequest() {
894
778
  allRows.splice(actualPageSize);
895
779
  }
896
780
  // 返回合并后的数据,保持与原始响应格式一致
897
- return _context5.abrupt("return", _objectSpread(_objectSpread({}, firstResponse), {}, {
781
+ return _context4.abrupt("return", _objectSpread(_objectSpread({}, firstResponse), {}, {
898
782
  rows: allRows,
899
783
  total: total // 保持原始的total值
900
784
  }));
901
785
  case 54:
902
- _context5.prev = 54;
903
- _context5.t0 = _context5["catch"](20);
904
- throw _context5.t0;
786
+ _context4.prev = 54;
787
+ _context4.t0 = _context4["catch"](20);
788
+ throw _context4.t0;
905
789
  case 57:
906
790
  case "end":
907
- return _context5.stop();
791
+ return _context4.stop();
908
792
  }
909
- }, _callee5, null, [[20, 54]]);
793
+ }, _callee4, null, [[20, 54]]);
910
794
  }));
911
795
  return _httpBatchRequest.apply(this, arguments);
912
796
  }
@@ -929,7 +813,7 @@ export var httpBatchGet = /*#__PURE__*/function () {
929
813
  }
930
814
  }, _callee2);
931
815
  }));
932
- return function httpBatchGet(_x8) {
816
+ return function httpBatchGet(_x4) {
933
817
  return _ref2.apply(this, arguments);
934
818
  };
935
819
  }();
@@ -963,8 +847,124 @@ export var httpBatchPost = /*#__PURE__*/function () {
963
847
  }
964
848
  }, _callee3);
965
849
  }));
966
- return function httpBatchPost(_x9) {
850
+ return function httpBatchPost(_x5) {
967
851
  return _ref3.apply(this, arguments);
968
852
  };
969
853
  }();
854
+ /**
855
+ * 读取数据字典
856
+ *
857
+ * @param dictCode 字典编码
858
+ * @param showValue 是否显示值
859
+ * @param needGateWay 是否需要网关 默认为true
860
+ * @param timeout 超时时间,默认60000毫秒
861
+ * @param isGet 是否Get请求
862
+ * @param valueIsNumber 返回值是否为数字,默认false
863
+ * @returns Promise<Record<string,string>[]>
864
+ */
865
+ export function getDict(dictCodes) {
866
+ var showValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
867
+ var needGateWay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
868
+ var timeout = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 60000;
869
+ var isGet = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
870
+ var valueIsNumber = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
871
+ var api = '/lesoon-petrel-integration-api/sysDictDtl/listByProperties';
872
+ var param = {
873
+ dictCodes: (dictCodes || '').split(',')
874
+ };
875
+ return fetchOptions(api, param, 'dictValue', 'displayName', showValue, needGateWay, timeout, isGet, valueIsNumber);
876
+ }
877
+ /**
878
+ * 加载下拉框的数据源
879
+ *
880
+ * @param url 后端接口
881
+ * @param param 请求参数
882
+ * @param valueField 值字段
883
+ * @param labelField 显示字段
884
+ * @param showValue 显示值
885
+ * @param needGateWay 是否需要网关 默认为true
886
+ * @param timeout
887
+ * @param isGet = true 是否get请求,默认true
888
+ * @param valueIsNumber 返回值是否为数字,默认false
889
+ * @returns
890
+ */
891
+ export function fetchOptions(_x6, _x7, _x8, _x9) {
892
+ return _fetchOptions.apply(this, arguments);
893
+ }
894
+ /**
895
+ * 获取用户资源Id对应的权限值
896
+ *
897
+ * @param ids 资源id
898
+ * @returns
899
+ */
900
+ function _fetchOptions() {
901
+ _fetchOptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(url, param, valueField, labelField) {
902
+ var showValue,
903
+ needGateWay,
904
+ timeout,
905
+ isGet,
906
+ valueIsNumber,
907
+ rows,
908
+ data,
909
+ _args5 = arguments;
910
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
911
+ while (1) switch (_context5.prev = _context5.next) {
912
+ case 0:
913
+ showValue = _args5.length > 4 && _args5[4] !== undefined ? _args5[4] : true;
914
+ needGateWay = _args5.length > 5 && _args5[5] !== undefined ? _args5[5] : true;
915
+ timeout = _args5.length > 6 && _args5[6] !== undefined ? _args5[6] : 60000;
916
+ isGet = _args5.length > 7 && _args5[7] !== undefined ? _args5[7] : true;
917
+ valueIsNumber = _args5.length > 8 && _args5[8] !== undefined ? _args5[8] : false;
918
+ if (!isGet) {
919
+ _context5.next = 14;
920
+ break;
921
+ }
922
+ _context5.next = 8;
923
+ return httpBatchGet(url, param, needGateWay, timeout);
924
+ case 8:
925
+ _context5.t0 = _context5.sent.rows;
926
+ if (_context5.t0) {
927
+ _context5.next = 11;
928
+ break;
929
+ }
930
+ _context5.t0 = [];
931
+ case 11:
932
+ rows = _context5.t0;
933
+ _context5.next = 20;
934
+ break;
935
+ case 14:
936
+ _context5.next = 16;
937
+ return httpBatchPost(url, param, needGateWay, timeout);
938
+ case 16:
939
+ _context5.t1 = _context5.sent.rows;
940
+ if (_context5.t1) {
941
+ _context5.next = 19;
942
+ break;
943
+ }
944
+ _context5.t1 = [];
945
+ case 19:
946
+ rows = _context5.t1;
947
+ case 20:
948
+ data = (rows || []).map(function (o) {
949
+ return _objectSpread(_objectSpread({}, o), {}, {
950
+ value: valueIsNumber && !isNaN(o[valueField]) ? Number(o[valueField]) : o[valueField],
951
+ text: o[labelField],
952
+ label: (showValue ? o[valueField] + '→' : '') + o[labelField]
953
+ });
954
+ });
955
+ return _context5.abrupt("return", data);
956
+ case 22:
957
+ case "end":
958
+ return _context5.stop();
959
+ }
960
+ }, _callee5);
961
+ }));
962
+ return _fetchOptions.apply(this, arguments);
963
+ }
964
+ export var getResourceRight = function getResourceRight(ids) {
965
+ var url = '/lesoon/lesoon-petrel-permission-api/sysUserRole/selectResourceIds';
966
+ return httpPost(url, {
967
+ resourceIds: ids
968
+ }, true, false);
969
+ };
970
970
  export default request;
package/lib/utils/url.js CHANGED
@@ -81,7 +81,7 @@ export var toGatewayUrl = function toGatewayUrl(url) {
81
81
  url = url || '';
82
82
  // 如果url带有名称,不需要设置网关
83
83
  if (url.startsWith('http://') || url.startsWith('https://') || url.startsWith('//')) return url;
84
- if (url.startsWith('/lesoon/') || url.startsWith('/petrel/')) {
84
+ if (url.startsWith('/lesoon/') || url.startsWith('/petrel/') || url.startsWith('/lesoon-retail/') || url.startsWith('/scm-bms/')) {
85
85
  return location.origin + url;
86
86
  }
87
87
  // 读取项目的默认网关
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ls-pro-common",
3
- "version": "3.1.49",
3
+ "version": "3.1.51",
4
4
  "description": "ls-pro-common",
5
5
  "license": "MIT",
6
6
  "sideEffects": [