ztxkutils 2.2.5 → 2.2.9
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 +3 -3
- package/dist/{reqUrl-68c864fb.js → reqUrl-b19a6e87.js} +7 -1
- package/dist/reqUrl.d.ts +1 -0
- package/dist/reqUrl.js +1 -1
- package/dist/{tools-e7505c92.js → tools-2876d65c.js} +2 -0
- package/dist/tools.js +1 -1
- package/dist/{validate-01242f5f.js → validate-ebe369e9.js} +5 -0
- package/dist/validate.d.ts +5 -0
- package/dist/validate.js +1 -1
- package/package.json +1 -1
- package/dist/tools-48c24adb.js +0 -200
- package/dist/tools-49b33116.js +0 -195
- package/dist/tools-8207f0a0.js +0 -197
- package/dist/tools-e1b35b23.js +0 -209
- package/dist/tools-e7de0bcc.js +0 -205
- package/dist/tools-e94e4c20.js +0 -209
- package/dist/validate-56d8f230.js +0 -61
- package/dist/validate-743d8f98.js +0 -60
- package/dist/validate-7f5dd1b3.js +0 -60
- package/dist/validate-8cbc61e4.js +0 -60
- package/dist/validate-bf84ec9c.js +0 -60
- package/dist/validate-cc61f65f.js +0 -60
- package/dist/validate-e4351b64.js +0 -60
package/dist/index.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
export { c as authority } from './authority-17b7fde2.js';
|
2
2
|
export { d as dataModel } from './dataModel-1fbaff40.js';
|
3
|
-
export { t as tools } from './tools-
|
4
|
-
export { v as validate } from './validate-
|
3
|
+
export { t as tools } from './tools-2876d65c.js';
|
4
|
+
export { v as validate } from './validate-ebe369e9.js';
|
5
5
|
export { r as request } from './request-74ca7860.js';
|
6
|
-
export { r as reqUrl } from './reqUrl-
|
6
|
+
export { r as reqUrl } from './reqUrl-b19a6e87.js';
|
7
7
|
import './tslib.es6-b9033aad.js';
|
8
8
|
import 'dayjs';
|
9
9
|
import 'number-precision';
|
@@ -9,6 +9,7 @@ function getReqUrl(processObj) {
|
|
9
9
|
var ZT_API_TEST = processObj.REACT_APP_ZT_API_TEST || 'http://192.168.0.135:8000'; // 测试环境
|
10
10
|
var ZT_API_STAGE = processObj.REACT_APP_ZT_API_STAGE || 'http://192.168.0.134:8000'; // 阶段性环境
|
11
11
|
var ZT_API_PRODUCT = processObj.REACT_APP_ZT_API_PRODUCT || 'http://dz.zmd.com.cn'; // 生产环境
|
12
|
+
var ZT_API_PUBLIC_PRODUCT = processObj.REACT_ZT_API_PUBLIC_PRODUCT || 'http://dz.zmd.com.cn:8000'; // 生产环境外网api地址
|
12
13
|
// 文件服务器
|
13
14
|
var ZT_FILE_PREVIEW_DEV = processObj.REACT_APP_ZT_FILE_PREVIEW_DEV || 'http://192.168.0.83:88'; // 开发环境
|
14
15
|
var ZT_FILE_PREVIEW_TEST = processObj.REACT_APP_ZT_FILE_PREVIEW_TEST || 'http://192.168.0.135:8012'; // 测试环境
|
@@ -16,28 +17,33 @@ function getReqUrl(processObj) {
|
|
16
17
|
var ZT_FILE_PREVIEW_PRODUCT = processObj.REACT_ZT_FILE_PREVIEW_PRODUCT || 'http://dzfile.zmd.com.cn:8012'; // 生产环境
|
17
18
|
// 实际api请求地址
|
18
19
|
var ZT_API_BASEURL = ZT_API_DEV;
|
20
|
+
var ZT_API_PUBLICURL = ZT_API_PUBLIC_PRODUCT;
|
19
21
|
var ZT_FILE_BASEURL = ZT_FILE_PREVIEW_DEV;
|
20
22
|
if (ENV) {
|
21
23
|
switch (ENV.toLowerCase()) {
|
22
24
|
case 'zt-dev':
|
23
25
|
ZT_API_BASEURL = ZT_API_DEV;
|
26
|
+
ZT_API_PUBLICURL = ZT_API_DEV;
|
24
27
|
ZT_FILE_BASEURL = ZT_FILE_PREVIEW_DEV;
|
25
28
|
break;
|
26
29
|
case 'zt-test':
|
27
30
|
ZT_API_BASEURL = ZT_API_TEST;
|
31
|
+
ZT_API_PUBLICURL = ZT_API_TEST;
|
28
32
|
ZT_FILE_BASEURL = ZT_FILE_PREVIEW_TEST;
|
29
33
|
break;
|
30
34
|
case 'zt-stage':
|
31
35
|
ZT_API_BASEURL = ZT_API_STAGE;
|
36
|
+
ZT_API_PUBLICURL = ZT_API_STAGE;
|
32
37
|
ZT_FILE_BASEURL = ZT_FILE_PREVIEW_STAGE;
|
33
38
|
break;
|
34
39
|
case 'zt-product':
|
35
40
|
ZT_API_BASEURL = ZT_API_PRODUCT;
|
41
|
+
ZT_API_PUBLICURL = ZT_API_PUBLICURL;
|
36
42
|
ZT_FILE_BASEURL = ZT_FILE_PREVIEW_PRODUCT;
|
37
43
|
break;
|
38
44
|
}
|
39
45
|
}
|
40
|
-
return { ZT_API_BASEURL: ZT_API_BASEURL, ZT_FILE_BASEURL: ZT_FILE_BASEURL };
|
46
|
+
return { ZT_API_BASEURL: ZT_API_BASEURL, ZT_FILE_BASEURL: ZT_FILE_BASEURL, ZT_API_PUBLICURL: ZT_API_PUBLICURL };
|
41
47
|
}
|
42
48
|
|
43
49
|
var reqUrl = /*#__PURE__*/Object.freeze({
|
package/dist/reqUrl.d.ts
CHANGED
package/dist/reqUrl.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export { g as getReqUrl } from './reqUrl-
|
1
|
+
export { g as getReqUrl } from './reqUrl-b19a6e87.js';
|
package/dist/tools.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
import './tslib.es6-b9033aad.js';
|
2
2
|
import 'dayjs';
|
3
3
|
export { minus, plus, times } from 'number-precision';
|
4
|
-
export { c as clearAssignStr, d as divide, e as exactRound, i as isEqualByKey, l as loadFileRename, a as timeTransfrom, b as toThousand, f as transformFileSize } from './tools-
|
4
|
+
export { c as clearAssignStr, d as divide, e as exactRound, i as isEqualByKey, l as loadFileRename, a as timeTransfrom, b as toThousand, f as transformFileSize } from './tools-2876d65c.js';
|
@@ -32,6 +32,10 @@ var validate = {
|
|
32
32
|
* @description 密码验证
|
33
33
|
*/
|
34
34
|
passwordValidate: /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$)^.{8,16}$/,
|
35
|
+
/**
|
36
|
+
* @description 空格验证
|
37
|
+
*/
|
38
|
+
spaceValidate: /^[^\s]*$/g,
|
35
39
|
};
|
36
40
|
var commonMessage = {
|
37
41
|
smallLenMessage: function (type) {
|
@@ -50,6 +54,7 @@ var commonMessage = {
|
|
50
54
|
idCardMessage: '请输入正确的身份证',
|
51
55
|
emailMessage: '请输入正确的邮箱',
|
52
56
|
passwordMessage: '密码由8-16位的字母+数字,字母+特殊字符,数字+特殊字符组成',
|
57
|
+
spaceMessage: '请勿输入空格',
|
53
58
|
};
|
54
59
|
|
55
60
|
var validate$1 = /*#__PURE__*/Object.freeze({
|
package/dist/validate.d.ts
CHANGED
@@ -31,6 +31,10 @@ declare const validate: {
|
|
31
31
|
* @description 密码验证
|
32
32
|
*/
|
33
33
|
passwordValidate: RegExp;
|
34
|
+
/**
|
35
|
+
* @description 空格验证
|
36
|
+
*/
|
37
|
+
spaceValidate: RegExp;
|
34
38
|
};
|
35
39
|
declare const commonMessage: {
|
36
40
|
smallLenMessage(type?: string): string;
|
@@ -40,5 +44,6 @@ declare const commonMessage: {
|
|
40
44
|
idCardMessage: string;
|
41
45
|
emailMessage: string;
|
42
46
|
passwordMessage: string;
|
47
|
+
spaceMessage: string;
|
43
48
|
};
|
44
49
|
export { validate, commonMessage };
|
package/dist/validate.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export { c as commonMessage, a as validate } from './validate-
|
1
|
+
export { c as commonMessage, a as validate } from './validate-ebe369e9.js';
|
package/package.json
CHANGED
package/dist/tools-48c24adb.js
DELETED
@@ -1,200 +0,0 @@
|
|
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
|
-
|
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
|
-
if (intime[0] == null || intime[1] == null) {
|
66
|
-
intime = null;
|
67
|
-
}
|
68
|
-
copyParams = __assign(__assign({}, copyParams), (_e = {}, _e[toKeyItem] = intime, _e));
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}
|
72
|
-
return copyParams;
|
73
|
-
}
|
74
|
-
function divide(num1, num2) {
|
75
|
-
var others = [];
|
76
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
77
|
-
others[_i - 2] = arguments[_i];
|
78
|
-
}
|
79
|
-
try {
|
80
|
-
return divide$1.apply(void 0, __spreadArray([num1, num2], others));
|
81
|
-
}
|
82
|
-
catch (err) {
|
83
|
-
console.log(err);
|
84
|
-
return 0;
|
85
|
-
}
|
86
|
-
}
|
87
|
-
/**
|
88
|
-
* @description 精确四舍五入后保留几位小数
|
89
|
-
*/
|
90
|
-
function exactRound(num, ratio) {
|
91
|
-
var typeNum = typeof num;
|
92
|
-
if (typeNum !== 'number' && typeNum !== 'string') {
|
93
|
-
return num;
|
94
|
-
}
|
95
|
-
try {
|
96
|
-
return round(num, ratio).toFixed(ratio);
|
97
|
-
}
|
98
|
-
catch (err) {
|
99
|
-
console.error(err);
|
100
|
-
return num;
|
101
|
-
}
|
102
|
-
}
|
103
|
-
/**
|
104
|
-
* @description 添加千分符符号
|
105
|
-
*/
|
106
|
-
function toThousand(num) {
|
107
|
-
var typeNum = typeof num;
|
108
|
-
if (typeNum !== 'number' && typeNum !== 'string') {
|
109
|
-
return num;
|
110
|
-
}
|
111
|
-
var str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
|
112
|
-
return str;
|
113
|
-
}
|
114
|
-
/**
|
115
|
-
* @description 去除指定字符串
|
116
|
-
*/
|
117
|
-
function clearAssignStr(str, originalStr) {
|
118
|
-
if (!originalStr) {
|
119
|
-
return originalStr;
|
120
|
-
}
|
121
|
-
if (originalStr.startsWith(str)) {
|
122
|
-
return originalStr.replace(str, '');
|
123
|
-
}
|
124
|
-
return originalStr;
|
125
|
-
}
|
126
|
-
/**
|
127
|
-
* @description 下载重命名
|
128
|
-
*/
|
129
|
-
function loadFileRename(fileUrl, fileName) {
|
130
|
-
var xhr = new XMLHttpRequest();
|
131
|
-
xhr.open('GET', fileUrl, true);
|
132
|
-
xhr.responseType = 'blob';
|
133
|
-
xhr.onload = function () {
|
134
|
-
if (xhr.status === 200) {
|
135
|
-
var link = document.createElement('a');
|
136
|
-
var body = document.querySelector('body');
|
137
|
-
link.href = window.URL.createObjectURL(xhr.response);
|
138
|
-
link.download = fileName;
|
139
|
-
// fix Firefox
|
140
|
-
link.style.display = 'none';
|
141
|
-
body.appendChild(link);
|
142
|
-
link.click();
|
143
|
-
body.removeChild(link);
|
144
|
-
window.URL.revokeObjectURL(link.href);
|
145
|
-
}
|
146
|
-
};
|
147
|
-
xhr.send();
|
148
|
-
}
|
149
|
-
/**
|
150
|
-
* @description 文件大小提示转换
|
151
|
-
*/
|
152
|
-
function transformFileSize(value) {
|
153
|
-
if (value < 1024) {
|
154
|
-
return round(value, 2).toFixed(2) + 'B';
|
155
|
-
}
|
156
|
-
else if (value < 1024 * 1024) {
|
157
|
-
return round(divide(value, 1024), 2).toFixed(2) + 'KB';
|
158
|
-
}
|
159
|
-
return round(divide(value, 1024, 1024), 2).toFixed(2) + 'MB';
|
160
|
-
}
|
161
|
-
/**
|
162
|
-
* @description 更具key判断前后值是否一致
|
163
|
-
*/
|
164
|
-
function isEqualByKey(keys, record, preRecord) {
|
165
|
-
var isEqual = false; // 是否相等
|
166
|
-
if (!record || !preRecord) {
|
167
|
-
isEqual = true;
|
168
|
-
return isEqual;
|
169
|
-
}
|
170
|
-
// 如果数据源相同的话,那么判断是初次更改,应该更新
|
171
|
-
if (record === preRecord) {
|
172
|
-
isEqual = true;
|
173
|
-
return isEqual;
|
174
|
-
}
|
175
|
-
for (var i = 0; i < keys.length; i++) {
|
176
|
-
var key = keys[i];
|
177
|
-
if (record[key] !== preRecord[key]) {
|
178
|
-
isEqual = true;
|
179
|
-
break;
|
180
|
-
}
|
181
|
-
}
|
182
|
-
return isEqual;
|
183
|
-
}
|
184
|
-
|
185
|
-
var tools = /*#__PURE__*/Object.freeze({
|
186
|
-
__proto__: null,
|
187
|
-
timeTransfrom: timeTransfrom,
|
188
|
-
plus: plus,
|
189
|
-
minus: minus,
|
190
|
-
times: times,
|
191
|
-
divide: divide,
|
192
|
-
exactRound: exactRound,
|
193
|
-
toThousand: toThousand,
|
194
|
-
clearAssignStr: clearAssignStr,
|
195
|
-
loadFileRename: loadFileRename,
|
196
|
-
transformFileSize: transformFileSize,
|
197
|
-
isEqualByKey: isEqualByKey
|
198
|
-
});
|
199
|
-
|
200
|
-
export { timeTransfrom as a, toThousand as b, clearAssignStr as c, divide as d, exactRound as e, transformFileSize as f, isEqualByKey as i, loadFileRename as l, tools as t };
|
package/dist/tools-49b33116.js
DELETED
@@ -1,195 +0,0 @@
|
|
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
|
-
|
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
|
-
function divide(num1, num2) {
|
72
|
-
var others = [];
|
73
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
74
|
-
others[_i - 2] = arguments[_i];
|
75
|
-
}
|
76
|
-
try {
|
77
|
-
return divide$1.apply(void 0, __spreadArray([num1, num2], others));
|
78
|
-
}
|
79
|
-
catch (err) {
|
80
|
-
console.log(err);
|
81
|
-
return 0;
|
82
|
-
}
|
83
|
-
}
|
84
|
-
/**
|
85
|
-
* @description 精确四舍五入后保留几位小数
|
86
|
-
*/
|
87
|
-
function exactRound(num, ratio) {
|
88
|
-
var typeNum = typeof num;
|
89
|
-
if (typeNum !== 'number' && typeNum !== 'string') {
|
90
|
-
return num;
|
91
|
-
}
|
92
|
-
try {
|
93
|
-
return round(num, ratio).toFixed(ratio);
|
94
|
-
}
|
95
|
-
catch (err) {
|
96
|
-
console.error(err);
|
97
|
-
return num;
|
98
|
-
}
|
99
|
-
}
|
100
|
-
/**
|
101
|
-
* @description 添加千分符符号
|
102
|
-
*/
|
103
|
-
function toThousand(num) {
|
104
|
-
var typeNum = typeof num;
|
105
|
-
if (typeNum !== 'number' && typeNum !== 'string') {
|
106
|
-
return num;
|
107
|
-
}
|
108
|
-
var str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
|
109
|
-
return str;
|
110
|
-
}
|
111
|
-
/**
|
112
|
-
* @description 去除指定字符串
|
113
|
-
*/
|
114
|
-
function clearAssignStr(str, originalStr) {
|
115
|
-
if (!originalStr) {
|
116
|
-
return originalStr;
|
117
|
-
}
|
118
|
-
if (originalStr.startsWith(str)) {
|
119
|
-
return originalStr.replace(str, '');
|
120
|
-
}
|
121
|
-
return originalStr;
|
122
|
-
}
|
123
|
-
/**
|
124
|
-
* @description 下载重命名
|
125
|
-
*/
|
126
|
-
function loadFileRename(fileUrl, fileName) {
|
127
|
-
var xhr = new XMLHttpRequest();
|
128
|
-
xhr.open('GET', fileUrl, true);
|
129
|
-
xhr.responseType = 'blob';
|
130
|
-
xhr.onload = function () {
|
131
|
-
if (xhr.status === 200) {
|
132
|
-
var link = document.createElement('a');
|
133
|
-
var body = document.querySelector('body');
|
134
|
-
link.href = window.URL.createObjectURL(xhr.response);
|
135
|
-
link.download = fileName;
|
136
|
-
// fix Firefox
|
137
|
-
link.style.display = 'none';
|
138
|
-
body.appendChild(link);
|
139
|
-
link.click();
|
140
|
-
body.removeChild(link);
|
141
|
-
window.URL.revokeObjectURL(link.href);
|
142
|
-
}
|
143
|
-
};
|
144
|
-
xhr.send();
|
145
|
-
}
|
146
|
-
/**
|
147
|
-
* @description 文件大小提示转换
|
148
|
-
*/
|
149
|
-
function transformFileSize(value) {
|
150
|
-
if (value < 1024) {
|
151
|
-
return round(value, 2).toFixed(2) + 'B';
|
152
|
-
}
|
153
|
-
else if (value < 1024 * 1024) {
|
154
|
-
return round(divide(value, 1024), 2).toFixed(2) + 'KB';
|
155
|
-
}
|
156
|
-
return round(divide(value, 1024, 1024), 2).toFixed(2) + 'MB';
|
157
|
-
}
|
158
|
-
/**
|
159
|
-
* @description 更具key判断前后值是否一致
|
160
|
-
*/
|
161
|
-
function isEqualByKey(keys, record, preRecord) {
|
162
|
-
var isEqual = false; // 是否相等
|
163
|
-
if (!record || !preRecord) {
|
164
|
-
isEqual = true;
|
165
|
-
return isEqual;
|
166
|
-
}
|
167
|
-
if (record === preRecord) {
|
168
|
-
return isEqual;
|
169
|
-
}
|
170
|
-
for (var i = 0; i < keys.length; i++) {
|
171
|
-
var key = keys[i];
|
172
|
-
if (record[key] !== preRecord[key]) {
|
173
|
-
isEqual = true;
|
174
|
-
break;
|
175
|
-
}
|
176
|
-
}
|
177
|
-
return isEqual;
|
178
|
-
}
|
179
|
-
|
180
|
-
var tools = /*#__PURE__*/Object.freeze({
|
181
|
-
__proto__: null,
|
182
|
-
timeTransfrom: timeTransfrom,
|
183
|
-
plus: plus,
|
184
|
-
minus: minus,
|
185
|
-
times: times,
|
186
|
-
divide: divide,
|
187
|
-
exactRound: exactRound,
|
188
|
-
toThousand: toThousand,
|
189
|
-
clearAssignStr: clearAssignStr,
|
190
|
-
loadFileRename: loadFileRename,
|
191
|
-
transformFileSize: transformFileSize,
|
192
|
-
isEqualByKey: isEqualByKey
|
193
|
-
});
|
194
|
-
|
195
|
-
export { timeTransfrom as a, toThousand as b, clearAssignStr as c, divide as d, exactRound as e, transformFileSize as f, isEqualByKey as i, loadFileRename as l, tools as t };
|