ls-pro-common 3.1.26 → 3.1.29
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/common.js +1 -1
- package/dist/common.min.js +1 -1
- package/es/components/index.d.ts +21 -0
- package/es/components/index.js +21 -0
- package/es/hooks/index.d.ts +13 -0
- package/es/hooks/index.js +13 -0
- package/es/http/index.js +33 -22
- package/es/index.d.ts +21 -43
- package/es/index.js +16 -37
- package/es/utils/clac.d.ts +16 -20
- package/es/utils/clac.js +54 -24
- package/es/utils/index.d.ts +6 -5
- package/es/utils/index.js +16 -8
- package/lib/components/index.d.ts +21 -0
- package/lib/components/index.js +21 -0
- package/lib/hooks/index.d.ts +13 -0
- package/lib/hooks/index.js +13 -0
- package/lib/http/index.js +33 -22
- package/lib/index.d.ts +21 -43
- package/lib/index.js +16 -37
- package/lib/utils/clac.d.ts +16 -20
- package/lib/utils/clac.js +54 -24
- package/lib/utils/index.d.ts +6 -5
- package/lib/utils/index.js +16 -8
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { default as useSingle } from './useSingle';
|
|
2
|
+
export { default as useDtl } from './useDtl';
|
|
3
|
+
export { default as usePermission } from './usePermission';
|
|
4
|
+
export { default as useGetState } from './useGetState';
|
|
5
|
+
export { default as useFilterLocal } from './useFilterBack';
|
|
6
|
+
export { default as useBaseDict } from './useBaseDict';
|
|
7
|
+
export { default as useSelectOptions } from './useSelectOptions';
|
|
8
|
+
export { default as showConfirmFun } from './useShowConfirm';
|
|
9
|
+
export { default as useQueue } from './useQueue';
|
|
10
|
+
export { default as useSyncState } from './useSyncState';
|
|
11
|
+
export { useApiLoader } from './useApiLoad';
|
|
12
|
+
export { useDict } from './useDict';
|
|
13
|
+
export { default as useMdm } from './useMdm';
|
package/lib/http/index.js
CHANGED
|
@@ -525,6 +525,8 @@ function _httpBatchRequest() {
|
|
|
525
525
|
currentPage,
|
|
526
526
|
_objectSpread2,
|
|
527
527
|
firstParams,
|
|
528
|
+
api,
|
|
529
|
+
_setUrlQuery3,
|
|
528
530
|
firstResponse,
|
|
529
531
|
firstData,
|
|
530
532
|
actualPageSize,
|
|
@@ -555,7 +557,8 @@ function _httpBatchRequest() {
|
|
|
555
557
|
}
|
|
556
558
|
return _context5.abrupt("return", ajax(url, params, method, needGateWay, true, timeout));
|
|
557
559
|
case 10:
|
|
558
|
-
|
|
560
|
+
// 是否为 2.0版本的api。
|
|
561
|
+
isV2 = url.includes('page.size') || (params === null || params === void 0 ? void 0 : params['page.size']) ? true : false; // 不同版本api的请求分页关键字处理,
|
|
559
562
|
PAGE_SIZE = isV2 ? 'page.size' : 'pageSize';
|
|
560
563
|
PAGE_NUM = isV2 ? 'page.pn' : 'page'; // 分批获取数据时,需要从URL中移除原有的pageSize和page参数
|
|
561
564
|
cleanUrl = url;
|
|
@@ -572,34 +575,38 @@ function _httpBatchRequest() {
|
|
|
572
575
|
currentPage = pageNum;
|
|
573
576
|
_context5.prev = 20;
|
|
574
577
|
// 第一次请求,获取总数
|
|
575
|
-
firstParams = _objectSpread(_objectSpread({}, params), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, PAGE_SIZE, batchSize), _defineProperty(_objectSpread2, PAGE_NUM, currentPage), _objectSpread2));
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
578
|
+
firstParams = _objectSpread(_objectSpread({}, params), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, PAGE_SIZE, batchSize), _defineProperty(_objectSpread2, PAGE_NUM, currentPage), _objectSpread2)); // 如果是 post 请求,body 和 query 里都传入分页参数
|
|
579
|
+
api = cleanUrl;
|
|
580
|
+
if (method === 'post') {
|
|
581
|
+
api = setUrlQuery(cleanUrl, (_setUrlQuery3 = {}, _defineProperty(_setUrlQuery3, PAGE_SIZE, batchSize), _defineProperty(_setUrlQuery3, PAGE_NUM, currentPage), _setUrlQuery3));
|
|
582
|
+
}
|
|
583
|
+
_context5.next = 26;
|
|
584
|
+
return ajax(api, firstParams, method, needGateWay, true, timeout);
|
|
585
|
+
case 26:
|
|
579
586
|
firstResponse = _context5.sent;
|
|
580
587
|
firstData = firstResponse; // 如果返回值没有 rows 或 total,直接返回普通请求
|
|
581
588
|
if (!(!('rows' in firstData) || !('total' in firstData))) {
|
|
582
|
-
_context5.next =
|
|
589
|
+
_context5.next = 30;
|
|
583
590
|
break;
|
|
584
591
|
}
|
|
585
592
|
return _context5.abrupt("return", ajax(url, params, method, needGateWay, true, timeout));
|
|
586
|
-
case
|
|
593
|
+
case 30:
|
|
587
594
|
if (firstData.rows) {
|
|
588
595
|
allRows.push.apply(allRows, _toConsumableArray(firstData.rows));
|
|
589
596
|
total = firstData.total || 0;
|
|
590
597
|
}
|
|
591
598
|
// 如果total小于等于defaultPageSize,不需要分批获取,直接返回
|
|
592
599
|
if (!(total <= defaultPageSize)) {
|
|
593
|
-
_context5.next =
|
|
600
|
+
_context5.next = 33;
|
|
594
601
|
break;
|
|
595
602
|
}
|
|
596
603
|
return _context5.abrupt("return", firstResponse);
|
|
597
|
-
case
|
|
604
|
+
case 33:
|
|
598
605
|
// 计算实际需要获取的数据量(不超过用户传入的pageSize)
|
|
599
606
|
actualPageSize = Math.min(pageSize, total); // 计算需要请求的总页数(基于实际需要的数据量)
|
|
600
607
|
totalPages = Math.ceil(actualPageSize / batchSize); // 如果还有更多数据需要获取
|
|
601
608
|
if (!(totalPages > 1)) {
|
|
602
|
-
_context5.next =
|
|
609
|
+
_context5.next = 50;
|
|
603
610
|
break;
|
|
604
611
|
}
|
|
605
612
|
// 分批并发请求,每次最多6个并发
|
|
@@ -610,9 +617,9 @@ function _httpBatchRequest() {
|
|
|
610
617
|
}
|
|
611
618
|
// 分批处理请求
|
|
612
619
|
_i = 0;
|
|
613
|
-
case
|
|
620
|
+
case 40:
|
|
614
621
|
if (!(_i < remainingPages.length)) {
|
|
615
|
-
_context5.next =
|
|
622
|
+
_context5.next = 50;
|
|
616
623
|
break;
|
|
617
624
|
}
|
|
618
625
|
batchPages = remainingPages.slice(_i, _i + maxConcurrent);
|
|
@@ -626,11 +633,15 @@ function _httpBatchRequest() {
|
|
|
626
633
|
currentPageSize = Math.max(0, remainingData);
|
|
627
634
|
}
|
|
628
635
|
var requestParams = _objectSpread(_objectSpread({}, params), {}, (_objectSpread3 = {}, _defineProperty(_objectSpread3, PAGE_SIZE, currentPageSize), _defineProperty(_objectSpread3, PAGE_NUM, pageNum), _objectSpread3));
|
|
629
|
-
|
|
636
|
+
if (method === 'post') {
|
|
637
|
+
var _setUrlQuery4;
|
|
638
|
+
api = setUrlQuery(cleanUrl, (_setUrlQuery4 = {}, _defineProperty(_setUrlQuery4, PAGE_SIZE, currentPageSize), _defineProperty(_setUrlQuery4, PAGE_NUM, pageNum), _setUrlQuery4));
|
|
639
|
+
}
|
|
640
|
+
return ajax(api, requestParams, method, needGateWay, true, timeout);
|
|
630
641
|
}); // 并发执行当前批次的请求
|
|
631
|
-
_context5.next =
|
|
642
|
+
_context5.next = 45;
|
|
632
643
|
return Promise.all(batchRequests);
|
|
633
|
-
case
|
|
644
|
+
case 45:
|
|
634
645
|
batchResponses = _context5.sent;
|
|
635
646
|
// 合并当前批次的响应数据
|
|
636
647
|
batchResponses.forEach(function (response) {
|
|
@@ -639,11 +650,11 @@ function _httpBatchRequest() {
|
|
|
639
650
|
allRows.push.apply(allRows, _toConsumableArray(data.rows));
|
|
640
651
|
}
|
|
641
652
|
});
|
|
642
|
-
case
|
|
653
|
+
case 47:
|
|
643
654
|
_i += maxConcurrent;
|
|
644
|
-
_context5.next =
|
|
655
|
+
_context5.next = 40;
|
|
645
656
|
break;
|
|
646
|
-
case
|
|
657
|
+
case 50:
|
|
647
658
|
// 如果获取的数据超过了用户要求的pageSize,进行截取
|
|
648
659
|
if (allRows.length > actualPageSize) {
|
|
649
660
|
allRows.splice(actualPageSize);
|
|
@@ -653,15 +664,15 @@ function _httpBatchRequest() {
|
|
|
653
664
|
rows: allRows,
|
|
654
665
|
total: total // 保持原始的total值
|
|
655
666
|
}));
|
|
656
|
-
case
|
|
657
|
-
_context5.prev =
|
|
667
|
+
case 54:
|
|
668
|
+
_context5.prev = 54;
|
|
658
669
|
_context5.t0 = _context5["catch"](20);
|
|
659
670
|
throw _context5.t0;
|
|
660
|
-
case
|
|
671
|
+
case 57:
|
|
661
672
|
case "end":
|
|
662
673
|
return _context5.stop();
|
|
663
674
|
}
|
|
664
|
-
}, _callee5, null, [[20,
|
|
675
|
+
}, _callee5, null, [[20, 54]]);
|
|
665
676
|
}));
|
|
666
677
|
return _httpBatchRequest.apply(this, arguments);
|
|
667
678
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,46 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import IconQuestion from './components/IconQuestion';
|
|
16
|
-
import IconBell from './components/IconBell';
|
|
17
|
-
import IconSearch from './components/IconSearch';
|
|
18
|
-
import TagCheck from './components/TagCheck';
|
|
19
|
-
import ViewOffice from './components/ViewOffice';
|
|
20
|
-
import ProButton from './components/ProButton';
|
|
21
|
-
import RecordLog from './components/RecordLog';
|
|
22
|
-
import request, { httpGet, httpPut, httpPost, httpDelete, getDict, fetchOptions, httpBatchGet, httpBatchPost, getResourceRight } from './http';
|
|
23
|
-
import BaseService from './service/BaseService';
|
|
1
|
+
/** 组件 */
|
|
2
|
+
export * from './components';
|
|
3
|
+
/** Hooks */
|
|
4
|
+
export * from './hooks';
|
|
5
|
+
/** Http请求 */
|
|
6
|
+
export { default as request } from './http';
|
|
7
|
+
export * from './http';
|
|
8
|
+
/** 基础服务 */
|
|
9
|
+
export { default as BaseService } from './service/BaseService';
|
|
10
|
+
/** 导出进度及完成后自动下载 */
|
|
11
|
+
export { default as exportProcess } from './utils/exportProcess';
|
|
12
|
+
/** Utils方法 */
|
|
13
|
+
export * from './utils';
|
|
14
|
+
/** 主数据请求 */
|
|
24
15
|
import * as mdmRequest from './http/mdmRequest';
|
|
16
|
+
/** Utils 对象 */
|
|
25
17
|
import * as utils from './utils';
|
|
26
|
-
|
|
27
|
-
/** Hooks */
|
|
28
|
-
import useSingle from './hooks/useSingle';
|
|
29
|
-
import useDtl from './hooks/useDtl';
|
|
30
|
-
import usePermission from './hooks/usePermission';
|
|
31
|
-
import useGetState from './hooks/useGetState';
|
|
32
|
-
import useFilterLocal from './hooks/useFilterBack';
|
|
33
|
-
import useBaseDict from './hooks/useBaseDict';
|
|
34
|
-
import useSelectOptions from './hooks/useSelectOptions';
|
|
35
|
-
import showConfirmFun from './hooks/useShowConfirm';
|
|
36
|
-
import useQueue from './hooks/useQueue';
|
|
37
|
-
import { useDict } from './hooks/useDict';
|
|
38
|
-
import useMdm from './hooks/useMdm';
|
|
18
|
+
export { utils, mdmRequest };
|
|
39
19
|
/** Type */
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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, httpBatchGet, httpBatchPost, getResourceRight, utils, useSingle, useDtl, usePermission, useGetState, useFilterLocal, useQueue, useBaseDict, useSelectOptions, useDict, useMdm, showConfirmFun, exportProcess, mdmRequest, ProButton, RecordLog, };
|
|
20
|
+
export type { ApiResponse, TableToolbar, BaseApiType, MethodType } from './typing';
|
|
21
|
+
export type { DtlLyaoutProps } from './components/DtlLayout';
|
|
22
|
+
export type { DescritionCardProps } from './components/DescritionCard';
|
|
23
|
+
export type { PermissionProps } from './components/Permission';
|
|
24
|
+
export type { TDict } from './hooks/useDict';
|
package/lib/index.js
CHANGED
|
@@ -1,39 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import IconQuestion from './components/IconQuestion';
|
|
16
|
-
import IconBell from './components/IconBell';
|
|
17
|
-
import IconSearch from './components/IconSearch';
|
|
18
|
-
import TagCheck from './components/TagCheck';
|
|
19
|
-
import ViewOffice from './components/ViewOffice';
|
|
20
|
-
import ProButton from './components/ProButton';
|
|
21
|
-
import RecordLog from './components/RecordLog';
|
|
22
|
-
import request, { httpGet, httpPut, httpPost, httpDelete, getDict, fetchOptions, httpBatchGet, httpBatchPost, getResourceRight } from './http';
|
|
23
|
-
import BaseService from './service/BaseService';
|
|
1
|
+
/** 组件 */
|
|
2
|
+
export * from './components';
|
|
3
|
+
/** Hooks */
|
|
4
|
+
export * from './hooks';
|
|
5
|
+
/** Http请求 */
|
|
6
|
+
export { default as request } from './http';
|
|
7
|
+
export * from './http';
|
|
8
|
+
/** 基础服务 */
|
|
9
|
+
export { default as BaseService } from './service/BaseService';
|
|
10
|
+
/** 导出进度及完成后自动下载 */
|
|
11
|
+
export { default as exportProcess } from './utils/exportProcess';
|
|
12
|
+
/** Utils方法 */
|
|
13
|
+
export * from './utils';
|
|
14
|
+
/** 主数据请求 */
|
|
24
15
|
import * as mdmRequest from './http/mdmRequest';
|
|
16
|
+
/** Utils 对象 */
|
|
25
17
|
import * as utils from './utils';
|
|
26
|
-
|
|
27
|
-
/** Hooks */
|
|
28
|
-
import useSingle from './hooks/useSingle';
|
|
29
|
-
import useDtl from './hooks/useDtl';
|
|
30
|
-
import usePermission from './hooks/usePermission';
|
|
31
|
-
import useGetState from './hooks/useGetState';
|
|
32
|
-
import useFilterLocal from './hooks/useFilterBack';
|
|
33
|
-
import useBaseDict from './hooks/useBaseDict';
|
|
34
|
-
import useSelectOptions from './hooks/useSelectOptions';
|
|
35
|
-
import showConfirmFun from './hooks/useShowConfirm';
|
|
36
|
-
import useQueue from './hooks/useQueue';
|
|
37
|
-
import { useDict } from './hooks/useDict';
|
|
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, httpBatchGet, httpBatchPost, getResourceRight, utils, useSingle, useDtl, usePermission, useGetState, useFilterLocal, useQueue, useBaseDict, useSelectOptions, useDict, useMdm, showConfirmFun, exportProcess, mdmRequest, ProButton, RecordLog };
|
|
18
|
+
export { utils, mdmRequest };
|
package/lib/utils/clac.d.ts
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Add
|
|
2
|
+
* Add 加法函数,支持多个参数相加
|
|
3
3
|
*
|
|
4
|
-
* @param
|
|
5
|
-
* @
|
|
6
|
-
* @returns
|
|
4
|
+
* @param values 数值参数,支持任意数量
|
|
5
|
+
* @returns 相加结果
|
|
7
6
|
*/
|
|
8
|
-
export declare const add: (
|
|
7
|
+
export declare const add: (...values: (number | string)[]) => string | number;
|
|
9
8
|
/**
|
|
10
|
-
* Sub
|
|
9
|
+
* Sub 减法函数,支持多个参数相减
|
|
11
10
|
*
|
|
12
|
-
* @param
|
|
13
|
-
* @
|
|
14
|
-
* @returns
|
|
11
|
+
* @param values 数值参数,支持任意数量
|
|
12
|
+
* @returns 相减结果
|
|
15
13
|
*/
|
|
16
|
-
export declare const sub: (
|
|
14
|
+
export declare const sub: (...values: (number | string)[]) => string | number;
|
|
17
15
|
/**
|
|
18
|
-
* Mul
|
|
16
|
+
* Mul 乘法函数,支持多个参数相乘
|
|
19
17
|
*
|
|
20
|
-
* @param
|
|
21
|
-
* @
|
|
22
|
-
* @returns
|
|
18
|
+
* @param values 数值参数,支持任意数量
|
|
19
|
+
* @returns 相乘结果
|
|
23
20
|
*/
|
|
24
|
-
export declare const mul: (
|
|
21
|
+
export declare const mul: (...values: (number | string)[]) => string | number;
|
|
25
22
|
/**
|
|
26
|
-
* Div
|
|
23
|
+
* Div 除法函数,支持多个参数相除
|
|
27
24
|
*
|
|
28
|
-
* @param
|
|
29
|
-
* @
|
|
30
|
-
* @returns
|
|
25
|
+
* @param values 数值参数,支持任意数量
|
|
26
|
+
* @returns 相除结果
|
|
31
27
|
*/
|
|
32
|
-
export declare const div: (
|
|
28
|
+
export declare const div: (...values: (number | string)[]) => string | number;
|
package/lib/utils/clac.js
CHANGED
|
@@ -1,41 +1,71 @@
|
|
|
1
1
|
import Big from 'big.js';
|
|
2
2
|
/**
|
|
3
|
-
* Add
|
|
3
|
+
* Add 加法函数,支持多个参数相加
|
|
4
4
|
*
|
|
5
|
-
* @param
|
|
6
|
-
* @
|
|
7
|
-
* @returns
|
|
5
|
+
* @param values 数值参数,支持任意数量
|
|
6
|
+
* @returns 相加结果
|
|
8
7
|
*/
|
|
9
|
-
export var add = function add(
|
|
10
|
-
|
|
8
|
+
export var add = function add() {
|
|
9
|
+
for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
10
|
+
values[_key] = arguments[_key];
|
|
11
|
+
}
|
|
12
|
+
if (values.length === 0) return 0;
|
|
13
|
+
if (values.length === 1) return Number(values[0]) || 0;
|
|
14
|
+
return values.reduce(function (acc, cur) {
|
|
15
|
+
return Number(new Big(Number(acc)).plus(Number(cur)));
|
|
16
|
+
}, 0);
|
|
11
17
|
};
|
|
12
18
|
/**
|
|
13
|
-
* Sub
|
|
19
|
+
* Sub 减法函数,支持多个参数相减
|
|
14
20
|
*
|
|
15
|
-
* @param
|
|
16
|
-
* @
|
|
17
|
-
* @returns
|
|
21
|
+
* @param values 数值参数,支持任意数量
|
|
22
|
+
* @returns 相减结果
|
|
18
23
|
*/
|
|
19
|
-
export var sub = function sub(
|
|
20
|
-
|
|
24
|
+
export var sub = function sub() {
|
|
25
|
+
for (var _len2 = arguments.length, values = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
26
|
+
values[_key2] = arguments[_key2];
|
|
27
|
+
}
|
|
28
|
+
if (values.length === 0) return 0;
|
|
29
|
+
if (values.length === 1) return Number(values[0]) || 0;
|
|
30
|
+
return values.reduce(function (acc, cur) {
|
|
31
|
+
return Number(new Big(Number(acc)).minus(Number(cur)));
|
|
32
|
+
});
|
|
21
33
|
};
|
|
22
34
|
/**
|
|
23
|
-
* Mul
|
|
35
|
+
* Mul 乘法函数,支持多个参数相乘
|
|
24
36
|
*
|
|
25
|
-
* @param
|
|
26
|
-
* @
|
|
27
|
-
* @returns
|
|
37
|
+
* @param values 数值参数,支持任意数量
|
|
38
|
+
* @returns 相乘结果
|
|
28
39
|
*/
|
|
29
|
-
export var mul = function mul(
|
|
30
|
-
|
|
40
|
+
export var mul = function mul() {
|
|
41
|
+
for (var _len3 = arguments.length, values = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
42
|
+
values[_key3] = arguments[_key3];
|
|
43
|
+
}
|
|
44
|
+
if (values.length === 0) return 0;
|
|
45
|
+
if (values.length === 1) return Number(values[0]) || 0;
|
|
46
|
+
return values.reduce(function (acc, cur) {
|
|
47
|
+
return Number(new Big(Number(acc)).times(Number(cur)));
|
|
48
|
+
}, 1); // 乘法从1开始
|
|
31
49
|
};
|
|
32
50
|
/**
|
|
33
|
-
* Div
|
|
51
|
+
* Div 除法函数,支持多个参数相除
|
|
34
52
|
*
|
|
35
|
-
* @param
|
|
36
|
-
* @
|
|
37
|
-
* @returns
|
|
53
|
+
* @param values 数值参数,支持任意数量
|
|
54
|
+
* @returns 相除结果
|
|
38
55
|
*/
|
|
39
|
-
export var div = function div(
|
|
40
|
-
|
|
56
|
+
export var div = function div() {
|
|
57
|
+
for (var _len4 = arguments.length, values = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
58
|
+
values[_key4] = arguments[_key4];
|
|
59
|
+
}
|
|
60
|
+
if (values.length === 0) return 0;
|
|
61
|
+
if (values.length === 1) return Number(values[0]) || 0;
|
|
62
|
+
// 检查除数是否为零
|
|
63
|
+
for (var i = 1; i < values.length; i++) {
|
|
64
|
+
if (Number(values[i]) === 0) {
|
|
65
|
+
throw new Error('除数不能为零');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return values.reduce(function (acc, cur) {
|
|
69
|
+
return Number(new Big(Number(acc)).div(Number(cur)));
|
|
70
|
+
});
|
|
41
71
|
};
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -28,10 +28,10 @@ export declare const setUrlQuery: (url: string, keyvals?: Record<string, any>) =
|
|
|
28
28
|
*
|
|
29
29
|
* @param url 原url,以 / 打头
|
|
30
30
|
* @param gatewayKey 设置gateway关键字 默认为 'gateway'
|
|
31
|
-
* @param
|
|
31
|
+
* @param defaultGateway 默认网关 ''
|
|
32
32
|
* @returns
|
|
33
33
|
*/
|
|
34
|
-
export declare const toGatewayUrl: (url: string, gatewayKey?: string,
|
|
34
|
+
export declare const toGatewayUrl: (url: string, gatewayKey?: string, defaultGateway?: string) => string;
|
|
35
35
|
/**
|
|
36
36
|
* 设置文档title
|
|
37
37
|
*
|
|
@@ -75,14 +75,14 @@ export declare const setCache: (key: string, data: any, session?: boolean) => vo
|
|
|
75
75
|
* @param {boolean} session 从 sessionStorage 取数还是从 localStorage 中取数 默认从 localStorage
|
|
76
76
|
* @returns 关键字对应的值
|
|
77
77
|
*/
|
|
78
|
-
export declare const getCache:
|
|
78
|
+
export declare const getCache: any;
|
|
79
79
|
/**
|
|
80
80
|
* 读取本地缓存,优先从sessionStorage 取,取不到时再从 localStorage取
|
|
81
81
|
*
|
|
82
82
|
* @param key
|
|
83
83
|
* @returns
|
|
84
84
|
*/
|
|
85
|
-
export declare const getCacheSessionFirst: (key: string) =>
|
|
85
|
+
export declare const getCacheSessionFirst: (key: string) => any;
|
|
86
86
|
/**
|
|
87
87
|
* @param key 关键字,不传清除所有
|
|
88
88
|
* @param session 是否session storage , 默认 localStorage
|
|
@@ -226,5 +226,6 @@ export declare const urlDownloadDomain: (url: string) => string;
|
|
|
226
226
|
*
|
|
227
227
|
* @param url 文件地址
|
|
228
228
|
* @param fileName 文件名
|
|
229
|
+
* @param isBlank 是否新开窗口下载,默认新开窗口,不影响原页面展示
|
|
229
230
|
*/
|
|
230
|
-
export declare const downloadFile: (url: string, fileName?: string | undefined) => void;
|
|
231
|
+
export declare const downloadFile: (url: string, fileName?: string | undefined, isBlank?: boolean) => void;
|
package/lib/utils/index.js
CHANGED
|
@@ -82,22 +82,26 @@ export var setUrlQuery = function setUrlQuery(url) {
|
|
|
82
82
|
*
|
|
83
83
|
* @param url 原url,以 / 打头
|
|
84
84
|
* @param gatewayKey 设置gateway关键字 默认为 'gateway'
|
|
85
|
-
* @param
|
|
85
|
+
* @param defaultGateway 默认网关 ''
|
|
86
86
|
* @returns
|
|
87
87
|
*/
|
|
88
88
|
export var toGatewayUrl = function toGatewayUrl(url) {
|
|
89
89
|
var gatewayKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'gateway';
|
|
90
|
-
var
|
|
90
|
+
var defaultGateway = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
91
|
+
url = url || '';
|
|
91
92
|
// 如果url带有名称,不需要设置网关
|
|
92
93
|
if (url.startsWith('http://') || url.startsWith('https://') || url.startsWith('//')) return url;
|
|
94
|
+
if (url.startsWith('/lesoon/') || url.startsWith('/petrel/')) {
|
|
95
|
+
return location.origin + url;
|
|
96
|
+
}
|
|
93
97
|
// 读取项目的默认网关
|
|
94
|
-
if (!
|
|
98
|
+
if (!defaultGateway) {
|
|
95
99
|
var _top;
|
|
96
100
|
// @ts-ignore
|
|
97
|
-
|
|
101
|
+
defaultGateway = window.defaultGateway || ((_top = top) === null || _top === void 0 ? void 0 : _top.window.lsMainGateway) || '';
|
|
98
102
|
}
|
|
99
103
|
// 取网关的顺序, 1.取url里的传参,2.取资源里的网关, 3. 取项目里设置的默认网关
|
|
100
|
-
var gateway = getUrlQuery(gatewayKey) || getResourceProps(gatewayKey) ||
|
|
104
|
+
var gateway = getUrlQuery(gatewayKey) || getResourceProps(gatewayKey) || defaultGateway;
|
|
101
105
|
// 如果没有找到网关,直接从项目配置中取网关
|
|
102
106
|
if (!gateway) {
|
|
103
107
|
var projects = JSON.parse(sessionStorage.getItem('lsProjects') || '[]');
|
|
@@ -113,8 +117,7 @@ export var toGatewayUrl = function toGatewayUrl(url) {
|
|
|
113
117
|
}
|
|
114
118
|
// 网关加上域名,避免多次设置
|
|
115
119
|
if (gateway && !gateway.startsWith('http')) {
|
|
116
|
-
|
|
117
|
-
gateway = h + gateway;
|
|
120
|
+
gateway = location.origin + gateway;
|
|
118
121
|
}
|
|
119
122
|
return gateway + url;
|
|
120
123
|
};
|
|
@@ -490,12 +493,17 @@ export var urlDownloadDomain = function urlDownloadDomain(url) {
|
|
|
490
493
|
*
|
|
491
494
|
* @param url 文件地址
|
|
492
495
|
* @param fileName 文件名
|
|
496
|
+
* @param isBlank 是否新开窗口下载,默认新开窗口,不影响原页面展示
|
|
493
497
|
*/
|
|
494
498
|
export var downloadFile = function downloadFile(url, fileName) {
|
|
499
|
+
var isBlank = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
495
500
|
var a = document.createElement('a');
|
|
496
501
|
url = urlDownloadDomain(url);
|
|
497
502
|
a.href = url;
|
|
498
|
-
|
|
503
|
+
if (isBlank) {
|
|
504
|
+
a.target = '_blank'; // 新开屏有闪烁,但不会导致下载文件不存在或无法访问时原始页面出错。
|
|
505
|
+
}
|
|
506
|
+
|
|
499
507
|
if (fileName) {
|
|
500
508
|
a.setAttribute('download', fileName);
|
|
501
509
|
}
|