ztxkutils 2.10.7 → 2.10.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.
@@ -1,5 +1,5 @@
1
1
  import { g as getToken } from './authority-09e50ba2.js';
2
- import { d as dangerouslySetXss } from './tools-1e6fe951.js';
2
+ import { d as dangerouslySetXss } from './tools-5541a681.js';
3
3
  import './tslib.es6-f9459658.js';
4
4
  import 'dayjs';
5
5
  import 'number-precision';
package/dist/hooks.js CHANGED
@@ -3,7 +3,7 @@ import { useState, useEffect, useRef, useCallback } from 'react';
3
3
  export { default as useFileIdToBase64 } from './useFileIdToBase64.js';
4
4
  import './fileOperation.js';
5
5
  import './authority-09e50ba2.js';
6
- import './tools-1e6fe951.js';
6
+ import './tools-5541a681.js';
7
7
  import 'dayjs';
8
8
  import 'number-precision';
9
9
 
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { c as authority } from './authority-09e50ba2.js';
2
2
  export { d as dataModel } from './dataModel-1fbaff40.js';
3
- export { t as tools } from './tools-1e6fe951.js';
3
+ export { t as tools } from './tools-5541a681.js';
4
4
  export { v as validate } from './validate-6e735536.js';
5
5
  export { r as request } from './request-3641b630.js';
6
6
  export { r as reqUrl } from './reqUrl-787dd9e5.js';
@@ -0,0 +1,408 @@
1
+ import { _ as __assign, a as __spreadArray } from './tslib.es6-f9459658.js';
2
+ import dayjs from 'dayjs';
3
+ import { plus as plus$1, minus as minus$1, times as times$1, divide as divide$1, round } 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
+ /**
92
+ * 精确加法
93
+ */
94
+ function plus(num1, num2) {
95
+ var others = [];
96
+ for (var _i = 2; _i < arguments.length; _i++) {
97
+ others[_i - 2] = arguments[_i];
98
+ }
99
+ try {
100
+ var _num1 = isNaN(Number(num1)) ? num1 : Number(num1);
101
+ var _num2 = isNaN(Number(num2)) ? num2 : Number(num2);
102
+ var _others = Array.isArray(others)
103
+ ? others === null || others === void 0 ? void 0 : others.map(function (item) { return (isNaN(Number(item)) ? item : Number(item)); })
104
+ : [];
105
+ return plus$1.apply(void 0, __spreadArray([_num1, _num2], _others));
106
+ }
107
+ catch (err) {
108
+ console.log(err);
109
+ return 0;
110
+ }
111
+ }
112
+ /**
113
+ * 精确减法
114
+ */
115
+ function minus(num1, num2) {
116
+ var others = [];
117
+ for (var _i = 2; _i < arguments.length; _i++) {
118
+ others[_i - 2] = arguments[_i];
119
+ }
120
+ try {
121
+ var _num1 = isNaN(Number(num1)) ? num1 : Number(num1);
122
+ var _num2 = isNaN(Number(num2)) ? num2 : Number(num2);
123
+ var _others = Array.isArray(others)
124
+ ? others === null || others === void 0 ? void 0 : others.map(function (item) { return (isNaN(Number(item)) ? item : Number(item)); })
125
+ : [];
126
+ return minus$1.apply(void 0, __spreadArray([_num1, _num2], _others));
127
+ }
128
+ catch (err) {
129
+ console.log(err);
130
+ return 0;
131
+ }
132
+ }
133
+ /**
134
+ * 精确乘法
135
+ */
136
+ function times(num1, num2) {
137
+ var others = [];
138
+ for (var _i = 2; _i < arguments.length; _i++) {
139
+ others[_i - 2] = arguments[_i];
140
+ }
141
+ try {
142
+ var _num1 = isNaN(Number(num1)) ? num1 : Number(num1);
143
+ var _num2 = isNaN(Number(num2)) ? num2 : Number(num2);
144
+ var _others = Array.isArray(others)
145
+ ? others === null || others === void 0 ? void 0 : others.map(function (item) { return (isNaN(Number(item)) ? item : Number(item)); })
146
+ : [];
147
+ return times$1.apply(void 0, __spreadArray([_num1, _num2], _others));
148
+ }
149
+ catch (err) {
150
+ console.log(err);
151
+ return 0;
152
+ }
153
+ }
154
+ /**
155
+ * 精确除法
156
+ */
157
+ function divide(num1, num2) {
158
+ var others = [];
159
+ for (var _i = 2; _i < arguments.length; _i++) {
160
+ others[_i - 2] = arguments[_i];
161
+ }
162
+ try {
163
+ var _num1 = isNaN(Number(num1)) ? num1 : Number(num1);
164
+ var _num2 = isNaN(Number(num2)) ? num2 : Number(num2);
165
+ var _others = Array.isArray(others)
166
+ ? others === null || others === void 0 ? void 0 : others.map(function (item) { return (isNaN(Number(item)) ? item : Number(item)); })
167
+ : [];
168
+ return divide$1.apply(void 0, __spreadArray([_num1, _num2], _others));
169
+ }
170
+ catch (err) {
171
+ console.log(err);
172
+ return 0;
173
+ }
174
+ }
175
+ /**
176
+ * @description 精确四舍五入后保留几位小数
177
+ */
178
+ function exactRound(num, ratio) {
179
+ var typeNum = typeof num;
180
+ if (typeNum !== 'number' && typeNum !== 'string') {
181
+ return num;
182
+ }
183
+ try {
184
+ return round(num, ratio).toFixed(ratio);
185
+ }
186
+ catch (err) {
187
+ console.error(err);
188
+ return num;
189
+ }
190
+ }
191
+ /**
192
+ * @description 添加千分符符号
193
+ */
194
+ // export function toThousand(num: number | string) {
195
+ // const typeNum = typeof num;
196
+ // if (typeNum !== 'number' && typeNum !== 'string') {
197
+ // return num;
198
+ // }
199
+ // let str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
200
+ // return str;
201
+ // }
202
+ function toThousand(n) {
203
+ if (n != null) {
204
+ var _n = n.toString();
205
+ var pointBeforeNum = '';
206
+ var pointAfterNum = '';
207
+ if (_n.startsWith('-')) {
208
+ pointBeforeNum = '-';
209
+ _n = _n.slice(1);
210
+ }
211
+ var pointIndex = _n.indexOf('.');
212
+ if (pointIndex !== -1) {
213
+ n = _n.slice(0, pointIndex);
214
+ pointAfterNum = _n.slice(pointIndex);
215
+ }
216
+ else {
217
+ n = _n;
218
+ }
219
+ var res = '';
220
+ var s = n.toString();
221
+ var length_1 = s.length;
222
+ for (var i = length_1 - 1; i >= 0; i--) {
223
+ var j = length_1 - i;
224
+ if (j % 3 === 0) {
225
+ if (i === 0) {
226
+ res = s[i] + res;
227
+ }
228
+ else {
229
+ res = ',' + s[i] + res;
230
+ }
231
+ }
232
+ else {
233
+ res = s[i] + res;
234
+ }
235
+ }
236
+ return pointBeforeNum + res + pointAfterNum;
237
+ }
238
+ else {
239
+ return n;
240
+ }
241
+ }
242
+ /**
243
+ * @description 去除指定字符串
244
+ */
245
+ function clearAssignStr(str, originalStr) {
246
+ if (!originalStr) {
247
+ return originalStr;
248
+ }
249
+ if (originalStr.startsWith(str)) {
250
+ return originalStr.replace(str, '');
251
+ }
252
+ return originalStr;
253
+ }
254
+ /**
255
+ * @description 下载重命名
256
+ */
257
+ function loadFileRename(fileUrl, fileName) {
258
+ var xhr = new XMLHttpRequest();
259
+ xhr.open('GET', fileUrl, true);
260
+ xhr.responseType = 'blob';
261
+ xhr.onload = function () {
262
+ if (xhr.status === 200) {
263
+ var link = document.createElement('a');
264
+ var body = document.querySelector('body');
265
+ link.href = window.URL.createObjectURL(xhr.response);
266
+ link.download = fileName;
267
+ // fix Firefox
268
+ link.style.display = 'none';
269
+ body.appendChild(link);
270
+ link.click();
271
+ body.removeChild(link);
272
+ window.URL.revokeObjectURL(link.href);
273
+ }
274
+ };
275
+ xhr.send();
276
+ }
277
+ /**
278
+ * @description 文件大小提示转换
279
+ */
280
+ function transformFileSize(value) {
281
+ if (value < 1024) {
282
+ return round(value, 2).toFixed(2) + 'B';
283
+ }
284
+ else if (value < 1024 * 1024) {
285
+ return round(divide(value, 1024), 2).toFixed(2) + 'KB';
286
+ }
287
+ return round(divide(value, 1024, 1024), 2).toFixed(2) + 'MB';
288
+ }
289
+ /**
290
+ * @description 更具key判断前后值是否一致
291
+ */
292
+ function isEqualByKey(keys, record, preRecord) {
293
+ var isEqual = false; // 是否相等
294
+ if (!record || !preRecord) {
295
+ isEqual = true;
296
+ return isEqual;
297
+ }
298
+ // 如果数据源相同的话,那么判断是初次更改,应该更新
299
+ if (record === preRecord) {
300
+ isEqual = true;
301
+ return isEqual;
302
+ }
303
+ for (var i = 0; i < keys.length; i++) {
304
+ var key = keys[i];
305
+ if (record[key] !== preRecord[key]) {
306
+ isEqual = true;
307
+ break;
308
+ }
309
+ }
310
+ return isEqual;
311
+ }
312
+ /**
313
+ * @description 判断是否显示框架
314
+ */
315
+ var SHOWFRAME_KEY = 'showFrame';
316
+ function showFrame() {
317
+ var _a;
318
+ var search = (_a = window.location) === null || _a === void 0 ? void 0 : _a.search;
319
+ try {
320
+ if (search) {
321
+ var searchList = search.slice(1).split('&');
322
+ for (var i = 0; i < searchList.length; i++) {
323
+ var _b = searchList[i].split('='), key = _b[0], value = _b[1];
324
+ if (key === SHOWFRAME_KEY)
325
+ return false;
326
+ }
327
+ }
328
+ }
329
+ catch (err) {
330
+ return true;
331
+ }
332
+ return true;
333
+ }
334
+ /**
335
+ *
336
+ * @description 取地址栏参数
337
+ */
338
+ function getUrlSearch() {
339
+ var _a;
340
+ var search = (_a = window.location) === null || _a === void 0 ? void 0 : _a.search;
341
+ var result = {};
342
+ try {
343
+ if (search) {
344
+ var searchList = search.slice(1).split('&');
345
+ for (var i = 0; i < searchList.length; i++) {
346
+ var _b = searchList[i].split('='), key = _b[0], value = _b[1];
347
+ result[key] = value;
348
+ }
349
+ }
350
+ }
351
+ catch (err) {
352
+ console.log(err);
353
+ }
354
+ return result;
355
+ }
356
+ /**
357
+ * @description 复制
358
+ */
359
+ function copyContent(text) {
360
+ var textarea = document.createElement('textarea');
361
+ textarea.setAttribute('readonly', 'readonly');
362
+ textarea.value = text;
363
+ document.body.appendChild(textarea);
364
+ textarea.select();
365
+ document === null || document === void 0 ? void 0 : document.execCommand('copy');
366
+ document.body.removeChild(textarea);
367
+ }
368
+ /**
369
+ * @author 陈亚雄
370
+ * @description 处理转义字符
371
+ */
372
+ function dangerouslySetXss(str) {
373
+ var _a;
374
+ if (!str) {
375
+ return str;
376
+ }
377
+ try {
378
+ var arrEntities_1 = { lt: '', gt: '', nbsp: ' ', amp: '&', quot: '"' };
379
+ 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) {
380
+ return arrEntities_1[t];
381
+ });
382
+ }
383
+ catch (err) {
384
+ return str;
385
+ }
386
+ }
387
+
388
+ var tools = /*#__PURE__*/Object.freeze({
389
+ __proto__: null,
390
+ timeTransfrom: timeTransfrom,
391
+ plus: plus,
392
+ minus: minus,
393
+ times: times,
394
+ divide: divide,
395
+ exactRound: exactRound,
396
+ toThousand: toThousand,
397
+ clearAssignStr: clearAssignStr,
398
+ loadFileRename: loadFileRename,
399
+ transformFileSize: transformFileSize,
400
+ isEqualByKey: isEqualByKey,
401
+ SHOWFRAME_KEY: SHOWFRAME_KEY,
402
+ showFrame: showFrame,
403
+ getUrlSearch: getUrlSearch,
404
+ copyContent: copyContent,
405
+ dangerouslySetXss: dangerouslySetXss
406
+ });
407
+
408
+ export { SHOWFRAME_KEY as S, timeTransfrom as a, times as b, divide as c, dangerouslySetXss as d, exactRound as e, toThousand as f, getUrlSearch as g, clearAssignStr as h, transformFileSize as i, isEqualByKey as j, copyContent as k, loadFileRename as l, minus as m, plus as p, showFrame as s, tools as t };
package/dist/tools.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { plus, minus, times } from 'number-precision';
2
1
  /**
3
2
  * @description 常用工具方法
4
3
  * 跟业务无关的一些方法可以放在这个文件里面
@@ -19,12 +18,22 @@ interface ITimeTransfrom {
19
18
  * @description 时间格式转换
20
19
  */
21
20
  export declare function timeTransfrom(timeParams: ITimeTransfrom): any;
21
+ declare type numType = number | string;
22
22
  /**
23
- * @description 四则运算
24
- * 加、减、乘、除
23
+ * 精确加法
24
+ */
25
+ export declare function plus(num1: numType, num2: numType, ...others: numType[]): number;
26
+ /**
27
+ * 精确减法
28
+ */
29
+ export declare function minus(num1: numType, num2: numType, ...others: numType[]): number;
30
+ /**
31
+ * 精确乘法
32
+ */
33
+ export declare function times(num1: numType, num2: numType, ...others: numType[]): number;
34
+ /**
35
+ * 精确除法
25
36
  */
26
- export { plus, minus, times };
27
- declare type numType = number | string;
28
37
  export declare function divide(num1: numType, num2: numType, ...others: numType[]): number;
29
38
  /**
30
39
  * @description 精确四舍五入后保留几位小数
@@ -69,3 +78,4 @@ export declare function copyContent(text: string): void;
69
78
  * @description 处理转义字符
70
79
  */
71
80
  export declare function dangerouslySetXss(str?: string): string;
81
+ export {};
package/dist/tools.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import './tslib.es6-f9459658.js';
2
2
  import 'dayjs';
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-1e6fe951.js';
3
+ import 'number-precision';
4
+ export { S as SHOWFRAME_KEY, h as clearAssignStr, k as copyContent, d as dangerouslySetXss, c as divide, e as exactRound, g as getUrlSearch, j as isEqualByKey, l as loadFileRename, m as minus, p as plus, s as showFrame, a as timeTransfrom, b as times, f as toThousand, i as transformFileSize } from './tools-5541a681.js';
@@ -1,7 +1,7 @@
1
1
  import { useState, useEffect } from 'react';
2
2
  import { createDownloadUrl } from './fileOperation.js';
3
3
  import './authority-09e50ba2.js';
4
- import './tools-1e6fe951.js';
4
+ import './tools-5541a681.js';
5
5
  import './tslib.es6-f9459658.js';
6
6
  import 'dayjs';
7
7
  import 'number-precision';
package/dist/workflow.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useEffect } from 'react';
2
- import { g as getUrlSearch } from './tools-1e6fe951.js';
2
+ import { g as getUrlSearch } from './tools-5541a681.js';
3
3
  import { WORKFLOW_HIDEFRAME_KEY } from './constants.js';
4
4
  import './tslib.es6-f9459658.js';
5
5
  import 'dayjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "2.10.7",
3
+ "version": "2.10.8",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",