lgutils 1.3.9 → 1.3.12
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 +179 -232
- package/lib/lgutils.cjs.js +43 -4
- package/lib/lgutils.cjs.prod.js +1 -1
- package/lib/lgutils.esm-bundler.js +43 -5
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -1,232 +1,179 @@
|
|
|
1
|
-
export declare const accAdd: (arg1: number, arg2: number) => number
|
|
2
|
-
|
|
3
|
-
export declare const accDiv: (arg1: number, arg2: number) => number
|
|
4
|
-
|
|
5
|
-
export declare const accMul: (arg1: number, arg2: number) => number
|
|
6
|
-
|
|
7
|
-
export declare const accSub: (arg1: number, arg2: number) => string
|
|
8
|
-
|
|
9
|
-
export declare const cutTimeFn: (n: number) => string
|
|
10
|
-
|
|
11
|
-
export declare const DATE_FORMAT =
|
|
12
|
-
|
|
13
|
-
export declare function digitCnUppercase(n: number): string
|
|
14
|
-
|
|
15
|
-
export declare
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
) => string
|
|
60
|
-
|
|
61
|
-
export declare const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
export declare
|
|
82
|
-
|
|
83
|
-
export declare const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
) =>
|
|
92
|
-
|
|
93
|
-
export declare const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
declare
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
export declare const
|
|
127
|
-
|
|
128
|
-
export declare
|
|
129
|
-
|
|
130
|
-
export declare
|
|
131
|
-
|
|
132
|
-
export declare const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
declare
|
|
162
|
-
|
|
163
|
-
export declare
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
export declare const randomString: (len?: number) => string
|
|
181
|
-
|
|
182
|
-
export declare const removeAll: () => any
|
|
183
|
-
|
|
184
|
-
export declare const removeItem: (key: string) => any
|
|
185
|
-
|
|
186
|
-
export declare const setItem: (key: string, value: any) => any
|
|
187
|
-
|
|
188
|
-
export declare const setProxyObj: (
|
|
189
|
-
data: object,
|
|
190
|
-
getFn: () => void,
|
|
191
|
-
setFn: () => void
|
|
192
|
-
) => object
|
|
193
|
-
|
|
194
|
-
export declare const sortObj: <
|
|
195
|
-
T extends keyof D,
|
|
196
|
-
D extends {
|
|
197
|
-
[key: string]: any
|
|
198
|
-
}
|
|
199
|
-
>(
|
|
200
|
-
obj: D[],
|
|
201
|
-
property: T,
|
|
202
|
-
type?: 'asc' | 'desc'
|
|
203
|
-
) => D[]
|
|
204
|
-
|
|
205
|
-
export declare const sumObj: <
|
|
206
|
-
T extends keyof D,
|
|
207
|
-
D extends {
|
|
208
|
-
[key: string]: any
|
|
209
|
-
}
|
|
210
|
-
>(
|
|
211
|
-
obj: D[],
|
|
212
|
-
key: T
|
|
213
|
-
) => number
|
|
214
|
-
|
|
215
|
-
export declare const trimString: (str: string) => string
|
|
216
|
-
|
|
217
|
-
export declare class WS {
|
|
218
|
-
socket: any
|
|
219
|
-
timer: any
|
|
220
|
-
ioUrl: string
|
|
221
|
-
private heartTime
|
|
222
|
-
constructor(ioUrl: string, token?: string)
|
|
223
|
-
init(obj: IWSObj): void
|
|
224
|
-
close(): void
|
|
225
|
-
start(info?: any): void
|
|
226
|
-
send(msg: AnyObj): void
|
|
227
|
-
reset(): void
|
|
228
|
-
getSocketState(): any
|
|
229
|
-
setHeartTime(time: number): void
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export {}
|
|
1
|
+
export declare const accAdd: (arg1: number, arg2: number) => number;
|
|
2
|
+
|
|
3
|
+
export declare const accDiv: (arg1: number, arg2: number) => number;
|
|
4
|
+
|
|
5
|
+
export declare const accMul: (arg1: number, arg2: number) => number;
|
|
6
|
+
|
|
7
|
+
export declare const accSub: (arg1: number, arg2: number) => string;
|
|
8
|
+
|
|
9
|
+
export declare const cutTimeFn: (n: number) => string;
|
|
10
|
+
|
|
11
|
+
export declare const DATE_FORMAT = "YYYY/MM/DD";
|
|
12
|
+
|
|
13
|
+
export declare function digitCnUppercase(n: number): string;
|
|
14
|
+
|
|
15
|
+
export declare function disableBrowserZoom(): void;
|
|
16
|
+
|
|
17
|
+
export declare const download: (data: string, strFileName?: string, strMimeType?: string, isImgUrl?: boolean | undefined) => true | undefined;
|
|
18
|
+
|
|
19
|
+
export declare const fileReaderToBase64: (target: any) => (cb: (p: any) => void) => void;
|
|
20
|
+
|
|
21
|
+
export declare const format10k: (n: number) => string;
|
|
22
|
+
|
|
23
|
+
export declare const format10kNil: (d: number | NIL) => string;
|
|
24
|
+
|
|
25
|
+
export declare const FORMAT_DATE = "YYYY-MM-DD";
|
|
26
|
+
|
|
27
|
+
export declare const FORMAT_TIME = "YYYY-MM-DD HH:mm:ss";
|
|
28
|
+
|
|
29
|
+
export declare const formatCash: (n: number | {
|
|
30
|
+
valueOf(): number;
|
|
31
|
+
}) => string;
|
|
32
|
+
|
|
33
|
+
export declare const formatCash2: (num: number) => string;
|
|
34
|
+
|
|
35
|
+
export declare const formatCashInt: (n: number | {
|
|
36
|
+
valueOf(): number;
|
|
37
|
+
}) => string;
|
|
38
|
+
|
|
39
|
+
export declare const formatCashIntNil: (d: number | {
|
|
40
|
+
valueOf(): number;
|
|
41
|
+
} | NIL) => string;
|
|
42
|
+
|
|
43
|
+
export declare const formatCashNil: (d: number | {
|
|
44
|
+
valueOf(): number;
|
|
45
|
+
} | NIL) => string;
|
|
46
|
+
|
|
47
|
+
export declare const formatCreditEnhanced: (yes: boolean) => string;
|
|
48
|
+
|
|
49
|
+
export declare function formatDate(d: string | number, formatType?: string): string;
|
|
50
|
+
|
|
51
|
+
export declare const formatDateNil: (d: string | number | null | undefined) => string;
|
|
52
|
+
|
|
53
|
+
export declare function formatDuration(period: string): string;
|
|
54
|
+
|
|
55
|
+
export declare const formatDurationNil: (d: string | null | undefined) => string;
|
|
56
|
+
|
|
57
|
+
export declare const formatRatio: (n: number | {
|
|
58
|
+
valueOf(): number;
|
|
59
|
+
}) => string;
|
|
60
|
+
|
|
61
|
+
export declare const formatRatioNil: (d: number | {
|
|
62
|
+
valueOf(): number;
|
|
63
|
+
} | NIL) => string;
|
|
64
|
+
|
|
65
|
+
export declare const getBase64: (file: File) => Promise<unknown>;
|
|
66
|
+
|
|
67
|
+
export declare const getItem: (key: string) => any;
|
|
68
|
+
|
|
69
|
+
export declare const getQueryObject: (url?: string) => any;
|
|
70
|
+
|
|
71
|
+
export declare const getSearchParams: (search: string) => URLSearchParams;
|
|
72
|
+
|
|
73
|
+
export declare const getValOfArr: (_array: number[]) => {
|
|
74
|
+
min: any;
|
|
75
|
+
max: any;
|
|
76
|
+
sum: number;
|
|
77
|
+
average: number;
|
|
78
|
+
mull: number;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export declare const getValueWithNil: (val: any) => any;
|
|
82
|
+
|
|
83
|
+
export declare const inBrowser: boolean;
|
|
84
|
+
|
|
85
|
+
declare type IndexType = {
|
|
86
|
+
[x: string]: any;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export declare const isArray: (value: any) => boolean;
|
|
90
|
+
|
|
91
|
+
export declare const isBlob: (value: any) => any;
|
|
92
|
+
|
|
93
|
+
export declare const isCardNo: (cardNum: any) => boolean;
|
|
94
|
+
|
|
95
|
+
export declare const isDate: (value: any) => boolean;
|
|
96
|
+
|
|
97
|
+
export declare const isEmail: (emailStr: string) => boolean;
|
|
98
|
+
|
|
99
|
+
export declare const isFile: (value: any) => any;
|
|
100
|
+
|
|
101
|
+
export declare const isNil: (val: any) => val is NIL;
|
|
102
|
+
|
|
103
|
+
export declare const isNull: (value: any) => boolean;
|
|
104
|
+
|
|
105
|
+
export declare const isObject: (value: any) => boolean;
|
|
106
|
+
|
|
107
|
+
export declare const isPhone: (phone: any) => boolean;
|
|
108
|
+
|
|
109
|
+
export declare const isSMSCode: (code: any) => any;
|
|
110
|
+
|
|
111
|
+
export declare const isUndefined: (value: any) => boolean;
|
|
112
|
+
|
|
113
|
+
declare interface IWSObj {
|
|
114
|
+
open?: (params?: any) => any;
|
|
115
|
+
msg: (params: any) => any;
|
|
116
|
+
error?: (params?: any) => any;
|
|
117
|
+
disconnect?: (params?: any) => any;
|
|
118
|
+
close?: (params?: any) => any;
|
|
119
|
+
heartInfo?: any;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export declare const log: (...rest: any) => void;
|
|
123
|
+
|
|
124
|
+
declare type NIL = undefined | null | '';
|
|
125
|
+
|
|
126
|
+
export declare const NIL_STRING = "\u2014\u2014";
|
|
127
|
+
|
|
128
|
+
export declare function normalizeFormValues<T extends IndexType>(values: T): any;
|
|
129
|
+
|
|
130
|
+
export declare function normalizeSearchParams(params: IndexType): IndexType;
|
|
131
|
+
|
|
132
|
+
export declare const os: () => {
|
|
133
|
+
isTablet: boolean;
|
|
134
|
+
isPhone: boolean;
|
|
135
|
+
isAndroid: boolean;
|
|
136
|
+
isPc: boolean;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export declare const playAudio: (mp3Id: string) => void;
|
|
140
|
+
|
|
141
|
+
export declare const random: (min: number, max: number) => number;
|
|
142
|
+
|
|
143
|
+
export declare const randomString: (len?: number) => string;
|
|
144
|
+
|
|
145
|
+
export declare const removeAll: () => any;
|
|
146
|
+
|
|
147
|
+
export declare const removeItem: (key: string) => any;
|
|
148
|
+
|
|
149
|
+
export declare const setItem: (key: string, value: any) => any;
|
|
150
|
+
|
|
151
|
+
export declare const setProxyObj: (data: object, getFn: () => void, setFn: () => void) => object;
|
|
152
|
+
|
|
153
|
+
export declare const sortObj: <T extends keyof D, D extends {
|
|
154
|
+
[key: string]: any;
|
|
155
|
+
}>(obj: D[], property: T, type?: 'asc' | 'desc') => D[];
|
|
156
|
+
|
|
157
|
+
export declare const sumObj: <T extends keyof D, D extends {
|
|
158
|
+
[key: string]: any;
|
|
159
|
+
}>(obj: D[], key: T) => number;
|
|
160
|
+
|
|
161
|
+
export declare const trimString: (str: string) => string;
|
|
162
|
+
|
|
163
|
+
export declare class WS {
|
|
164
|
+
socket: any;
|
|
165
|
+
timer: any;
|
|
166
|
+
ioUrl: string;
|
|
167
|
+
heartInfo: any;
|
|
168
|
+
private heartTime;
|
|
169
|
+
constructor(ioUrl: string, token?: string);
|
|
170
|
+
init(obj: IWSObj): void;
|
|
171
|
+
close(): void;
|
|
172
|
+
start(info: string): void;
|
|
173
|
+
send(msg: AnyObj): void;
|
|
174
|
+
reset(): void;
|
|
175
|
+
getSocketState(): any;
|
|
176
|
+
setHeartTime(time: number): void;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export { }
|
package/lib/lgutils.cjs.js
CHANGED
|
@@ -465,9 +465,12 @@ class WS {
|
|
|
465
465
|
}
|
|
466
466
|
init(obj) {
|
|
467
467
|
const that = this;
|
|
468
|
+
that.heartInfo = (obj === null || obj === void 0 ? void 0 : obj.heartInfo)
|
|
469
|
+
? JSON.stringify(obj === null || obj === void 0 ? void 0 : obj.heartInfo)
|
|
470
|
+
: `ws HeartBeat!`;
|
|
468
471
|
that.socket.addEventListener('open', () => {
|
|
469
472
|
log('ws connect!');
|
|
470
|
-
that.start(
|
|
473
|
+
that.start(that.heartInfo);
|
|
471
474
|
if (obj.open)
|
|
472
475
|
obj.open();
|
|
473
476
|
}, false);
|
|
@@ -508,17 +511,52 @@ class WS {
|
|
|
508
511
|
that.socket.send(msg);
|
|
509
512
|
}
|
|
510
513
|
reset() {
|
|
511
|
-
|
|
512
|
-
|
|
514
|
+
const that = this;
|
|
515
|
+
clearTimeout(that.timer);
|
|
516
|
+
that.start(that.heartInfo);
|
|
513
517
|
}
|
|
514
518
|
getSocketState() {
|
|
515
519
|
return this.socket.readyState;
|
|
516
520
|
}
|
|
517
521
|
setHeartTime(time) {
|
|
518
|
-
|
|
522
|
+
const that = this;
|
|
523
|
+
that.heartTime = time;
|
|
524
|
+
that.reset();
|
|
519
525
|
}
|
|
520
526
|
}
|
|
521
527
|
|
|
528
|
+
function disableBrowserZoom() {
|
|
529
|
+
// @ts-ignore
|
|
530
|
+
document.addEventListener('keydown', function (event) {
|
|
531
|
+
if ((event.ctrlKey === true || event.metaKey === true) &&
|
|
532
|
+
(event.which === 61 ||
|
|
533
|
+
event.which === 107 ||
|
|
534
|
+
event.which === 173 ||
|
|
535
|
+
event.which === 109 ||
|
|
536
|
+
event.which === 187 ||
|
|
537
|
+
event.which === 189)) {
|
|
538
|
+
event.preventDefault();
|
|
539
|
+
}
|
|
540
|
+
}, false);
|
|
541
|
+
// @ts-ignore
|
|
542
|
+
window.addEventListener('mousewheel', function (event) {
|
|
543
|
+
// @ts-ignore
|
|
544
|
+
if (event.ctrlKey === true || event.metaKey) {
|
|
545
|
+
event.preventDefault();
|
|
546
|
+
}
|
|
547
|
+
}, {
|
|
548
|
+
passive: false,
|
|
549
|
+
});
|
|
550
|
+
window.addEventListener('DOMMouseScroll', function (event) {
|
|
551
|
+
// @ts-ignore
|
|
552
|
+
if (event.ctrlKey === true || event.metaKey) {
|
|
553
|
+
event.preventDefault();
|
|
554
|
+
}
|
|
555
|
+
}, {
|
|
556
|
+
passive: false,
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
|
|
522
560
|
exports.DATE_FORMAT = DATE_FORMAT;
|
|
523
561
|
exports.FORMAT_DATE = FORMAT_DATE;
|
|
524
562
|
exports.FORMAT_TIME = FORMAT_TIME;
|
|
@@ -530,6 +568,7 @@ exports.accMul = accMul;
|
|
|
530
568
|
exports.accSub = accSub;
|
|
531
569
|
exports.cutTimeFn = cutTimeFn;
|
|
532
570
|
exports.digitCnUppercase = digitCnUppercase;
|
|
571
|
+
exports.disableBrowserZoom = disableBrowserZoom;
|
|
533
572
|
exports.download = download;
|
|
534
573
|
exports.fileReaderToBase64 = fileReaderToBase64;
|
|
535
574
|
exports.format10k = format10k;
|
package/lib/lgutils.cjs.prod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("qs"),t=require("d3-format"),r=require("lodash/omit"),o=require("moment");function s(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var n=s(r),a=s(o);const i=(...e)=>{console.group("====================="),console.info(...e),console.groupEnd()},c="undefined"!=typeof window,l=e=>e&&"number"==typeof e.size&&"string"==typeof e.type&&"function"==typeof e.slice,d=c?localStorage:{};let p={};const u=t.format(",.2f"),m=t.format(","),h=t.format(".2%"),f=y(u),x=y(m),g=y(h);function y(e){return t=>S(t)?v:e(t)}const w=e=>u(e/1e4),M=y(w),D=(b="增信",function(e){return e?b:"不"+b});var b;const S=e=>null==e||""===e,v="——";function Y(e,t="YYYY-MM-DD"){return a(new Date(e)).format(t)}const A=y(Y),T={d:"天",m:"个月",y:"年"};function R(e){return e?`${parseInt(e,10)}${T[e.slice(-1).toLowerCase()]}`:e}const k=y(R);exports.DATE_FORMAT="YYYY/MM/DD",exports.FORMAT_DATE="YYYY-MM-DD",exports.FORMAT_TIME="YYYY-MM-DD HH:mm:ss",exports.NIL_STRING=v,exports.WS=class{constructor(e,t){this.socket=null,this.timer=null,this.ioUrl="",this.heartTime=1e4;this.ioUrl=e,this.socket=t?new WebSocket(e,t):new WebSocket(e)}init(e){const t=this;t.heartInfo=(null==e?void 0:e.heartInfo)?JSON.stringify(null==e?void 0:e.heartInfo):"ws HeartBeat!",t.socket.addEventListener("open",(()=>{i("ws connect!"),t.start(t.heartInfo),e.open&&e.open()}),!1),t.socket.addEventListener("disconnect",(()=>{console.info("[ws info]: disconnect and reconnect... "),e.disconnect&&e.disconnect(),t.socket=new WebSocket(t.ioUrl)}),!1),t.socket.addEventListener("error",(t=>{console.info("---------------"),console.info("[ws error]: "),console.info(t),console.info("---------------"),e.error&&e.error()}),!1),t.socket.addEventListener("close",e.close,!1),t.socket.addEventListener("message",(r=>{t.reset(),e.msg(r)}),!1)}close(){this.timer&&clearTimeout(this.timer),console.info("[ws close]: close!"),this.socket.close()}start(e){const t=this;t.timer=setTimeout((()=>{t.socket.send(e)}),t.heartTime)}send(e){this.socket.send(e)}reset(){const e=this;clearTimeout(e.timer),e.start(e.heartInfo)}getSocketState(){return this.socket.readyState}setHeartTime(e){this.heartTime=e,this.reset()}},exports.accAdd=(e,t)=>{let r,o,s;try{r=e.toString().split(".")[1].length}catch(n){r=0}try{o=t.toString().split(".")[1].length}catch(n){o=0}return s=Math.pow(10,Math.max(r,o)),(e*s+t*s)/s},exports.accDiv=(e,t)=>{let r,o,s=0,n=0;try{s=e.toString().split(".")[1].length}catch(a){}try{n=t.toString().split(".")[1].length}catch(a){}return r=Number(e.toString().replace(".","")),o=Number(t.toString().replace(".","")),r/o*Math.pow(10,n-s)},exports.accMul=(e,t)=>{let r=0,o=e.toString(),s=t.toString();try{r+=o.split(".")[1].length}catch(n){}try{r+=s.split(".")[1].length}catch(n){}return Number(o.replace(".",""))*Number(s.replace(".",""))/Math.pow(10,r)},exports.accSub=function(e,t){let r,o,s,n;try{r=e.toString().split(".")[1].length}catch(a){r=0}try{o=t.toString().split(".")[1].length}catch(a){o=0}return s=Math.pow(10,Math.max(r,o)),n=r>=o?r:o,((e*s-t*s)/s).toFixed(n)},exports.cutTimeFn=e=>`00‘${0===e?"00":"0"+Math.floor(e/60)}’${0===e?"00":e%60>=10?e%60:"0"+e%60}`,exports.digitCnUppercase=function(e){var t=["角","分"],r=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],o=[["元","万","亿"],["","拾","佰","仟"]],s=e<0?"欠":"";e=Math.abs(e);for(var n="",a=0;a<t.length;a++)n+=(r[Math.floor(10*e*Math.pow(10,a))%10]+t[a]).replace(/零./,"");for(n=n||"整",e=Math.floor(e),a=0;a<o[0].length&&e>0;a++){for(var i="",c=0;c<o[1].length&&e>0;c++)i=r[e%10]+o[1][c]+i,e=Math.floor(e/10);n=i.replace(/(零.)*零$/,"").replace(/^$/,"零")+o[0][a]+n}return s+n.replace(/(零.)*零元/,"元").replace(/(零.)+/g,"零").replace(/^整$/,"零元整")},exports.disableBrowserZoom=function(){document.addEventListener("keydown",(function(e){!0!==e.ctrlKey&&!0!==e.metaKey||61!==e.which&&107!==e.which&&173!==e.which&&109!==e.which&&187!==e.which&&189!==e.which||e.preventDefault()}),!1),window.addEventListener("mousewheel",(function(e){(!0===e.ctrlKey||e.metaKey)&&e.preventDefault()}),{passive:!1}),window.addEventListener("DOMMouseScroll",(function(e){(!0===e.ctrlKey||e.metaKey)&&e.preventDefault()}),{passive:!1})},exports.download=(e,t="download",r="application/octet-stream",o)=>{const s=window;let n=r,a=e;const i=document,c=i.createElement("a"),l=e=>String(e),d=s.Blob||l(c),p=t;let u=null,m=null;const h=(t,r)=>{if("download"in c)return c.href=o?e:t,c.setAttribute("download",p),c.innerHTML="downloading...",i.body.appendChild(c),setTimeout((()=>{c.click(),i.body.removeChild(c),!0===r&&setTimeout((()=>{s.URL.revokeObjectURL(c.href)}),250)}),66),!0;const n=i.createElement("iframe");i.body.appendChild(n),r||(t="data:"+t.replace(/^data:([\w\/\-\+]+)/,"application/octet-stream")),n.src=t,setTimeout((()=>{i.body.removeChild(n)}),333)};if(String(a).match(/^data\:[\w+\-]+\/[\w+\-]+[,;]/))return h(a);try{u=a instanceof d?a:new d([a],{type:n})}catch(f){}if(s.URL)h(s.URL.createObjectURL(u),!0);else{if("string"==typeof u||u.constructor===l(c))try{return h("data:"+n+";base64,"+s.btoa(u))}catch(f){return h("data:"+n+","+encodeURIComponent(u))}m=new FileReader,m.onload=function(){h(this.result)},m.readAsDataURL(u)}return!0},exports.fileReaderToBase64=e=>t=>{const r=new FileReader;r.onload=e=>{t&&t(e.target.result)},r.readAsDataURL(e)},exports.format10k=w,exports.format10kNil=M,exports.formatCash=u,exports.formatCash2=e=>(Math.floor(100*e)/100).toFixed(2),exports.formatCashInt=m,exports.formatCashIntNil=x,exports.formatCashNil=f,exports.formatCreditEnhanced=D,exports.formatDate=Y,exports.formatDateNil=A,exports.formatDuration=R,exports.formatDurationNil=k,exports.formatRatio=h,exports.formatRatioNil=g,exports.getBase64=e=>new Promise(((t,r)=>{const o=new FileReader;o.readAsDataURL(e),o.onload=()=>t(o.result),o.onerror=e=>r(e)})),exports.getItem=e=>((p[e]||d.getItem(""+e))&&(p[e]=JSON.parse(d.getItem(""+e)||"null")),p[e]),exports.getQueryObject=(t=window.location.href)=>{const r=t.split("?")[1];return e.parse(r||"")},exports.getSearchParams=e=>new URLSearchParams(e),exports.getValOfArr=e=>{const t=e.length,r=e.reduce(((e,t)=>e+t),0),o=e.reduce(((e,t)=>e*t),1);return{min:Math.min.apply(null,e),max:Math.max.apply(null,e),sum:r,average:r/t,mull:o}},exports.getValueWithNil=e=>S(e)?v:e,exports.inBrowser=c,exports.isArray=e=>Array.isArray(e),exports.isBlob=l,exports.isCardNo=e=>/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/.test(e),exports.isDate=e=>e instanceof Date,exports.isEmail=e=>/^(.+)@(.+)\.(.+)$/.test(e),exports.isFile=e=>l(e)&&"string"==typeof e.name&&("object"==typeof e.lastModifiedDate||"number"==typeof e.lastModified),exports.isNil=S,exports.isNull=e=>null===e,exports.isObject=e=>e===Object(e),exports.isPhone=e=>/^[1](\d{10})$/.test(e),exports.isSMSCode=e=>e.match(/^\d{6}$/),exports.isUndefined=e=>void 0===e,exports.log=i,exports.normalizeFormValues=function(e){return Object.entries(e).filter((([e,t])=>void 0!==t&&"all"!==t)).reduce(((e,[t,r])=>(Array.isArray(r)&&r.some((e=>a.isMoment(e)))?(r[0]&&(e.startDate=r[0].format("YYYY-MM-DD")),r[1]&&(e.endDate=r[1].format("YYYY-MM-DD"))):e[t]=a.isMoment(r)?r.format("YYYY-MM-DD"):r,e)),{})},exports.normalizeSearchParams=function(e){return(e.startDate||e.endDate)&&(e=Object.assign(Object.assign({},n(e,["startDate","endDate"])),{dateRange:[e.startDate&&a(e.startDate),e.endDate&&a(e.endDate)]})),Object.entries(e).forEach((([t,r])=>{"string"==typeof r&&r.includes(",")&&(e[t]="all")})),e},exports.os=()=>{if(!c)return{isTablet:!1,isPhone:!1,isAndroid:!1,isPc:!1};const e=navigator.userAgent,t=/(?:Windows Phone)/.test(e),r=/(?:SymbianOS)/.test(e)||t,o=/(?:Android)/.test(e),s=/(?:Firefox)/.test(e),n=/(?:iPad|PlayBook)/.test(e)||o&&!/(?:Mobile)/.test(e)||s&&/(?:Tablet)/.test(e),a=/(?:iPhone)/.test(e)&&!n;return{isTablet:n,isPhone:a,isAndroid:o,isPc:!a&&!o&&!r}},exports.playAudio=e=>{const t=document.querySelectorAll("audio");Array.from(t).forEach((e=>{e.pause(),e.currentTime=0})),document.querySelector(`#${e}`).play()},exports.random=(e,t)=>Math.round(Math.random()*(t-e)+e),exports.randomString=(e=32)=>{const t="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",r=t.length;let o="";for(let s=0;s<e;s++)o+=t.charAt(Math.floor(Math.random()*r));return o},exports.removeAll=()=>(p={},d.clear()),exports.removeItem=e=>(delete p[e],d.removeItem(""+e)),exports.setItem=(e,t)=>(p[e]=t,d.setItem(""+e,JSON.stringify(t))),exports.setProxyObj=(e,t,r)=>new Proxy(e,{get:(e,r)=>(t(),Reflect.get(e,r)),set:(e,t,o)=>(r(),Reflect.set(e,t,o))}),exports.sortObj=(e,t,r="asc")=>e.sort(((e,o)=>"asc"===r?o[t]-e[t]:e[t]-o[t])),exports.sumObj=(e,t)=>e.reduce(((e,r)=>r[t]+e),0),exports.trimString=e=>e.replace(/(^\s*)|(\s*$)/g,"");
|
|
@@ -456,9 +456,12 @@ class WS {
|
|
|
456
456
|
}
|
|
457
457
|
init(obj) {
|
|
458
458
|
const that = this;
|
|
459
|
+
that.heartInfo = (obj === null || obj === void 0 ? void 0 : obj.heartInfo)
|
|
460
|
+
? JSON.stringify(obj === null || obj === void 0 ? void 0 : obj.heartInfo)
|
|
461
|
+
: `ws HeartBeat!`;
|
|
459
462
|
that.socket.addEventListener('open', () => {
|
|
460
463
|
log('ws connect!');
|
|
461
|
-
that.start(
|
|
464
|
+
that.start(that.heartInfo);
|
|
462
465
|
if (obj.open)
|
|
463
466
|
obj.open();
|
|
464
467
|
}, false);
|
|
@@ -499,15 +502,50 @@ class WS {
|
|
|
499
502
|
that.socket.send(msg);
|
|
500
503
|
}
|
|
501
504
|
reset() {
|
|
502
|
-
|
|
503
|
-
|
|
505
|
+
const that = this;
|
|
506
|
+
clearTimeout(that.timer);
|
|
507
|
+
that.start(that.heartInfo);
|
|
504
508
|
}
|
|
505
509
|
getSocketState() {
|
|
506
510
|
return this.socket.readyState;
|
|
507
511
|
}
|
|
508
512
|
setHeartTime(time) {
|
|
509
|
-
|
|
513
|
+
const that = this;
|
|
514
|
+
that.heartTime = time;
|
|
515
|
+
that.reset();
|
|
510
516
|
}
|
|
511
517
|
}
|
|
512
518
|
|
|
513
|
-
|
|
519
|
+
function disableBrowserZoom() {
|
|
520
|
+
// @ts-ignore
|
|
521
|
+
document.addEventListener('keydown', function (event) {
|
|
522
|
+
if ((event.ctrlKey === true || event.metaKey === true) &&
|
|
523
|
+
(event.which === 61 ||
|
|
524
|
+
event.which === 107 ||
|
|
525
|
+
event.which === 173 ||
|
|
526
|
+
event.which === 109 ||
|
|
527
|
+
event.which === 187 ||
|
|
528
|
+
event.which === 189)) {
|
|
529
|
+
event.preventDefault();
|
|
530
|
+
}
|
|
531
|
+
}, false);
|
|
532
|
+
// @ts-ignore
|
|
533
|
+
window.addEventListener('mousewheel', function (event) {
|
|
534
|
+
// @ts-ignore
|
|
535
|
+
if (event.ctrlKey === true || event.metaKey) {
|
|
536
|
+
event.preventDefault();
|
|
537
|
+
}
|
|
538
|
+
}, {
|
|
539
|
+
passive: false,
|
|
540
|
+
});
|
|
541
|
+
window.addEventListener('DOMMouseScroll', function (event) {
|
|
542
|
+
// @ts-ignore
|
|
543
|
+
if (event.ctrlKey === true || event.metaKey) {
|
|
544
|
+
event.preventDefault();
|
|
545
|
+
}
|
|
546
|
+
}, {
|
|
547
|
+
passive: false,
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
export { DATE_FORMAT, FORMAT_DATE, FORMAT_TIME, NIL_STRING, WS, accAdd, accDiv, accMul, accSub, cutTimeFn, digitCnUppercase, disableBrowserZoom, download, fileReaderToBase64, format10k, format10kNil, formatCash, formatCash2, formatCashInt, formatCashIntNil, formatCashNil, formatCreditEnhanced, formatDate, formatDateNil, formatDuration, formatDurationNil, formatRatio, formatRatioNil, getBase64, getItem, getQueryObject, getSearchParams, getValOfArr, getValueWithNil, inBrowser, isArray, isBlob, isCardNo, isDate, isEmail, isFile, isNil, isNull, isObject, isPhone, isSMSCode, isUndefined, log, normalizeFormValues, normalizeSearchParams, os, playAudio, random, randomString, removeAll, removeItem, setItem, setProxyObj, sortObj, sumObj, trimString };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lgutils",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.12",
|
|
4
4
|
"description": "lgutils",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "lib/lgutils.cjs.prod.js",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"@types/moment": "^2.13.0",
|
|
36
36
|
"@types/qs": "^6.9.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "96b76a80b0f40c9706a622cb9b7f07bb24735811"
|
|
39
39
|
}
|