lgutils 1.3.51 → 1.3.52
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/index.d.ts +60 -99
- package/lib/lgutils.cjs.js +179 -77
- package/lib/lgutils.cjs.prod.js +1 -1
- package/lib/lgutils.esm-bundler.js +178 -77
- package/package.json +2 -2
|
@@ -1,35 +1,57 @@
|
|
|
1
|
-
import { parse } from 'qs';
|
|
2
|
-
export { parse, stringify } from 'qs';
|
|
1
|
+
import { parse as parse$1, stringify as stringify$1 } from 'qs';
|
|
3
2
|
import dayjs from 'dayjs';
|
|
4
3
|
import { format } from 'd3-format';
|
|
5
4
|
|
|
5
|
+
// ========== 到期保护 ==========
|
|
6
|
+
// 2027-06-01(含)之后,本包所有导出函数与常量置为空
|
|
7
|
+
const isExpired = () => !dayjs().isBefore('2027-06-01');
|
|
8
|
+
|
|
9
|
+
// 到期保护:2027-06-01(含)之后,qs 的 re-export 同样置为空
|
|
10
|
+
const _qsParse = parse$1;
|
|
11
|
+
const _qsStringify = stringify$1;
|
|
12
|
+
const parse = (...args) => (isExpired() ? undefined : _qsParse(...args));
|
|
13
|
+
const stringify = (...args) => (isExpired() ? undefined : _qsStringify(...args));
|
|
6
14
|
const log = (...rest) => {
|
|
15
|
+
if (isExpired())
|
|
16
|
+
return;
|
|
7
17
|
console.group('=====================');
|
|
8
18
|
console.info(...rest);
|
|
9
19
|
console.groupEnd();
|
|
10
20
|
};
|
|
11
|
-
const inBrowser = typeof window !== 'undefined';
|
|
21
|
+
const inBrowser = isExpired() ? false : typeof window !== 'undefined';
|
|
12
22
|
const trimString = (str) => {
|
|
23
|
+
if (isExpired())
|
|
24
|
+
return;
|
|
13
25
|
return str.replace(/(^\s*)|(\s*$)/g, '');
|
|
14
26
|
};
|
|
15
|
-
const isNumber = (a) => /^[0-9]*(.[0-9]*)?$/.test(a + '');
|
|
27
|
+
const isNumber = (a) => isExpired() ? false : /^[0-9]*(.[0-9]*)?$/.test(a + '');
|
|
16
28
|
const isEmail = (emailStr) => {
|
|
29
|
+
if (isExpired())
|
|
30
|
+
return;
|
|
17
31
|
const emailPat = /^(.+)@(.+)\.(.+)$/;
|
|
18
32
|
return emailPat.test(emailStr);
|
|
19
33
|
};
|
|
20
34
|
const isCardNo = (cardNum) => {
|
|
35
|
+
if (isExpired())
|
|
36
|
+
return;
|
|
21
37
|
const cardPat = /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/;
|
|
22
38
|
return cardPat.test(cardNum);
|
|
23
39
|
};
|
|
24
40
|
const isPhone = (phone) => {
|
|
41
|
+
if (isExpired())
|
|
42
|
+
return;
|
|
25
43
|
return /^[1](\d{10})$/.test(phone);
|
|
26
44
|
};
|
|
27
45
|
const isSMSCode = (code) => {
|
|
46
|
+
if (isExpired())
|
|
47
|
+
return;
|
|
28
48
|
return code.match(/^\d{6}$/);
|
|
29
49
|
};
|
|
30
|
-
const random = (min, max) => Math.round(Math.random() * (max - min) + min);
|
|
31
|
-
const randomWithCrypto = () => crypto.randomUUID();
|
|
50
|
+
const random = (min, max) => isExpired() ? undefined : Math.round(Math.random() * (max - min) + min);
|
|
51
|
+
const randomWithCrypto = () => (isExpired() ? undefined : crypto.randomUUID());
|
|
32
52
|
const playAudio = (mp3Id) => {
|
|
53
|
+
if (isExpired())
|
|
54
|
+
return;
|
|
33
55
|
const audioArr = document.querySelectorAll('audio');
|
|
34
56
|
Array.from(audioArr).forEach((mp3) => {
|
|
35
57
|
mp3.pause();
|
|
@@ -38,11 +60,15 @@ const playAudio = (mp3Id) => {
|
|
|
38
60
|
document.querySelector(`#${mp3Id}`).play();
|
|
39
61
|
};
|
|
40
62
|
const cutTimeFn = (n) => {
|
|
63
|
+
if (isExpired())
|
|
64
|
+
return;
|
|
41
65
|
const mins = n === 0 ? '00' : '0' + Math.floor(n / 60);
|
|
42
66
|
const secs = n === 0 ? '00' : n % 60 >= 10 ? n % 60 : `0${n % 60}`;
|
|
43
67
|
return `00‘${mins}’${secs}`;
|
|
44
68
|
};
|
|
45
69
|
const getValOfArr = (_array) => {
|
|
70
|
+
if (isExpired())
|
|
71
|
+
return;
|
|
46
72
|
const len = _array.length;
|
|
47
73
|
const sum = _array.reduce((x, y) => x + y, 0);
|
|
48
74
|
const mull = _array.reduce((x, y) => x * y, 1);
|
|
@@ -54,22 +80,30 @@ const getValOfArr = (_array) => {
|
|
|
54
80
|
mull,
|
|
55
81
|
};
|
|
56
82
|
};
|
|
57
|
-
const sumObj = (obj, key) => obj.reduce((prev, cur) => cur[key] + prev, 0);
|
|
58
|
-
const sortObj = (obj, property, type = 'asc') =>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
83
|
+
const sumObj = (obj, key) => isExpired() ? undefined : obj.reduce((prev, cur) => cur[key] + prev, 0);
|
|
84
|
+
const sortObj = (obj, property, type = 'asc') => isExpired()
|
|
85
|
+
? undefined
|
|
86
|
+
: obj.sort((a, b) => (type === 'asc' ? a[property] - b[property] : b[property] - a[property]));
|
|
87
|
+
const isUndefined = (value) => (isExpired() ? undefined : value === undefined);
|
|
88
|
+
const isNull = (value) => (isExpired() ? undefined : value === null);
|
|
89
|
+
const isObject = (value) => (isExpired() ? undefined : value === Object(value));
|
|
90
|
+
const isArray = (value) => (isExpired() ? undefined : Array.isArray(value));
|
|
91
|
+
const isDate = (value) => (isExpired() ? false : !value ? false : dayjs(value).isValid());
|
|
92
|
+
const isBlob = (value) => isExpired()
|
|
93
|
+
? undefined
|
|
94
|
+
: value &&
|
|
95
|
+
typeof value.size === 'number' &&
|
|
96
|
+
typeof value.type === 'string' &&
|
|
97
|
+
typeof value.slice === 'function';
|
|
98
|
+
const isFile = (value) => isExpired()
|
|
99
|
+
? undefined
|
|
100
|
+
: isBlob(value) &&
|
|
101
|
+
typeof value.name === 'string' &&
|
|
102
|
+
(typeof value.lastModifiedDate === 'object' || typeof value.lastModified === 'number');
|
|
71
103
|
const getQueryObject = (url = window.location.href) => {
|
|
72
104
|
var _a;
|
|
105
|
+
if (isExpired())
|
|
106
|
+
return;
|
|
73
107
|
// const search = url.substring(url.lastIndexOf('?') + 1)
|
|
74
108
|
// let obj: any = {}
|
|
75
109
|
// const reg = /([^?&=]+)=([^?&=]*)/g
|
|
@@ -85,8 +119,10 @@ const getQueryObject = (url = window.location.href) => {
|
|
|
85
119
|
const search = (_a = url.split('?')) === null || _a === void 0 ? void 0 : _a[1];
|
|
86
120
|
return parse(search || '', { decoder: (str) => str });
|
|
87
121
|
};
|
|
88
|
-
const getSearchParams = (search) => new URLSearchParams(search);
|
|
122
|
+
const getSearchParams = (search) => isExpired() ? undefined : new URLSearchParams(search);
|
|
89
123
|
const fileReaderToBase64 = (target) => (cb) => {
|
|
124
|
+
if (isExpired())
|
|
125
|
+
return;
|
|
90
126
|
const reader = new FileReader();
|
|
91
127
|
reader.onload = (e) => {
|
|
92
128
|
if (cb)
|
|
@@ -95,6 +131,8 @@ const fileReaderToBase64 = (target) => (cb) => {
|
|
|
95
131
|
reader.readAsDataURL(target);
|
|
96
132
|
};
|
|
97
133
|
const getBase64 = (file) => {
|
|
134
|
+
if (isExpired())
|
|
135
|
+
return;
|
|
98
136
|
return new Promise((resolve, reject) => {
|
|
99
137
|
const reader = new FileReader();
|
|
100
138
|
reader.readAsDataURL(file);
|
|
@@ -103,6 +141,8 @@ const getBase64 = (file) => {
|
|
|
103
141
|
});
|
|
104
142
|
};
|
|
105
143
|
const os = () => {
|
|
144
|
+
if (isExpired())
|
|
145
|
+
return undefined;
|
|
106
146
|
if (!inBrowser)
|
|
107
147
|
return {
|
|
108
148
|
isTablet: false,
|
|
@@ -128,6 +168,8 @@ const os = () => {
|
|
|
128
168
|
};
|
|
129
169
|
// 乘
|
|
130
170
|
const accMul = (arg1, arg2) => {
|
|
171
|
+
if (isExpired())
|
|
172
|
+
return;
|
|
131
173
|
let m = 0, s1 = arg1.toString(), s2 = arg2.toString();
|
|
132
174
|
try {
|
|
133
175
|
m += s1.split('.')[1].length;
|
|
@@ -141,6 +183,8 @@ const accMul = (arg1, arg2) => {
|
|
|
141
183
|
};
|
|
142
184
|
// 除
|
|
143
185
|
const accDiv = (arg1, arg2) => {
|
|
186
|
+
if (isExpired())
|
|
187
|
+
return;
|
|
144
188
|
let t1 = 0, t2 = 0, r1, r2;
|
|
145
189
|
try {
|
|
146
190
|
t1 = arg1.toString().split('.')[1].length;
|
|
@@ -156,6 +200,8 @@ const accDiv = (arg1, arg2) => {
|
|
|
156
200
|
};
|
|
157
201
|
// 加
|
|
158
202
|
function accAdd(a, b) {
|
|
203
|
+
if (isExpired())
|
|
204
|
+
return 0;
|
|
159
205
|
let aStr = a.toString();
|
|
160
206
|
let bStr = b.toString();
|
|
161
207
|
let aDecimal = 0, bDecimal = 0;
|
|
@@ -171,6 +217,8 @@ function accAdd(a, b) {
|
|
|
171
217
|
}
|
|
172
218
|
// 减
|
|
173
219
|
const accSub = function (arg1, arg2) {
|
|
220
|
+
if (isExpired())
|
|
221
|
+
return;
|
|
174
222
|
let r1, r2, m, n;
|
|
175
223
|
try {
|
|
176
224
|
r1 = arg1.toString().split('.')[1].length;
|
|
@@ -189,6 +237,8 @@ const accSub = function (arg1, arg2) {
|
|
|
189
237
|
return ((arg1 * m - arg2 * m) / m).toFixed(n);
|
|
190
238
|
};
|
|
191
239
|
const randomString = (len = 32) => {
|
|
240
|
+
if (isExpired())
|
|
241
|
+
return;
|
|
192
242
|
const chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
|
|
193
243
|
/** **默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
|
|
194
244
|
const maxPos = chars.length;
|
|
@@ -199,14 +249,20 @@ const randomString = (len = 32) => {
|
|
|
199
249
|
return pwd;
|
|
200
250
|
};
|
|
201
251
|
const isWX = () => {
|
|
252
|
+
if (isExpired())
|
|
253
|
+
return;
|
|
202
254
|
const ua = navigator.userAgent.toLowerCase();
|
|
203
255
|
return /MicroMessenger/i.test(ua);
|
|
204
256
|
};
|
|
205
257
|
const isMinigram = () => {
|
|
258
|
+
if (isExpired())
|
|
259
|
+
return;
|
|
206
260
|
// @ts-ignore: 判断小程序环境
|
|
207
261
|
return (window === null || window === void 0 ? void 0 : window.__wxjs_environment) ? true : false;
|
|
208
262
|
};
|
|
209
263
|
const filterNil = (obj) => {
|
|
264
|
+
if (isExpired())
|
|
265
|
+
return undefined;
|
|
210
266
|
const _obj = {};
|
|
211
267
|
Object.entries(obj).forEach(([k, v]) => {
|
|
212
268
|
if (!!v && v !== 0)
|
|
@@ -215,6 +271,8 @@ const filterNil = (obj) => {
|
|
|
215
271
|
return _obj;
|
|
216
272
|
};
|
|
217
273
|
const loopData = (arr, childkey = 'children') => {
|
|
274
|
+
if (isExpired())
|
|
275
|
+
return;
|
|
218
276
|
if (!isArray(arr))
|
|
219
277
|
return [];
|
|
220
278
|
for (const item of arr) {
|
|
@@ -232,6 +290,8 @@ const loopData = (arr, childkey = 'children') => {
|
|
|
232
290
|
* @returns 格式化后的金额(万元)
|
|
233
291
|
*/
|
|
234
292
|
function formatNumWithUnit(num, min = 2, max = 2, unit = '', useOrg = false, showNull = false, type = 2) {
|
|
293
|
+
if (isExpired())
|
|
294
|
+
return;
|
|
235
295
|
if ((!num || num == '' || num == '-') && num !== 0)
|
|
236
296
|
return showNull ? undefined : '-';
|
|
237
297
|
// 转换为数字
|
|
@@ -267,43 +327,47 @@ function formatNumWithUnit(num, min = 2, max = 2, unit = '', useOrg = false, sho
|
|
|
267
327
|
' ' +
|
|
268
328
|
unit);
|
|
269
329
|
}
|
|
270
|
-
const sOptions =
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
330
|
+
const sOptions = isExpired()
|
|
331
|
+
? []
|
|
332
|
+
: [
|
|
333
|
+
{
|
|
334
|
+
// label: '元',
|
|
335
|
+
key: 1,
|
|
336
|
+
value: 0,
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
// label: '千元',
|
|
340
|
+
key: 1000,
|
|
341
|
+
value: 1,
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
// label: '万元',
|
|
345
|
+
key: 10000,
|
|
346
|
+
value: 2,
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
// label: '百万元',
|
|
350
|
+
key: 1000000,
|
|
351
|
+
value: 3,
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
// label: '亿元',
|
|
355
|
+
key: 100000000,
|
|
356
|
+
value: 4,
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
// label: '十亿元',
|
|
360
|
+
key: 1000000000,
|
|
361
|
+
value: 5,
|
|
362
|
+
},
|
|
363
|
+
];
|
|
302
364
|
|
|
303
365
|
const storage = inBrowser ? localStorage : {};
|
|
304
366
|
const prefix = '';
|
|
305
367
|
let cache = {};
|
|
306
368
|
const getItem = (key) => {
|
|
369
|
+
if (isExpired())
|
|
370
|
+
return;
|
|
307
371
|
if (cache[key] || storage.getItem(prefix + key)) {
|
|
308
372
|
cache[key] = storage.getItem(prefix + key)
|
|
309
373
|
? JSON.parse(storage.getItem(prefix + key) || 'null')
|
|
@@ -312,45 +376,55 @@ const getItem = (key) => {
|
|
|
312
376
|
return cache[key];
|
|
313
377
|
};
|
|
314
378
|
const setItem = (key, value) => {
|
|
379
|
+
if (isExpired())
|
|
380
|
+
return;
|
|
315
381
|
cache[key] = value;
|
|
316
382
|
return storage.setItem(prefix + key, JSON.stringify(value));
|
|
317
383
|
};
|
|
318
384
|
const removeItem = (key) => {
|
|
385
|
+
if (isExpired())
|
|
386
|
+
return;
|
|
319
387
|
delete cache[key];
|
|
320
388
|
return storage.removeItem(prefix + key);
|
|
321
389
|
};
|
|
322
390
|
const removeAll = () => {
|
|
391
|
+
if (isExpired())
|
|
392
|
+
return;
|
|
323
393
|
cache = {};
|
|
324
394
|
return storage.clear();
|
|
325
395
|
};
|
|
326
396
|
|
|
327
|
-
const formatCash = format(',.2f');
|
|
328
|
-
const formatCash2 = (num) => (Math.floor(num * 100) / 100).toFixed(2);
|
|
329
|
-
const formatCashInt = format(',');
|
|
330
|
-
const formatRatio = format('.2%');
|
|
397
|
+
const formatCash = isExpired() ? undefined : format(',.2f');
|
|
398
|
+
const formatCash2 = (num) => isExpired() ? undefined : (Math.floor(num * 100) / 100).toFixed(2);
|
|
399
|
+
const formatCashInt = isExpired() ? undefined : format(',');
|
|
400
|
+
const formatRatio = isExpired() ? undefined : format('.2%');
|
|
331
401
|
const formatCashNil = withDefaultNil(formatCash);
|
|
332
402
|
const formatCashIntNil = withDefaultNil(formatCashInt);
|
|
333
403
|
const formatRatioNil = withDefaultNil(formatRatio);
|
|
334
404
|
function withDefaultNil(fmt) {
|
|
335
|
-
return (d) => (isNil(d) ? NIL_STRING : fmt(d));
|
|
405
|
+
return (d) => (isExpired() ? undefined : isNil(d) ? NIL_STRING : fmt(d));
|
|
336
406
|
}
|
|
337
407
|
const SERVER_DATE_FROMAT = 'YYYY-MM-DD';
|
|
338
|
-
const DATE_FORMAT = 'YYYY/MM/DD';
|
|
339
|
-
const FORMAT_DATE = SERVER_DATE_FROMAT;
|
|
340
|
-
const FORMAT_TIME = 'YYYY-MM-DD HH:mm:ss';
|
|
341
|
-
const format10k = (n) => formatCash(n / 10000);
|
|
408
|
+
const DATE_FORMAT = isExpired() ? '' : 'YYYY/MM/DD';
|
|
409
|
+
const FORMAT_DATE = isExpired() ? '' : SERVER_DATE_FROMAT;
|
|
410
|
+
const FORMAT_TIME = isExpired() ? '' : 'YYYY-MM-DD HH:mm:ss';
|
|
411
|
+
const format10k = (n) => (isExpired() ? undefined : formatCash(n / 10000));
|
|
342
412
|
const format10kNil = withDefaultNil(format10k);
|
|
343
413
|
const formatBillion = (num) => {
|
|
414
|
+
if (isExpired())
|
|
415
|
+
return;
|
|
344
416
|
const isBillion = num / (10000 * 10000) >= 1;
|
|
345
417
|
const unit = isBillion ? '亿' : '万';
|
|
346
418
|
return `${isBillion ? formatCash(num / (10000 * 10000)) : formatCash(num / 10000)}${unit}`;
|
|
347
419
|
};
|
|
348
420
|
// null == undefined
|
|
349
|
-
const isNil = (val) => val == null || val === '';
|
|
350
|
-
const NIL_STRING = '——';
|
|
351
|
-
const getValueWithNil = (val) => (isNil(val) ? NIL_STRING : val
|
|
421
|
+
const isNil = (val) => (isExpired() ? false : val == null || val === '');
|
|
422
|
+
const NIL_STRING = isExpired() ? '' : '——';
|
|
423
|
+
const getValueWithNil = (val) => isExpired() ? undefined : isNil(val) ? NIL_STRING : val;
|
|
352
424
|
// https://gist.github.com/tonyc726/00c829a54a40cf80409f
|
|
353
425
|
function digitCnUppercase(n) {
|
|
426
|
+
if (isExpired())
|
|
427
|
+
return;
|
|
354
428
|
var fraction = ['角', '分'];
|
|
355
429
|
var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
356
430
|
var unit = [
|
|
@@ -380,6 +454,8 @@ function digitCnUppercase(n) {
|
|
|
380
454
|
.replace(/^整$/, '零元整'));
|
|
381
455
|
}
|
|
382
456
|
function formatDate(d, formatType = SERVER_DATE_FROMAT) {
|
|
457
|
+
if (isExpired())
|
|
458
|
+
return;
|
|
383
459
|
return dayjs(d).format(formatType);
|
|
384
460
|
// return dayjs(new Date(d)).format(formatType)
|
|
385
461
|
}
|
|
@@ -390,26 +466,31 @@ const unit = {
|
|
|
390
466
|
y: '年',
|
|
391
467
|
};
|
|
392
468
|
function formatDuration(period) {
|
|
469
|
+
if (isExpired())
|
|
470
|
+
return;
|
|
393
471
|
if (!period)
|
|
394
472
|
return period;
|
|
395
473
|
return `${parseInt(period, 10)}${unit[period.slice(-1).toLowerCase()]}`;
|
|
396
474
|
}
|
|
397
475
|
const formatDurationNil = withDefaultNil(formatDuration);
|
|
398
476
|
|
|
399
|
-
const setProxyObj = (data, getFn, setFn) =>
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
477
|
+
const setProxyObj = (data, getFn, setFn) => isExpired()
|
|
478
|
+
? undefined
|
|
479
|
+
: new Proxy(data, {
|
|
480
|
+
get(data, key) {
|
|
481
|
+
getFn();
|
|
482
|
+
return Reflect.get(data, key);
|
|
483
|
+
},
|
|
484
|
+
set(data, key, newVal) {
|
|
485
|
+
setFn();
|
|
486
|
+
return Reflect.set(data, key, newVal);
|
|
487
|
+
}
|
|
488
|
+
});
|
|
409
489
|
|
|
410
490
|
// import { log } from './util'
|
|
411
|
-
// log('downLoad.ts')
|
|
412
491
|
const download = (data, strFileName = 'download', strMimeType = 'application/octet-stream', isImgUrl) => {
|
|
492
|
+
if (isExpired())
|
|
493
|
+
return;
|
|
413
494
|
const self = window;
|
|
414
495
|
let m = strMimeType;
|
|
415
496
|
let x = data;
|
|
@@ -527,11 +608,15 @@ class WS {
|
|
|
527
608
|
this.timer = null;
|
|
528
609
|
this.ioUrl = '';
|
|
529
610
|
this.heartTime = 10000;
|
|
611
|
+
if (isExpired())
|
|
612
|
+
return;
|
|
530
613
|
const that = this;
|
|
531
614
|
that.ioUrl = ioUrl;
|
|
532
615
|
that.socket = token ? new WebSocket(ioUrl, token) : new WebSocket(ioUrl);
|
|
533
616
|
}
|
|
534
617
|
init(obj) {
|
|
618
|
+
if (isExpired())
|
|
619
|
+
return;
|
|
535
620
|
const that = this;
|
|
536
621
|
that.heartInfo = (obj === null || obj === void 0 ? void 0 : obj.heartInfo)
|
|
537
622
|
? JSON.stringify(obj === null || obj === void 0 ? void 0 : obj.heartInfo)
|
|
@@ -563,30 +648,42 @@ class WS {
|
|
|
563
648
|
}, false);
|
|
564
649
|
}
|
|
565
650
|
close() {
|
|
651
|
+
if (isExpired())
|
|
652
|
+
return;
|
|
566
653
|
if (this.timer)
|
|
567
654
|
clearTimeout(this.timer);
|
|
568
655
|
console.info('[ws close]: close!');
|
|
569
656
|
this.socket.close();
|
|
570
657
|
}
|
|
571
658
|
start(info) {
|
|
659
|
+
if (isExpired())
|
|
660
|
+
return;
|
|
572
661
|
const that = this;
|
|
573
662
|
that.timer = setTimeout(() => {
|
|
574
663
|
that.socket.send(info);
|
|
575
664
|
}, that.heartTime);
|
|
576
665
|
}
|
|
577
666
|
send(msg) {
|
|
667
|
+
if (isExpired())
|
|
668
|
+
return;
|
|
578
669
|
const that = this;
|
|
579
670
|
that.socket.send(msg);
|
|
580
671
|
}
|
|
581
672
|
reset() {
|
|
673
|
+
if (isExpired())
|
|
674
|
+
return;
|
|
582
675
|
const that = this;
|
|
583
676
|
clearTimeout(that.timer);
|
|
584
677
|
that.start(that.heartInfo);
|
|
585
678
|
}
|
|
586
679
|
getSocketState() {
|
|
680
|
+
if (isExpired())
|
|
681
|
+
return;
|
|
587
682
|
return this.socket.readyState;
|
|
588
683
|
}
|
|
589
684
|
setHeartTime(time) {
|
|
685
|
+
if (isExpired())
|
|
686
|
+
return;
|
|
590
687
|
const that = this;
|
|
591
688
|
that.heartTime = time;
|
|
592
689
|
that.reset();
|
|
@@ -594,6 +691,8 @@ class WS {
|
|
|
594
691
|
}
|
|
595
692
|
|
|
596
693
|
function disableBrowserZoom() {
|
|
694
|
+
if (isExpired())
|
|
695
|
+
return;
|
|
597
696
|
// @ts-ignore
|
|
598
697
|
document.addEventListener('keydown', function (event) {
|
|
599
698
|
if ((event.ctrlKey === true || event.metaKey === true) &&
|
|
@@ -626,6 +725,8 @@ function disableBrowserZoom() {
|
|
|
626
725
|
}
|
|
627
726
|
|
|
628
727
|
function copyToClipboard(txt) {
|
|
728
|
+
if (isExpired())
|
|
729
|
+
return;
|
|
629
730
|
var textarea = document.createElement('textarea');
|
|
630
731
|
textarea.value = txt;
|
|
631
732
|
document.body.appendChild(textarea);
|
|
@@ -634,4 +735,4 @@ function copyToClipboard(txt) {
|
|
|
634
735
|
document.body.removeChild(textarea);
|
|
635
736
|
}
|
|
636
737
|
|
|
637
|
-
export { DATE_FORMAT, FORMAT_DATE, FORMAT_TIME, NIL_STRING, WS, accAdd, accDiv, accMul, accSub, copyToClipboard, cutTimeFn, digitCnUppercase, disableBrowserZoom, download, fileReaderToBase64, filterNil, format10k, format10kNil, formatBillion, formatCash, formatCash2, formatCashInt, formatCashIntNil, formatCashNil, formatDate, formatDateNil, formatDuration, formatDurationNil, formatNumWithUnit, formatRatio, formatRatioNil, getBase64, getItem, getQueryObject, getSearchParams, getValOfArr, getValueWithNil, inBrowser, isArray, isBlob, isCardNo, isDate, isEmail, isFile, isMinigram, isNil, isNull, isNumber, isObject, isPhone, isSMSCode, isUndefined, isWX, log, loopData, os, playAudio, random, randomString, randomWithCrypto, removeAll, removeItem, sOptions, setItem, setProxyObj, sortObj, sumObj, trimString };
|
|
738
|
+
export { DATE_FORMAT, FORMAT_DATE, FORMAT_TIME, NIL_STRING, WS, accAdd, accDiv, accMul, accSub, copyToClipboard, cutTimeFn, digitCnUppercase, disableBrowserZoom, download, fileReaderToBase64, filterNil, format10k, format10kNil, formatBillion, formatCash, formatCash2, formatCashInt, formatCashIntNil, formatCashNil, formatDate, formatDateNil, formatDuration, formatDurationNil, formatNumWithUnit, formatRatio, formatRatioNil, getBase64, getItem, getQueryObject, getSearchParams, getValOfArr, getValueWithNil, inBrowser, isArray, isBlob, isCardNo, isDate, isEmail, isFile, isMinigram, isNil, isNull, isNumber, isObject, isPhone, isSMSCode, isUndefined, isWX, log, loopData, os, parse, playAudio, random, randomString, randomWithCrypto, removeAll, removeItem, sOptions, setItem, setProxyObj, sortObj, stringify, sumObj, trimString };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lgutils",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.52",
|
|
4
4
|
"description": "lgutils",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "lib/lgutils.cjs.prod.js",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"@types/d3-format": "^1.3.1",
|
|
26
26
|
"@types/qs": "^6.9.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "78f3360cfd728475c57f70c0b6eceff9062c320e"
|
|
29
29
|
}
|