ztxkutils 1.8.7 → 1.8.8
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/index.js +1 -1
- package/dist/request-6de9e809.js +2659 -0
- package/dist/{request-da082897.js → request-7944ad16.js} +2 -2
- package/dist/request-ae61b772.js +2663 -0
- package/dist/request.js +1 -1
- package/dist/stompClient.js +2 -2
- package/dist/tools-3340e70f.js +147 -0
- package/dist/tools-46a946e5.js +183 -0
- package/dist/tools-b75fec50.js +196 -0
- package/dist/tools-d11ca423.js +170 -0
- package/dist/tools-e073f57e.js +173 -0
- package/dist/tslib.es6-79a6072b.js +65 -0
- package/dist/validate-35adc5a8.js +60 -0
- package/dist/validate-b4c69167.js +60 -0
- package/package.json +1 -1
- package/dist/authority-b230d455.js +0 -327
- package/dist/reqUrl-4dc7964e.js +0 -48
- package/dist/reqUrl-4ece5399.js +0 -48
package/dist/request.js
CHANGED
package/dist/stompClient.js
CHANGED
@@ -30,9 +30,9 @@ var StompClient = /** @class */ (function () {
|
|
30
30
|
};
|
31
31
|
// 心跳检测 stompjs 底层使用window.setInterval() 定期发送心跳检测
|
32
32
|
this.client.heartbeat.outgoing =
|
33
|
-
(_b = (_a = this.connectWsConfig.heartbeat) === null || _a === void 0 ? void 0 : _a.outgoing) !== null && _b !== void 0 ? _b :
|
33
|
+
(_b = (_a = this.connectWsConfig.heartbeat) === null || _a === void 0 ? void 0 : _a.outgoing) !== null && _b !== void 0 ? _b : 5000; // 客户端将每5000ms发送一次心跳
|
34
34
|
this.client.heartbeat.incoming =
|
35
|
-
(_d = (_c = this.connectWsConfig.heartbeat) === null || _c === void 0 ? void 0 : _c.incoming) !== null && _d !== void 0 ? _d :
|
35
|
+
(_d = (_c = this.connectWsConfig.heartbeat) === null || _c === void 0 ? void 0 : _c.incoming) !== null && _d !== void 0 ? _d : 5000; // 客户端不希望从服务器接收心跳
|
36
36
|
this.client.connect({},
|
37
37
|
// 连接成功回调
|
38
38
|
function () {
|
@@ -0,0 +1,147 @@
|
|
1
|
+
import { _ as __assign } from './tslib.es6-79a6072b.js';
|
2
|
+
import dayjs from 'dayjs';
|
3
|
+
import { round, plus, minus, times, divide } from 'number-precision';
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @description 时间格式转换
|
7
|
+
*/
|
8
|
+
function timeTransfrom(timeParams) {
|
9
|
+
var _a, _b, _c, _d, _e;
|
10
|
+
var params = timeParams.params, fromKey = timeParams.fromKey, toKey = timeParams.toKey, _f = timeParams.type, type = _f === void 0 ? 'string' : _f;
|
11
|
+
var copyParams = __assign({}, params);
|
12
|
+
for (var i = 0; i < fromKey.length; i++) {
|
13
|
+
var fromKeyItem = fromKey[i];
|
14
|
+
var toKeyItem = toKey[i];
|
15
|
+
// 从一个键转换成两个键
|
16
|
+
if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'object') {
|
17
|
+
if (type === 'string' && copyParams[fromKeyItem]) {
|
18
|
+
var _g = copyParams[fromKeyItem], startMoment = _g[0], endMoment = _g[1];
|
19
|
+
var start = void 0, end = void 0;
|
20
|
+
if (dayjs.isDayjs(startMoment)) {
|
21
|
+
start = startMoment.format('YYYY-MM-DD');
|
22
|
+
}
|
23
|
+
if (dayjs.isDayjs(endMoment)) {
|
24
|
+
end = endMoment.format('YYYY-MM-DD');
|
25
|
+
}
|
26
|
+
delete copyParams[fromKeyItem];
|
27
|
+
copyParams = __assign(__assign({}, copyParams), (_a = {}, _a[toKeyItem[0]] = start, _a[toKeyItem[1]] = end, _a));
|
28
|
+
}
|
29
|
+
else {
|
30
|
+
copyParams = __assign(__assign({}, copyParams), (_b = {}, _b[toKeyItem[0]] = undefined, _b[toKeyItem[1]] = undefined, _b));
|
31
|
+
}
|
32
|
+
}
|
33
|
+
// 从一个键转换成一个键
|
34
|
+
if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'string') {
|
35
|
+
if (type === 'string') {
|
36
|
+
var _dayjsObj = copyParams[fromKeyItem];
|
37
|
+
var start = void 0;
|
38
|
+
if (dayjs.isDayjs(_dayjsObj)) {
|
39
|
+
start = _dayjsObj.format('YYYY-MM-DD');
|
40
|
+
}
|
41
|
+
delete copyParams[fromKeyItem];
|
42
|
+
copyParams = __assign(__assign({}, copyParams), (_c = {}, _c[toKeyItem] = start, _c));
|
43
|
+
}
|
44
|
+
if (type === 'object') {
|
45
|
+
var start = copyParams[fromKeyItem]
|
46
|
+
? dayjs(copyParams[fromKeyItem])
|
47
|
+
: undefined;
|
48
|
+
delete copyParams[fromKeyItem];
|
49
|
+
copyParams = __assign(__assign({}, copyParams), (_d = {}, _d[toKeyItem] = start, _d));
|
50
|
+
}
|
51
|
+
}
|
52
|
+
// 从两个键转换成一个键
|
53
|
+
if (typeof fromKeyItem === 'object' && typeof toKeyItem === 'string') {
|
54
|
+
if (type === 'object') {
|
55
|
+
var startMoment = fromKeyItem[0], endMoment = fromKeyItem[1];
|
56
|
+
var intime = copyParams[toKeyItem] || [null, null];
|
57
|
+
if (copyParams[startMoment]) {
|
58
|
+
intime[0] = dayjs(copyParams[startMoment]);
|
59
|
+
delete copyParams[startMoment];
|
60
|
+
}
|
61
|
+
if (copyParams[endMoment]) {
|
62
|
+
intime[1] = dayjs(copyParams[endMoment]);
|
63
|
+
delete copyParams[endMoment];
|
64
|
+
}
|
65
|
+
copyParams = __assign(__assign({}, copyParams), (_e = {}, _e[toKeyItem] = intime, _e));
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
return copyParams;
|
70
|
+
}
|
71
|
+
/**
|
72
|
+
* @description 精确四舍五入后保留几位小数
|
73
|
+
*/
|
74
|
+
function exactRound(num, ratio) {
|
75
|
+
var typeNum = typeof num;
|
76
|
+
if (typeNum !== 'number' && typeNum !== 'string') {
|
77
|
+
return num;
|
78
|
+
}
|
79
|
+
try {
|
80
|
+
return round(num, ratio).toFixed(ratio);
|
81
|
+
}
|
82
|
+
catch (err) {
|
83
|
+
console.error(err);
|
84
|
+
return num;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
/**
|
88
|
+
* @description 添加千分符符号
|
89
|
+
*/
|
90
|
+
function toThousand(num) {
|
91
|
+
var typeNum = typeof num;
|
92
|
+
if (typeNum !== 'number' && typeNum !== 'string') {
|
93
|
+
return num;
|
94
|
+
}
|
95
|
+
var str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
|
96
|
+
return str;
|
97
|
+
}
|
98
|
+
/**
|
99
|
+
* @description 去除指定字符串
|
100
|
+
*/
|
101
|
+
function clearAssignStr(str, originalStr) {
|
102
|
+
if (!originalStr) {
|
103
|
+
return originalStr;
|
104
|
+
}
|
105
|
+
if (originalStr.startsWith(str)) {
|
106
|
+
return originalStr.replace(str, '');
|
107
|
+
}
|
108
|
+
return originalStr;
|
109
|
+
}
|
110
|
+
/**
|
111
|
+
* @description 下载重命名
|
112
|
+
*/
|
113
|
+
function loadFileRename(fileUrl, fileName) {
|
114
|
+
var xhr = new XMLHttpRequest();
|
115
|
+
xhr.open('GET', fileUrl, true);
|
116
|
+
xhr.responseType = 'blob';
|
117
|
+
xhr.onload = function () {
|
118
|
+
if (xhr.status === 200) {
|
119
|
+
var link = document.createElement('a');
|
120
|
+
var body = document.querySelector('body');
|
121
|
+
link.href = window.URL.createObjectURL(xhr.response);
|
122
|
+
link.download = fileName;
|
123
|
+
// fix Firefox
|
124
|
+
link.style.display = 'none';
|
125
|
+
body.appendChild(link);
|
126
|
+
link.click();
|
127
|
+
body.removeChild(link);
|
128
|
+
window.URL.revokeObjectURL(link.href);
|
129
|
+
}
|
130
|
+
};
|
131
|
+
xhr.send();
|
132
|
+
}
|
133
|
+
|
134
|
+
var tools = /*#__PURE__*/Object.freeze({
|
135
|
+
__proto__: null,
|
136
|
+
timeTransfrom: timeTransfrom,
|
137
|
+
plus: plus,
|
138
|
+
minus: minus,
|
139
|
+
times: times,
|
140
|
+
divide: divide,
|
141
|
+
exactRound: exactRound,
|
142
|
+
toThousand: toThousand,
|
143
|
+
clearAssignStr: clearAssignStr,
|
144
|
+
loadFileRename: loadFileRename
|
145
|
+
});
|
146
|
+
|
147
|
+
export { timeTransfrom as a, toThousand as b, clearAssignStr as c, exactRound as e, loadFileRename as l, tools as t };
|
@@ -0,0 +1,183 @@
|
|
1
|
+
import { _ as __assign, a as __spreadArray } from './tslib.es6-b9033aad.js';
|
2
|
+
import dayjs from 'dayjs';
|
3
|
+
import { divide as divide$1, round, plus, minus, times } from 'number-precision';
|
4
|
+
import { Modal } from 'ztxkui';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @description 时间格式转换
|
8
|
+
*/
|
9
|
+
function timeTransfrom(timeParams) {
|
10
|
+
var _a, _b, _c, _d, _e;
|
11
|
+
var params = timeParams.params, fromKey = timeParams.fromKey, toKey = timeParams.toKey, _f = timeParams.type, type = _f === void 0 ? 'string' : _f;
|
12
|
+
var copyParams = __assign({}, params);
|
13
|
+
for (var i = 0; i < fromKey.length; i++) {
|
14
|
+
var fromKeyItem = fromKey[i];
|
15
|
+
var toKeyItem = toKey[i];
|
16
|
+
// 从一个键转换成两个键
|
17
|
+
if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'object') {
|
18
|
+
if (type === 'string' && copyParams[fromKeyItem]) {
|
19
|
+
var _g = copyParams[fromKeyItem], startMoment = _g[0], endMoment = _g[1];
|
20
|
+
var start = void 0, end = void 0;
|
21
|
+
if (dayjs.isDayjs(startMoment)) {
|
22
|
+
start = startMoment.format('YYYY-MM-DD');
|
23
|
+
}
|
24
|
+
if (dayjs.isDayjs(endMoment)) {
|
25
|
+
end = endMoment.format('YYYY-MM-DD');
|
26
|
+
}
|
27
|
+
delete copyParams[fromKeyItem];
|
28
|
+
copyParams = __assign(__assign({}, copyParams), (_a = {}, _a[toKeyItem[0]] = start, _a[toKeyItem[1]] = end, _a));
|
29
|
+
}
|
30
|
+
else {
|
31
|
+
copyParams = __assign(__assign({}, copyParams), (_b = {}, _b[toKeyItem[0]] = undefined, _b[toKeyItem[1]] = undefined, _b));
|
32
|
+
}
|
33
|
+
}
|
34
|
+
// 从一个键转换成一个键
|
35
|
+
if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'string') {
|
36
|
+
if (type === 'string') {
|
37
|
+
var _dayjsObj = copyParams[fromKeyItem];
|
38
|
+
var start = void 0;
|
39
|
+
if (dayjs.isDayjs(_dayjsObj)) {
|
40
|
+
start = _dayjsObj.format('YYYY-MM-DD');
|
41
|
+
}
|
42
|
+
delete copyParams[fromKeyItem];
|
43
|
+
copyParams = __assign(__assign({}, copyParams), (_c = {}, _c[toKeyItem] = start, _c));
|
44
|
+
}
|
45
|
+
if (type === 'object') {
|
46
|
+
var start = copyParams[fromKeyItem]
|
47
|
+
? dayjs(copyParams[fromKeyItem])
|
48
|
+
: undefined;
|
49
|
+
delete copyParams[fromKeyItem];
|
50
|
+
copyParams = __assign(__assign({}, copyParams), (_d = {}, _d[toKeyItem] = start, _d));
|
51
|
+
}
|
52
|
+
}
|
53
|
+
// 从两个键转换成一个键
|
54
|
+
if (typeof fromKeyItem === 'object' && typeof toKeyItem === 'string') {
|
55
|
+
if (type === 'object') {
|
56
|
+
var startMoment = fromKeyItem[0], endMoment = fromKeyItem[1];
|
57
|
+
var intime = copyParams[toKeyItem] || [null, null];
|
58
|
+
if (copyParams[startMoment]) {
|
59
|
+
intime[0] = dayjs(copyParams[startMoment]);
|
60
|
+
delete copyParams[startMoment];
|
61
|
+
}
|
62
|
+
if (copyParams[endMoment]) {
|
63
|
+
intime[1] = dayjs(copyParams[endMoment]);
|
64
|
+
delete copyParams[endMoment];
|
65
|
+
}
|
66
|
+
copyParams = __assign(__assign({}, copyParams), (_e = {}, _e[toKeyItem] = intime, _e));
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
return copyParams;
|
71
|
+
}
|
72
|
+
function divide(num1, num2) {
|
73
|
+
var others = [];
|
74
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
75
|
+
others[_i - 2] = arguments[_i];
|
76
|
+
}
|
77
|
+
try {
|
78
|
+
return divide$1.apply(void 0, __spreadArray([num1, num2], others));
|
79
|
+
}
|
80
|
+
catch (err) {
|
81
|
+
console.log(err);
|
82
|
+
return 0;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
/**
|
86
|
+
* @description 精确四舍五入后保留几位小数
|
87
|
+
*/
|
88
|
+
function exactRound(num, ratio) {
|
89
|
+
var typeNum = typeof num;
|
90
|
+
if (typeNum !== 'number' && typeNum !== 'string') {
|
91
|
+
return num;
|
92
|
+
}
|
93
|
+
try {
|
94
|
+
return round(num, ratio).toFixed(ratio);
|
95
|
+
}
|
96
|
+
catch (err) {
|
97
|
+
console.error(err);
|
98
|
+
return num;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
/**
|
102
|
+
* @description 添加千分符符号
|
103
|
+
*/
|
104
|
+
function toThousand(num) {
|
105
|
+
var typeNum = typeof num;
|
106
|
+
if (typeNum !== 'number' && typeNum !== 'string') {
|
107
|
+
return num;
|
108
|
+
}
|
109
|
+
var str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
|
110
|
+
return str;
|
111
|
+
}
|
112
|
+
/**
|
113
|
+
* @description 去除指定字符串
|
114
|
+
*/
|
115
|
+
function clearAssignStr(str, originalStr) {
|
116
|
+
if (!originalStr) {
|
117
|
+
return originalStr;
|
118
|
+
}
|
119
|
+
if (originalStr.startsWith(str)) {
|
120
|
+
return originalStr.replace(str, '');
|
121
|
+
}
|
122
|
+
return originalStr;
|
123
|
+
}
|
124
|
+
/**
|
125
|
+
* @description 下载重命名
|
126
|
+
*/
|
127
|
+
function loadFileRename(fileUrl, fileName) {
|
128
|
+
var xhr = new XMLHttpRequest();
|
129
|
+
xhr.open('GET', fileUrl, true);
|
130
|
+
xhr.responseType = 'blob';
|
131
|
+
xhr.onload = function () {
|
132
|
+
if (xhr.status === 200) {
|
133
|
+
var link = document.createElement('a');
|
134
|
+
var body = document.querySelector('body');
|
135
|
+
link.href = window.URL.createObjectURL(xhr.response);
|
136
|
+
link.download = fileName;
|
137
|
+
// fix Firefox
|
138
|
+
link.style.display = 'none';
|
139
|
+
body.appendChild(link);
|
140
|
+
link.click();
|
141
|
+
body.removeChild(link);
|
142
|
+
window.URL.revokeObjectURL(link.href);
|
143
|
+
}
|
144
|
+
};
|
145
|
+
xhr.send();
|
146
|
+
}
|
147
|
+
/**
|
148
|
+
* @description 当有依赖改变时,提示用户
|
149
|
+
*/
|
150
|
+
function openTipModal(callback, data, tipTitle) {
|
151
|
+
if (Array.isArray(data) && data.length > 0) {
|
152
|
+
Modal.confirm({
|
153
|
+
content: tipTitle || '切换将清空已选数据!',
|
154
|
+
okText: '确认',
|
155
|
+
cancelText: '取消',
|
156
|
+
onCancel: function () {
|
157
|
+
callback && callback(false);
|
158
|
+
},
|
159
|
+
onOk: function () {
|
160
|
+
callback && callback(true);
|
161
|
+
},
|
162
|
+
});
|
163
|
+
}
|
164
|
+
else {
|
165
|
+
callback && callback(true);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
var tools = /*#__PURE__*/Object.freeze({
|
170
|
+
__proto__: null,
|
171
|
+
timeTransfrom: timeTransfrom,
|
172
|
+
plus: plus,
|
173
|
+
minus: minus,
|
174
|
+
times: times,
|
175
|
+
divide: divide,
|
176
|
+
exactRound: exactRound,
|
177
|
+
toThousand: toThousand,
|
178
|
+
clearAssignStr: clearAssignStr,
|
179
|
+
loadFileRename: loadFileRename,
|
180
|
+
openTipModal: openTipModal
|
181
|
+
});
|
182
|
+
|
183
|
+
export { timeTransfrom as a, toThousand as b, clearAssignStr as c, divide as d, exactRound as e, loadFileRename as l, openTipModal as o, tools as t };
|
@@ -0,0 +1,196 @@
|
|
1
|
+
import { _ as __assign, a as __spreadArray } from './tslib.es6-b9033aad.js';
|
2
|
+
import dayjs from 'dayjs';
|
3
|
+
import { divide as divide$1, round, plus, minus, times } from 'number-precision';
|
4
|
+
import { Modal } from 'ztxkui';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @description 时间格式转换
|
8
|
+
*/
|
9
|
+
function timeTransfrom(timeParams) {
|
10
|
+
var _a, _b, _c, _d, _e;
|
11
|
+
var params = timeParams.params, fromKey = timeParams.fromKey, toKey = timeParams.toKey, _f = timeParams.type, type = _f === void 0 ? 'string' : _f;
|
12
|
+
var copyParams = __assign({}, params);
|
13
|
+
for (var i = 0; i < fromKey.length; i++) {
|
14
|
+
var fromKeyItem = fromKey[i];
|
15
|
+
var toKeyItem = toKey[i];
|
16
|
+
// 从一个键转换成两个键
|
17
|
+
if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'object') {
|
18
|
+
if (type === 'string' && copyParams[fromKeyItem]) {
|
19
|
+
var _g = copyParams[fromKeyItem], startMoment = _g[0], endMoment = _g[1];
|
20
|
+
var start = void 0, end = void 0;
|
21
|
+
if (dayjs.isDayjs(startMoment)) {
|
22
|
+
start = startMoment.format('YYYY-MM-DD');
|
23
|
+
}
|
24
|
+
if (dayjs.isDayjs(endMoment)) {
|
25
|
+
end = endMoment.format('YYYY-MM-DD');
|
26
|
+
}
|
27
|
+
delete copyParams[fromKeyItem];
|
28
|
+
copyParams = __assign(__assign({}, copyParams), (_a = {}, _a[toKeyItem[0]] = start, _a[toKeyItem[1]] = end, _a));
|
29
|
+
}
|
30
|
+
else {
|
31
|
+
copyParams = __assign(__assign({}, copyParams), (_b = {}, _b[toKeyItem[0]] = undefined, _b[toKeyItem[1]] = undefined, _b));
|
32
|
+
}
|
33
|
+
}
|
34
|
+
// 从一个键转换成一个键
|
35
|
+
if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'string') {
|
36
|
+
if (type === 'string') {
|
37
|
+
var _dayjsObj = copyParams[fromKeyItem];
|
38
|
+
var start = void 0;
|
39
|
+
if (dayjs.isDayjs(_dayjsObj)) {
|
40
|
+
start = _dayjsObj.format('YYYY-MM-DD');
|
41
|
+
}
|
42
|
+
delete copyParams[fromKeyItem];
|
43
|
+
copyParams = __assign(__assign({}, copyParams), (_c = {}, _c[toKeyItem] = start, _c));
|
44
|
+
}
|
45
|
+
if (type === 'object') {
|
46
|
+
var start = copyParams[fromKeyItem]
|
47
|
+
? dayjs(copyParams[fromKeyItem])
|
48
|
+
: undefined;
|
49
|
+
delete copyParams[fromKeyItem];
|
50
|
+
copyParams = __assign(__assign({}, copyParams), (_d = {}, _d[toKeyItem] = start, _d));
|
51
|
+
}
|
52
|
+
}
|
53
|
+
// 从两个键转换成一个键
|
54
|
+
if (typeof fromKeyItem === 'object' && typeof toKeyItem === 'string') {
|
55
|
+
if (type === 'object') {
|
56
|
+
var startMoment = fromKeyItem[0], endMoment = fromKeyItem[1];
|
57
|
+
var intime = copyParams[toKeyItem] || [null, null];
|
58
|
+
if (copyParams[startMoment]) {
|
59
|
+
intime[0] = dayjs(copyParams[startMoment]);
|
60
|
+
delete copyParams[startMoment];
|
61
|
+
}
|
62
|
+
if (copyParams[endMoment]) {
|
63
|
+
intime[1] = dayjs(copyParams[endMoment]);
|
64
|
+
delete copyParams[endMoment];
|
65
|
+
}
|
66
|
+
copyParams = __assign(__assign({}, copyParams), (_e = {}, _e[toKeyItem] = intime, _e));
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
return copyParams;
|
71
|
+
}
|
72
|
+
function divide(num1, num2) {
|
73
|
+
var others = [];
|
74
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
75
|
+
others[_i - 2] = arguments[_i];
|
76
|
+
}
|
77
|
+
try {
|
78
|
+
return divide$1.apply(void 0, __spreadArray([num1, num2], others));
|
79
|
+
}
|
80
|
+
catch (err) {
|
81
|
+
console.log(err);
|
82
|
+
return 0;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
/**
|
86
|
+
* @description 精确四舍五入后保留几位小数
|
87
|
+
*/
|
88
|
+
function exactRound(num, ratio) {
|
89
|
+
var typeNum = typeof num;
|
90
|
+
if (typeNum !== 'number' && typeNum !== 'string') {
|
91
|
+
return num;
|
92
|
+
}
|
93
|
+
try {
|
94
|
+
return round(num, ratio).toFixed(ratio);
|
95
|
+
}
|
96
|
+
catch (err) {
|
97
|
+
console.error(err);
|
98
|
+
return num;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
/**
|
102
|
+
* @description 添加千分符符号
|
103
|
+
*/
|
104
|
+
function toThousand(num) {
|
105
|
+
var typeNum = typeof num;
|
106
|
+
if (typeNum !== 'number' && typeNum !== 'string') {
|
107
|
+
return num;
|
108
|
+
}
|
109
|
+
var str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
|
110
|
+
return str;
|
111
|
+
}
|
112
|
+
/**
|
113
|
+
* @description 去除指定字符串
|
114
|
+
*/
|
115
|
+
function clearAssignStr(str, originalStr) {
|
116
|
+
if (!originalStr) {
|
117
|
+
return originalStr;
|
118
|
+
}
|
119
|
+
if (originalStr.startsWith(str)) {
|
120
|
+
return originalStr.replace(str, '');
|
121
|
+
}
|
122
|
+
return originalStr;
|
123
|
+
}
|
124
|
+
/**
|
125
|
+
* @description 下载重命名
|
126
|
+
*/
|
127
|
+
function loadFileRename(fileUrl, fileName) {
|
128
|
+
var xhr = new XMLHttpRequest();
|
129
|
+
xhr.open('GET', fileUrl, true);
|
130
|
+
xhr.responseType = 'blob';
|
131
|
+
xhr.onload = function () {
|
132
|
+
if (xhr.status === 200) {
|
133
|
+
var link = document.createElement('a');
|
134
|
+
var body = document.querySelector('body');
|
135
|
+
link.href = window.URL.createObjectURL(xhr.response);
|
136
|
+
link.download = fileName;
|
137
|
+
// fix Firefox
|
138
|
+
link.style.display = 'none';
|
139
|
+
body.appendChild(link);
|
140
|
+
link.click();
|
141
|
+
body.removeChild(link);
|
142
|
+
window.URL.revokeObjectURL(link.href);
|
143
|
+
}
|
144
|
+
};
|
145
|
+
xhr.send();
|
146
|
+
}
|
147
|
+
/**
|
148
|
+
* @description 当有依赖改变时,提示用户
|
149
|
+
*/
|
150
|
+
function openTipModal(callback, data, tipTitle) {
|
151
|
+
if (Array.isArray(data) && data.length > 0) {
|
152
|
+
Modal.confirm({
|
153
|
+
content: tipTitle || '切换将清空已选数据!',
|
154
|
+
okText: '确认',
|
155
|
+
cancelText: '取消',
|
156
|
+
onCancel: function () {
|
157
|
+
callback && callback(false);
|
158
|
+
},
|
159
|
+
onOk: function () {
|
160
|
+
callback && callback(true);
|
161
|
+
},
|
162
|
+
});
|
163
|
+
}
|
164
|
+
else {
|
165
|
+
callback && callback(true);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
/**
|
169
|
+
* @description 文件大小提示转换
|
170
|
+
*/
|
171
|
+
function transformFileSize(value) {
|
172
|
+
if (value < 1024) {
|
173
|
+
return round(value, 2).toFixed(2) + 'B';
|
174
|
+
}
|
175
|
+
else if (value < 1024 * 1024) {
|
176
|
+
return round(divide(value, 1024), 2).toFixed(2) + 'KB';
|
177
|
+
}
|
178
|
+
return round(divide(value, 1024, 1024), 2).toFixed(2) + 'MB';
|
179
|
+
}
|
180
|
+
|
181
|
+
var tools = /*#__PURE__*/Object.freeze({
|
182
|
+
__proto__: null,
|
183
|
+
timeTransfrom: timeTransfrom,
|
184
|
+
plus: plus,
|
185
|
+
minus: minus,
|
186
|
+
times: times,
|
187
|
+
divide: divide,
|
188
|
+
exactRound: exactRound,
|
189
|
+
toThousand: toThousand,
|
190
|
+
clearAssignStr: clearAssignStr,
|
191
|
+
loadFileRename: loadFileRename,
|
192
|
+
openTipModal: openTipModal,
|
193
|
+
transformFileSize: transformFileSize
|
194
|
+
});
|
195
|
+
|
196
|
+
export { timeTransfrom as a, toThousand as b, clearAssignStr as c, divide as d, exactRound as e, transformFileSize as f, loadFileRename as l, openTipModal as o, tools as t };
|