ztxkutils 2.8.19 → 2.9.0
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/fileOperation.js +1 -1
- package/dist/index.js +1 -1
- package/dist/tools-1e6fe951.js +337 -0
- package/dist/tools.js +1 -1
- package/dist/workflow.js +1 -1
- package/package.json +1 -1
package/dist/fileOperation.js
CHANGED
package/dist/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
export { c as authority } from './authority-5bc06c1a.js';
|
2
2
|
export { d as dataModel } from './dataModel-1fbaff40.js';
|
3
|
-
export { t as tools } from './tools-
|
3
|
+
export { t as tools } from './tools-1e6fe951.js';
|
4
4
|
export { v as validate } from './validate-3e15dd74.js';
|
5
5
|
export { r as request } from './request-09b081d4.js';
|
6
6
|
export { r as reqUrl } from './reqUrl-88fcc5c5.js';
|
@@ -0,0 +1,337 @@
|
|
1
|
+
import { _ as __assign, a as __spreadArray } from './tslib.es6-f9459658.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, format = timeParams.format;
|
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
|
+
var formatItem = Array.isArray(format)
|
16
|
+
? format[i]
|
17
|
+
? format[i]
|
18
|
+
: 'YYYY-MM-DD'
|
19
|
+
: format
|
20
|
+
? format
|
21
|
+
: 'YYYY-MM-DD';
|
22
|
+
// 从一个键转换成两个键
|
23
|
+
if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'object') {
|
24
|
+
if (type === 'string' && copyParams[fromKeyItem]) {
|
25
|
+
var _g = copyParams[fromKeyItem], startMoment = _g[0], endMoment = _g[1];
|
26
|
+
var start = void 0, end = void 0;
|
27
|
+
if (dayjs.isDayjs(startMoment)) {
|
28
|
+
start = startMoment.format(formatItem);
|
29
|
+
}
|
30
|
+
if (dayjs.isDayjs(endMoment)) {
|
31
|
+
end = endMoment.format(formatItem);
|
32
|
+
}
|
33
|
+
if (formatItem === 'YYYY-MM-DD HH:mm:ss') {
|
34
|
+
start = start.substr(0, 10) + ' 00:00:00';
|
35
|
+
end = end.substr(0, 10) + ' 23:59:59';
|
36
|
+
}
|
37
|
+
delete copyParams[fromKeyItem];
|
38
|
+
copyParams = __assign(__assign({}, copyParams), (_a = {}, _a[toKeyItem[0]] = start, _a[toKeyItem[1]] = end, _a));
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
copyParams = __assign(__assign({}, copyParams), (_b = {}, _b[toKeyItem[0]] = undefined, _b[toKeyItem[1]] = undefined, _b));
|
42
|
+
}
|
43
|
+
}
|
44
|
+
// 从一个键转换成一个键
|
45
|
+
if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'string') {
|
46
|
+
if (type === 'string') {
|
47
|
+
var _dayjsObj = copyParams[fromKeyItem];
|
48
|
+
var start = void 0;
|
49
|
+
if (dayjs.isDayjs(_dayjsObj)) {
|
50
|
+
start = _dayjsObj.format(formatItem);
|
51
|
+
}
|
52
|
+
if (formatItem === 'startTime') {
|
53
|
+
start = start.substr(0, 10) + ' 00:00:00';
|
54
|
+
}
|
55
|
+
if (formatItem === 'endTime') {
|
56
|
+
start = start.substr(0, 10) + ' 23:59:59';
|
57
|
+
}
|
58
|
+
delete copyParams[fromKeyItem];
|
59
|
+
copyParams = __assign(__assign({}, copyParams), (_c = {}, _c[toKeyItem] = start, _c));
|
60
|
+
}
|
61
|
+
if (type === 'object') {
|
62
|
+
var start = copyParams[fromKeyItem]
|
63
|
+
? dayjs(copyParams[fromKeyItem])
|
64
|
+
: undefined;
|
65
|
+
delete copyParams[fromKeyItem];
|
66
|
+
copyParams = __assign(__assign({}, copyParams), (_d = {}, _d[toKeyItem] = start, _d));
|
67
|
+
}
|
68
|
+
}
|
69
|
+
// 从两个键转换成一个键
|
70
|
+
if (typeof fromKeyItem === 'object' && typeof toKeyItem === 'string') {
|
71
|
+
if (type === 'object') {
|
72
|
+
var startMoment = fromKeyItem[0], endMoment = fromKeyItem[1];
|
73
|
+
var intime = copyParams[toKeyItem] || [null, null];
|
74
|
+
if (copyParams[startMoment]) {
|
75
|
+
intime[0] = dayjs(copyParams[startMoment]);
|
76
|
+
delete copyParams[startMoment];
|
77
|
+
}
|
78
|
+
if (copyParams[endMoment]) {
|
79
|
+
intime[1] = dayjs(copyParams[endMoment]);
|
80
|
+
delete copyParams[endMoment];
|
81
|
+
}
|
82
|
+
if (intime[0] == null || intime[1] == null) {
|
83
|
+
intime = null;
|
84
|
+
}
|
85
|
+
copyParams = __assign(__assign({}, copyParams), (_e = {}, _e[toKeyItem] = intime, _e));
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
return copyParams;
|
90
|
+
}
|
91
|
+
function divide(num1, num2) {
|
92
|
+
var others = [];
|
93
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
94
|
+
others[_i - 2] = arguments[_i];
|
95
|
+
}
|
96
|
+
try {
|
97
|
+
return divide$1.apply(void 0, __spreadArray([num1, num2], others));
|
98
|
+
}
|
99
|
+
catch (err) {
|
100
|
+
console.log(err);
|
101
|
+
return 0;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
/**
|
105
|
+
* @description 精确四舍五入后保留几位小数
|
106
|
+
*/
|
107
|
+
function exactRound(num, ratio) {
|
108
|
+
var typeNum = typeof num;
|
109
|
+
if (typeNum !== 'number' && typeNum !== 'string') {
|
110
|
+
return num;
|
111
|
+
}
|
112
|
+
try {
|
113
|
+
return round(num, ratio).toFixed(ratio);
|
114
|
+
}
|
115
|
+
catch (err) {
|
116
|
+
console.error(err);
|
117
|
+
return num;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
/**
|
121
|
+
* @description 添加千分符符号
|
122
|
+
*/
|
123
|
+
// export function toThousand(num: number | string) {
|
124
|
+
// const typeNum = typeof num;
|
125
|
+
// if (typeNum !== 'number' && typeNum !== 'string') {
|
126
|
+
// return num;
|
127
|
+
// }
|
128
|
+
// let str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
|
129
|
+
// return str;
|
130
|
+
// }
|
131
|
+
function toThousand(n) {
|
132
|
+
if (n != null) {
|
133
|
+
var _n = n.toString();
|
134
|
+
var pointBeforeNum = '';
|
135
|
+
var pointAfterNum = '';
|
136
|
+
if (_n.startsWith('-')) {
|
137
|
+
pointBeforeNum = '-';
|
138
|
+
_n = _n.slice(1);
|
139
|
+
}
|
140
|
+
var pointIndex = _n.indexOf('.');
|
141
|
+
if (pointIndex !== -1) {
|
142
|
+
n = _n.slice(0, pointIndex);
|
143
|
+
pointAfterNum = _n.slice(pointIndex);
|
144
|
+
}
|
145
|
+
else {
|
146
|
+
n = _n;
|
147
|
+
}
|
148
|
+
var res = '';
|
149
|
+
var s = n.toString();
|
150
|
+
var length_1 = s.length;
|
151
|
+
for (var i = length_1 - 1; i >= 0; i--) {
|
152
|
+
var j = length_1 - i;
|
153
|
+
if (j % 3 === 0) {
|
154
|
+
if (i === 0) {
|
155
|
+
res = s[i] + res;
|
156
|
+
}
|
157
|
+
else {
|
158
|
+
res = ',' + s[i] + res;
|
159
|
+
}
|
160
|
+
}
|
161
|
+
else {
|
162
|
+
res = s[i] + res;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
return pointBeforeNum + res + pointAfterNum;
|
166
|
+
}
|
167
|
+
else {
|
168
|
+
return n;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
/**
|
172
|
+
* @description 去除指定字符串
|
173
|
+
*/
|
174
|
+
function clearAssignStr(str, originalStr) {
|
175
|
+
if (!originalStr) {
|
176
|
+
return originalStr;
|
177
|
+
}
|
178
|
+
if (originalStr.startsWith(str)) {
|
179
|
+
return originalStr.replace(str, '');
|
180
|
+
}
|
181
|
+
return originalStr;
|
182
|
+
}
|
183
|
+
/**
|
184
|
+
* @description 下载重命名
|
185
|
+
*/
|
186
|
+
function loadFileRename(fileUrl, fileName) {
|
187
|
+
var xhr = new XMLHttpRequest();
|
188
|
+
xhr.open('GET', fileUrl, true);
|
189
|
+
xhr.responseType = 'blob';
|
190
|
+
xhr.onload = function () {
|
191
|
+
if (xhr.status === 200) {
|
192
|
+
var link = document.createElement('a');
|
193
|
+
var body = document.querySelector('body');
|
194
|
+
link.href = window.URL.createObjectURL(xhr.response);
|
195
|
+
link.download = fileName;
|
196
|
+
// fix Firefox
|
197
|
+
link.style.display = 'none';
|
198
|
+
body.appendChild(link);
|
199
|
+
link.click();
|
200
|
+
body.removeChild(link);
|
201
|
+
window.URL.revokeObjectURL(link.href);
|
202
|
+
}
|
203
|
+
};
|
204
|
+
xhr.send();
|
205
|
+
}
|
206
|
+
/**
|
207
|
+
* @description 文件大小提示转换
|
208
|
+
*/
|
209
|
+
function transformFileSize(value) {
|
210
|
+
if (value < 1024) {
|
211
|
+
return round(value, 2).toFixed(2) + 'B';
|
212
|
+
}
|
213
|
+
else if (value < 1024 * 1024) {
|
214
|
+
return round(divide(value, 1024), 2).toFixed(2) + 'KB';
|
215
|
+
}
|
216
|
+
return round(divide(value, 1024, 1024), 2).toFixed(2) + 'MB';
|
217
|
+
}
|
218
|
+
/**
|
219
|
+
* @description 更具key判断前后值是否一致
|
220
|
+
*/
|
221
|
+
function isEqualByKey(keys, record, preRecord) {
|
222
|
+
var isEqual = false; // 是否相等
|
223
|
+
if (!record || !preRecord) {
|
224
|
+
isEqual = true;
|
225
|
+
return isEqual;
|
226
|
+
}
|
227
|
+
// 如果数据源相同的话,那么判断是初次更改,应该更新
|
228
|
+
if (record === preRecord) {
|
229
|
+
isEqual = true;
|
230
|
+
return isEqual;
|
231
|
+
}
|
232
|
+
for (var i = 0; i < keys.length; i++) {
|
233
|
+
var key = keys[i];
|
234
|
+
if (record[key] !== preRecord[key]) {
|
235
|
+
isEqual = true;
|
236
|
+
break;
|
237
|
+
}
|
238
|
+
}
|
239
|
+
return isEqual;
|
240
|
+
}
|
241
|
+
/**
|
242
|
+
* @description 判断是否显示框架
|
243
|
+
*/
|
244
|
+
var SHOWFRAME_KEY = 'showFrame';
|
245
|
+
function showFrame() {
|
246
|
+
var _a;
|
247
|
+
var search = (_a = window.location) === null || _a === void 0 ? void 0 : _a.search;
|
248
|
+
try {
|
249
|
+
if (search) {
|
250
|
+
var searchList = search.slice(1).split('&');
|
251
|
+
for (var i = 0; i < searchList.length; i++) {
|
252
|
+
var _b = searchList[i].split('='), key = _b[0], value = _b[1];
|
253
|
+
if (key === SHOWFRAME_KEY)
|
254
|
+
return false;
|
255
|
+
}
|
256
|
+
}
|
257
|
+
}
|
258
|
+
catch (err) {
|
259
|
+
return true;
|
260
|
+
}
|
261
|
+
return true;
|
262
|
+
}
|
263
|
+
/**
|
264
|
+
*
|
265
|
+
* @description 取地址栏参数
|
266
|
+
*/
|
267
|
+
function getUrlSearch() {
|
268
|
+
var _a;
|
269
|
+
var search = (_a = window.location) === null || _a === void 0 ? void 0 : _a.search;
|
270
|
+
var result = {};
|
271
|
+
try {
|
272
|
+
if (search) {
|
273
|
+
var searchList = search.slice(1).split('&');
|
274
|
+
for (var i = 0; i < searchList.length; i++) {
|
275
|
+
var _b = searchList[i].split('='), key = _b[0], value = _b[1];
|
276
|
+
result[key] = value;
|
277
|
+
}
|
278
|
+
}
|
279
|
+
}
|
280
|
+
catch (err) {
|
281
|
+
console.log(err);
|
282
|
+
}
|
283
|
+
return result;
|
284
|
+
}
|
285
|
+
/**
|
286
|
+
* @description 复制
|
287
|
+
*/
|
288
|
+
function copyContent(text) {
|
289
|
+
var textarea = document.createElement('textarea');
|
290
|
+
textarea.setAttribute('readonly', 'readonly');
|
291
|
+
textarea.value = text;
|
292
|
+
document.body.appendChild(textarea);
|
293
|
+
textarea.select();
|
294
|
+
document === null || document === void 0 ? void 0 : document.execCommand('copy');
|
295
|
+
document.body.removeChild(textarea);
|
296
|
+
}
|
297
|
+
/**
|
298
|
+
* @author 陈亚雄
|
299
|
+
* @description 处理转义字符
|
300
|
+
*/
|
301
|
+
function dangerouslySetXss(str) {
|
302
|
+
var _a;
|
303
|
+
if (!str) {
|
304
|
+
return str;
|
305
|
+
}
|
306
|
+
try {
|
307
|
+
var arrEntities_1 = { lt: '', gt: '', nbsp: ' ', amp: '&', quot: '"' };
|
308
|
+
return (_a = str === null || str === void 0 ? void 0 : str.replace) === null || _a === void 0 ? void 0 : _a.call(str, /&(lt|gt|nbsp|amp|quot);/gi, function (all, t) {
|
309
|
+
return arrEntities_1[t];
|
310
|
+
});
|
311
|
+
}
|
312
|
+
catch (err) {
|
313
|
+
return str;
|
314
|
+
}
|
315
|
+
}
|
316
|
+
|
317
|
+
var tools = /*#__PURE__*/Object.freeze({
|
318
|
+
__proto__: null,
|
319
|
+
timeTransfrom: timeTransfrom,
|
320
|
+
plus: plus,
|
321
|
+
minus: minus,
|
322
|
+
times: times,
|
323
|
+
divide: divide,
|
324
|
+
exactRound: exactRound,
|
325
|
+
toThousand: toThousand,
|
326
|
+
clearAssignStr: clearAssignStr,
|
327
|
+
loadFileRename: loadFileRename,
|
328
|
+
transformFileSize: transformFileSize,
|
329
|
+
isEqualByKey: isEqualByKey,
|
330
|
+
SHOWFRAME_KEY: SHOWFRAME_KEY,
|
331
|
+
showFrame: showFrame,
|
332
|
+
getUrlSearch: getUrlSearch,
|
333
|
+
copyContent: copyContent,
|
334
|
+
dangerouslySetXss: dangerouslySetXss
|
335
|
+
});
|
336
|
+
|
337
|
+
export { SHOWFRAME_KEY as S, timeTransfrom as a, divide as b, toThousand as c, dangerouslySetXss as d, exactRound as e, clearAssignStr as f, getUrlSearch as g, transformFileSize as h, isEqualByKey as i, copyContent as j, loadFileRename as l, showFrame as s, tools as t };
|
package/dist/tools.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
import './tslib.es6-f9459658.js';
|
2
2
|
import 'dayjs';
|
3
3
|
export { minus, plus, times } from 'number-precision';
|
4
|
-
export { S as SHOWFRAME_KEY, f as clearAssignStr, j as copyContent, d as dangerouslySetXss, b as divide, e as exactRound, g as getUrlSearch, i as isEqualByKey, l as loadFileRename, s as showFrame, a as timeTransfrom, c as toThousand, h as transformFileSize } from './tools-
|
4
|
+
export { S as SHOWFRAME_KEY, f as clearAssignStr, j as copyContent, d as dangerouslySetXss, b as divide, e as exactRound, g as getUrlSearch, i as isEqualByKey, l as loadFileRename, s as showFrame, a as timeTransfrom, c as toThousand, h as transformFileSize } from './tools-1e6fe951.js';
|
package/dist/workflow.js
CHANGED