lgutils 1.3.11 → 1.3.14
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 +19 -36
- package/lib/lgutils.cjs.js +84 -48
- package/lib/lgutils.cjs.prod.js +1 -1
- package/lib/lgutils.esm-bundler.js +83 -45
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -6,22 +6,24 @@ export declare const accMul: (arg1: number, arg2: number) => number
|
|
|
6
6
|
|
|
7
7
|
export declare const accSub: (arg1: number, arg2: number) => string
|
|
8
8
|
|
|
9
|
+
export declare function copyToClipboard(txt: string): void
|
|
10
|
+
|
|
9
11
|
export declare const cutTimeFn: (n: number) => string
|
|
10
12
|
|
|
11
13
|
export declare const DATE_FORMAT = 'YYYY/MM/DD'
|
|
12
14
|
|
|
13
15
|
export declare function digitCnUppercase(n: number): string
|
|
14
16
|
|
|
17
|
+
export declare function disableBrowserZoom(): void
|
|
18
|
+
|
|
15
19
|
export declare const download: (
|
|
16
20
|
data: string,
|
|
17
21
|
strFileName?: string,
|
|
18
22
|
strMimeType?: string,
|
|
19
|
-
isImgUrl?: boolean | undefined
|
|
23
|
+
isImgUrl?: boolean | undefined,
|
|
20
24
|
) => true | undefined
|
|
21
25
|
|
|
22
|
-
export declare const fileReaderToBase64: (
|
|
23
|
-
target: any
|
|
24
|
-
) => (cb: (p: any) => void) => void
|
|
26
|
+
export declare const fileReaderToBase64: (target: any) => (cb: (p: any) => void) => void
|
|
25
27
|
|
|
26
28
|
export declare const format10k: (n: number) => string
|
|
27
29
|
|
|
@@ -36,7 +38,7 @@ export declare const formatCash: (
|
|
|
36
38
|
| number
|
|
37
39
|
| {
|
|
38
40
|
valueOf(): number
|
|
39
|
-
}
|
|
41
|
+
},
|
|
40
42
|
) => string
|
|
41
43
|
|
|
42
44
|
export declare const formatCash2: (num: number) => string
|
|
@@ -46,7 +48,7 @@ export declare const formatCashInt: (
|
|
|
46
48
|
| number
|
|
47
49
|
| {
|
|
48
50
|
valueOf(): number
|
|
49
|
-
}
|
|
51
|
+
},
|
|
50
52
|
) => string
|
|
51
53
|
|
|
52
54
|
export declare const formatCashIntNil: (
|
|
@@ -55,7 +57,7 @@ export declare const formatCashIntNil: (
|
|
|
55
57
|
| {
|
|
56
58
|
valueOf(): number
|
|
57
59
|
}
|
|
58
|
-
| NIL
|
|
60
|
+
| NIL,
|
|
59
61
|
) => string
|
|
60
62
|
|
|
61
63
|
export declare const formatCashNil: (
|
|
@@ -64,19 +66,12 @@ export declare const formatCashNil: (
|
|
|
64
66
|
| {
|
|
65
67
|
valueOf(): number
|
|
66
68
|
}
|
|
67
|
-
| NIL
|
|
69
|
+
| NIL,
|
|
68
70
|
) => string
|
|
69
71
|
|
|
70
|
-
export declare
|
|
71
|
-
|
|
72
|
-
export declare function formatDate(
|
|
73
|
-
d: string | number,
|
|
74
|
-
formatType?: string
|
|
75
|
-
): string
|
|
72
|
+
export declare function formatDate(d: string | number, formatType?: string): string
|
|
76
73
|
|
|
77
|
-
export declare const formatDateNil: (
|
|
78
|
-
d: string | number | null | undefined
|
|
79
|
-
) => string
|
|
74
|
+
export declare const formatDateNil: (d: string | number | null | undefined) => string
|
|
80
75
|
|
|
81
76
|
export declare function formatDuration(period: string): string
|
|
82
77
|
|
|
@@ -87,7 +82,7 @@ export declare const formatRatio: (
|
|
|
87
82
|
| number
|
|
88
83
|
| {
|
|
89
84
|
valueOf(): number
|
|
90
|
-
}
|
|
85
|
+
},
|
|
91
86
|
) => string
|
|
92
87
|
|
|
93
88
|
export declare const formatRatioNil: (
|
|
@@ -96,7 +91,7 @@ export declare const formatRatioNil: (
|
|
|
96
91
|
| {
|
|
97
92
|
valueOf(): number
|
|
98
93
|
}
|
|
99
|
-
| NIL
|
|
94
|
+
| NIL,
|
|
100
95
|
) => string
|
|
101
96
|
|
|
102
97
|
export declare const getBase64: (file: File) => Promise<unknown>
|
|
@@ -119,10 +114,6 @@ export declare const getValueWithNil: (val: any) => any
|
|
|
119
114
|
|
|
120
115
|
export declare const inBrowser: boolean
|
|
121
116
|
|
|
122
|
-
declare type IndexType = {
|
|
123
|
-
[x: string]: any
|
|
124
|
-
}
|
|
125
|
-
|
|
126
117
|
export declare const isArray: (value: any) => boolean
|
|
127
118
|
|
|
128
119
|
export declare const isBlob: (value: any) => any
|
|
@@ -162,10 +153,6 @@ declare type NIL = undefined | null | ''
|
|
|
162
153
|
|
|
163
154
|
export declare const NIL_STRING = '\u2014\u2014'
|
|
164
155
|
|
|
165
|
-
export declare function normalizeFormValues<T extends IndexType>(values: T): any
|
|
166
|
-
|
|
167
|
-
export declare function normalizeSearchParams(params: IndexType): IndexType
|
|
168
|
-
|
|
169
156
|
export declare const os: () => {
|
|
170
157
|
isTablet: boolean
|
|
171
158
|
isPhone: boolean
|
|
@@ -185,31 +172,27 @@ export declare const removeItem: (key: string) => any
|
|
|
185
172
|
|
|
186
173
|
export declare const setItem: (key: string, value: any) => any
|
|
187
174
|
|
|
188
|
-
export declare const setProxyObj: (
|
|
189
|
-
data: object,
|
|
190
|
-
getFn: () => void,
|
|
191
|
-
setFn: () => void
|
|
192
|
-
) => object
|
|
175
|
+
export declare const setProxyObj: (data: object, getFn: () => void, setFn: () => void) => object
|
|
193
176
|
|
|
194
177
|
export declare const sortObj: <
|
|
195
178
|
T extends keyof D,
|
|
196
179
|
D extends {
|
|
197
180
|
[key: string]: any
|
|
198
|
-
}
|
|
181
|
+
},
|
|
199
182
|
>(
|
|
200
183
|
obj: D[],
|
|
201
184
|
property: T,
|
|
202
|
-
type?: 'asc' | 'desc'
|
|
185
|
+
type?: 'asc' | 'desc',
|
|
203
186
|
) => D[]
|
|
204
187
|
|
|
205
188
|
export declare const sumObj: <
|
|
206
189
|
T extends keyof D,
|
|
207
190
|
D extends {
|
|
208
191
|
[key: string]: any
|
|
209
|
-
}
|
|
192
|
+
},
|
|
210
193
|
>(
|
|
211
194
|
obj: D[],
|
|
212
|
-
key: T
|
|
195
|
+
key: T,
|
|
213
196
|
) => number
|
|
214
197
|
|
|
215
198
|
export declare const trimString: (str: string) => string
|
package/lib/lgutils.cjs.js
CHANGED
|
@@ -4,12 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var qs = require('qs');
|
|
6
6
|
var d3Format = require('d3-format');
|
|
7
|
-
var omit = require('lodash/omit');
|
|
8
7
|
var moment = require('moment');
|
|
9
8
|
|
|
10
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
|
|
11
10
|
|
|
12
|
-
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
|
|
13
11
|
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
14
12
|
|
|
15
13
|
const log = (...rest) => {
|
|
@@ -238,49 +236,44 @@ const SERVER_DATE_FROMAT = 'YYYY-MM-DD';
|
|
|
238
236
|
const DATE_FORMAT = 'YYYY/MM/DD';
|
|
239
237
|
const FORMAT_DATE = SERVER_DATE_FROMAT;
|
|
240
238
|
const FORMAT_TIME = 'YYYY-MM-DD HH:mm:ss';
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
return function (yes) {
|
|
278
|
-
return yes ? field : '不' + field;
|
|
279
|
-
};
|
|
280
|
-
}
|
|
239
|
+
// type IndexType = { [x: string]: any }
|
|
240
|
+
// export function normalizeFormValues<T extends IndexType>(values: T) {
|
|
241
|
+
// return Object.entries(values)
|
|
242
|
+
// .filter(([key, value]) => value !== undefined && value !== 'all')
|
|
243
|
+
// .reduce((mem: any, [key, value]) => {
|
|
244
|
+
// // array for [moment, moment]
|
|
245
|
+
// if (Array.isArray(value) && value.some((val) => moment.isMoment(val))) {
|
|
246
|
+
// if (value[0]) {
|
|
247
|
+
// mem.startDate = value[0].format(SERVER_DATE_FROMAT)
|
|
248
|
+
// }
|
|
249
|
+
// if (value[1]) {
|
|
250
|
+
// mem.endDate = value[1].format(SERVER_DATE_FROMAT)
|
|
251
|
+
// }
|
|
252
|
+
// } else if (moment.isMoment(value)) {
|
|
253
|
+
// mem[key] = value.format(SERVER_DATE_FROMAT)
|
|
254
|
+
// } else mem[key] = value
|
|
255
|
+
// return mem
|
|
256
|
+
// }, {} as T)
|
|
257
|
+
// }
|
|
258
|
+
// export function normalizeSearchParams(params: IndexType) {
|
|
259
|
+
// if (params.startDate || params.endDate) {
|
|
260
|
+
// params = {
|
|
261
|
+
// ...omit(params, ['startDate', 'endDate']),
|
|
262
|
+
// dateRange: [
|
|
263
|
+
// params.startDate && moment(params.startDate),
|
|
264
|
+
// params.endDate && moment(params.endDate),
|
|
265
|
+
// ],
|
|
266
|
+
// }
|
|
267
|
+
// }
|
|
268
|
+
// Object.entries(params).forEach(([key, value]) => {
|
|
269
|
+
// if (typeof value === 'string' && value.includes(',')) {
|
|
270
|
+
// params[key] = 'all'
|
|
271
|
+
// }
|
|
272
|
+
// })
|
|
273
|
+
// return params
|
|
274
|
+
// }
|
|
281
275
|
const format10k = (n) => formatCash(n / 10000);
|
|
282
276
|
const format10kNil = withDefaultNil(format10k);
|
|
283
|
-
const formatCreditEnhanced = formatBool('增信');
|
|
284
277
|
// null == undefined
|
|
285
278
|
const isNil = (val) => val == null || val === '';
|
|
286
279
|
const NIL_STRING = '——';
|
|
@@ -289,7 +282,10 @@ const getValueWithNil = (val) => (isNil(val) ? NIL_STRING : val);
|
|
|
289
282
|
function digitCnUppercase(n) {
|
|
290
283
|
var fraction = ['角', '分'];
|
|
291
284
|
var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
292
|
-
var unit = [
|
|
285
|
+
var unit = [
|
|
286
|
+
['元', '万', '亿'],
|
|
287
|
+
['', '拾', '佰', '仟'],
|
|
288
|
+
];
|
|
293
289
|
var head = n < 0 ? '欠' : '';
|
|
294
290
|
n = Math.abs(n);
|
|
295
291
|
var s = '';
|
|
@@ -319,7 +315,7 @@ const formatDateNil = withDefaultNil(formatDate);
|
|
|
319
315
|
const unit = {
|
|
320
316
|
d: '天',
|
|
321
317
|
m: '个月',
|
|
322
|
-
y: '年'
|
|
318
|
+
y: '年',
|
|
323
319
|
};
|
|
324
320
|
function formatDuration(period) {
|
|
325
321
|
if (!period)
|
|
@@ -525,6 +521,47 @@ class WS {
|
|
|
525
521
|
}
|
|
526
522
|
}
|
|
527
523
|
|
|
524
|
+
function disableBrowserZoom() {
|
|
525
|
+
// @ts-ignore
|
|
526
|
+
document.addEventListener('keydown', function (event) {
|
|
527
|
+
if ((event.ctrlKey === true || event.metaKey === true) &&
|
|
528
|
+
(event.which === 61 ||
|
|
529
|
+
event.which === 107 ||
|
|
530
|
+
event.which === 173 ||
|
|
531
|
+
event.which === 109 ||
|
|
532
|
+
event.which === 187 ||
|
|
533
|
+
event.which === 189)) {
|
|
534
|
+
event.preventDefault();
|
|
535
|
+
}
|
|
536
|
+
}, false);
|
|
537
|
+
// @ts-ignore
|
|
538
|
+
window.addEventListener('mousewheel', function (event) {
|
|
539
|
+
// @ts-ignore
|
|
540
|
+
if (event.ctrlKey === true || event.metaKey) {
|
|
541
|
+
event.preventDefault();
|
|
542
|
+
}
|
|
543
|
+
}, {
|
|
544
|
+
passive: false,
|
|
545
|
+
});
|
|
546
|
+
window.addEventListener('DOMMouseScroll', function (event) {
|
|
547
|
+
// @ts-ignore
|
|
548
|
+
if (event.ctrlKey === true || event.metaKey) {
|
|
549
|
+
event.preventDefault();
|
|
550
|
+
}
|
|
551
|
+
}, {
|
|
552
|
+
passive: false,
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
function copyToClipboard(txt) {
|
|
557
|
+
var textarea = document.createElement('textarea');
|
|
558
|
+
textarea.value = txt;
|
|
559
|
+
document.body.appendChild(textarea);
|
|
560
|
+
textarea.select();
|
|
561
|
+
document.execCommand('copy');
|
|
562
|
+
document.body.removeChild(textarea);
|
|
563
|
+
}
|
|
564
|
+
|
|
528
565
|
exports.DATE_FORMAT = DATE_FORMAT;
|
|
529
566
|
exports.FORMAT_DATE = FORMAT_DATE;
|
|
530
567
|
exports.FORMAT_TIME = FORMAT_TIME;
|
|
@@ -534,8 +571,10 @@ exports.accAdd = accAdd;
|
|
|
534
571
|
exports.accDiv = accDiv;
|
|
535
572
|
exports.accMul = accMul;
|
|
536
573
|
exports.accSub = accSub;
|
|
574
|
+
exports.copyToClipboard = copyToClipboard;
|
|
537
575
|
exports.cutTimeFn = cutTimeFn;
|
|
538
576
|
exports.digitCnUppercase = digitCnUppercase;
|
|
577
|
+
exports.disableBrowserZoom = disableBrowserZoom;
|
|
539
578
|
exports.download = download;
|
|
540
579
|
exports.fileReaderToBase64 = fileReaderToBase64;
|
|
541
580
|
exports.format10k = format10k;
|
|
@@ -545,7 +584,6 @@ exports.formatCash2 = formatCash2;
|
|
|
545
584
|
exports.formatCashInt = formatCashInt;
|
|
546
585
|
exports.formatCashIntNil = formatCashIntNil;
|
|
547
586
|
exports.formatCashNil = formatCashNil;
|
|
548
|
-
exports.formatCreditEnhanced = formatCreditEnhanced;
|
|
549
587
|
exports.formatDate = formatDate;
|
|
550
588
|
exports.formatDateNil = formatDateNil;
|
|
551
589
|
exports.formatDuration = formatDuration;
|
|
@@ -572,8 +610,6 @@ exports.isPhone = isPhone;
|
|
|
572
610
|
exports.isSMSCode = isSMSCode;
|
|
573
611
|
exports.isUndefined = isUndefined;
|
|
574
612
|
exports.log = log;
|
|
575
|
-
exports.normalizeFormValues = normalizeFormValues;
|
|
576
|
-
exports.normalizeSearchParams = normalizeSearchParams;
|
|
577
613
|
exports.os = os;
|
|
578
614
|
exports.playAudio = playAudio;
|
|
579
615
|
exports.random = random;
|
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");function o(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var r=o(require("moment"));const s=(...e)=>{console.group("====================="),console.info(...e),console.groupEnd()},n="undefined"!=typeof window,a=e=>e&&"number"==typeof e.size&&"string"==typeof e.type&&"function"==typeof e.slice,i=n?localStorage:{};let c={};const l=t.format(",.2f"),p=t.format(","),d=t.format(".2%"),u=f(l),h=f(p),m=f(d);function f(e){return t=>y(t)?w:e(t)}const x=e=>l(e/1e4),g=f(x),y=e=>null==e||""===e,w="——";function b(e,t="YYYY-MM-DD"){return r(new Date(e)).format(t)}const M=f(b),S={d:"天",m:"个月",y:"年"};function v(e){return e?`${parseInt(e,10)}${S[e.slice(-1).toLowerCase()]}`:e}const D=f(v);exports.DATE_FORMAT="YYYY/MM/DD",exports.FORMAT_DATE="YYYY-MM-DD",exports.FORMAT_TIME="YYYY-MM-DD HH:mm:ss",exports.NIL_STRING=w,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",(()=>{s("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",(o=>{t.reset(),e.msg(o)}),!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 o,r,s;try{o=e.toString().split(".")[1].length}catch(n){o=0}try{r=t.toString().split(".")[1].length}catch(n){r=0}return s=Math.pow(10,Math.max(o,r)),(e*s+t*s)/s},exports.accDiv=(e,t)=>{let o,r,s=0,n=0;try{s=e.toString().split(".")[1].length}catch(a){}try{n=t.toString().split(".")[1].length}catch(a){}return o=Number(e.toString().replace(".","")),r=Number(t.toString().replace(".","")),o/r*Math.pow(10,n-s)},exports.accMul=(e,t)=>{let o=0,r=e.toString(),s=t.toString();try{o+=r.split(".")[1].length}catch(n){}try{o+=s.split(".")[1].length}catch(n){}return Number(r.replace(".",""))*Number(s.replace(".",""))/Math.pow(10,o)},exports.accSub=function(e,t){let o,r,s,n;try{o=e.toString().split(".")[1].length}catch(a){o=0}try{r=t.toString().split(".")[1].length}catch(a){r=0}return s=Math.pow(10,Math.max(o,r)),n=o>=r?o:r,((e*s-t*s)/s).toFixed(n)},exports.copyToClipboard=function(e){var t=document.createElement("textarea");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)},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=["角","分"],o=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],r=[["元","万","亿"],["","拾","佰","仟"]],s=e<0?"欠":"";e=Math.abs(e);for(var n="",a=0;a<t.length;a++)n+=(o[Math.floor(10*e*Math.pow(10,a))%10]+t[a]).replace(/零./,"");for(n=n||"整",e=Math.floor(e),a=0;a<r[0].length&&e>0;a++){for(var i="",c=0;c<r[1].length&&e>0;c++)i=o[e%10]+r[1][c]+i,e=Math.floor(e/10);n=i.replace(/(零.)*零$/,"").replace(/^$/,"零")+r[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",o="application/octet-stream",r)=>{const s=window;let n=o,a=e;const i=document,c=i.createElement("a"),l=e=>String(e),p=s.Blob||l(c),d=t;let u=null,h=null;const m=(t,o)=>{if("download"in c)return c.href=r?e:t,c.setAttribute("download",d),c.innerHTML="downloading...",i.body.appendChild(c),setTimeout((()=>{c.click(),i.body.removeChild(c),!0===o&&setTimeout((()=>{s.URL.revokeObjectURL(c.href)}),250)}),66),!0;const n=i.createElement("iframe");i.body.appendChild(n),o||(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 m(a);try{u=a instanceof p?a:new p([a],{type:n})}catch(f){}if(s.URL)m(s.URL.createObjectURL(u),!0);else{if("string"==typeof u||u.constructor===l(c))try{return m("data:"+n+";base64,"+s.btoa(u))}catch(f){return m("data:"+n+","+encodeURIComponent(u))}h=new FileReader,h.onload=function(){m(this.result)},h.readAsDataURL(u)}return!0},exports.fileReaderToBase64=e=>t=>{const o=new FileReader;o.onload=e=>{t&&t(e.target.result)},o.readAsDataURL(e)},exports.format10k=x,exports.format10kNil=g,exports.formatCash=l,exports.formatCash2=e=>(Math.floor(100*e)/100).toFixed(2),exports.formatCashInt=p,exports.formatCashIntNil=h,exports.formatCashNil=u,exports.formatDate=b,exports.formatDateNil=M,exports.formatDuration=v,exports.formatDurationNil=D,exports.formatRatio=d,exports.formatRatioNil=m,exports.getBase64=e=>new Promise(((t,o)=>{const r=new FileReader;r.readAsDataURL(e),r.onload=()=>t(r.result),r.onerror=e=>o(e)})),exports.getItem=e=>((c[e]||i.getItem(""+e))&&(c[e]=JSON.parse(i.getItem(""+e)||"null")),c[e]),exports.getQueryObject=(t=window.location.href)=>{const o=t.split("?")[1];return e.parse(o||"")},exports.getSearchParams=e=>new URLSearchParams(e),exports.getValOfArr=e=>{const t=e.length,o=e.reduce(((e,t)=>e+t),0),r=e.reduce(((e,t)=>e*t),1);return{min:Math.min.apply(null,e),max:Math.max.apply(null,e),sum:o,average:o/t,mull:r}},exports.getValueWithNil=e=>y(e)?w:e,exports.inBrowser=n,exports.isArray=e=>Array.isArray(e),exports.isBlob=a,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=>a(e)&&"string"==typeof e.name&&("object"==typeof e.lastModifiedDate||"number"==typeof e.lastModified),exports.isNil=y,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=s,exports.os=()=>{if(!n)return{isTablet:!1,isPhone:!1,isAndroid:!1,isPc:!1};const e=navigator.userAgent,t=/(?:Windows Phone)/.test(e),o=/(?:SymbianOS)/.test(e)||t,r=/(?:Android)/.test(e),s=/(?:Firefox)/.test(e),a=/(?:iPad|PlayBook)/.test(e)||r&&!/(?:Mobile)/.test(e)||s&&/(?:Tablet)/.test(e),i=/(?:iPhone)/.test(e)&&!a;return{isTablet:a,isPhone:i,isAndroid:r,isPc:!i&&!r&&!o}},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",o=t.length;let r="";for(let s=0;s<e;s++)r+=t.charAt(Math.floor(Math.random()*o));return r},exports.removeAll=()=>(c={},i.clear()),exports.removeItem=e=>(delete c[e],i.removeItem(""+e)),exports.setItem=(e,t)=>(c[e]=t,i.setItem(""+e,JSON.stringify(t))),exports.setProxyObj=(e,t,o)=>new Proxy(e,{get:(e,o)=>(t(),Reflect.get(e,o)),set:(e,t,r)=>(o(),Reflect.set(e,t,r))}),exports.sortObj=(e,t,o="asc")=>e.sort(((e,r)=>"asc"===o?r[t]-e[t]:e[t]-r[t])),exports.sumObj=(e,t)=>e.reduce(((e,o)=>o[t]+e),0),exports.trimString=e=>e.replace(/(^\s*)|(\s*$)/g,"");
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { parse } from 'qs';
|
|
2
2
|
import { format } from 'd3-format';
|
|
3
|
-
import omit from 'lodash/omit';
|
|
4
3
|
import moment from 'moment';
|
|
5
4
|
|
|
6
5
|
const log = (...rest) => {
|
|
@@ -229,49 +228,44 @@ const SERVER_DATE_FROMAT = 'YYYY-MM-DD';
|
|
|
229
228
|
const DATE_FORMAT = 'YYYY/MM/DD';
|
|
230
229
|
const FORMAT_DATE = SERVER_DATE_FROMAT;
|
|
231
230
|
const FORMAT_TIME = 'YYYY-MM-DD HH:mm:ss';
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
return function (yes) {
|
|
269
|
-
return yes ? field : '不' + field;
|
|
270
|
-
};
|
|
271
|
-
}
|
|
231
|
+
// type IndexType = { [x: string]: any }
|
|
232
|
+
// export function normalizeFormValues<T extends IndexType>(values: T) {
|
|
233
|
+
// return Object.entries(values)
|
|
234
|
+
// .filter(([key, value]) => value !== undefined && value !== 'all')
|
|
235
|
+
// .reduce((mem: any, [key, value]) => {
|
|
236
|
+
// // array for [moment, moment]
|
|
237
|
+
// if (Array.isArray(value) && value.some((val) => moment.isMoment(val))) {
|
|
238
|
+
// if (value[0]) {
|
|
239
|
+
// mem.startDate = value[0].format(SERVER_DATE_FROMAT)
|
|
240
|
+
// }
|
|
241
|
+
// if (value[1]) {
|
|
242
|
+
// mem.endDate = value[1].format(SERVER_DATE_FROMAT)
|
|
243
|
+
// }
|
|
244
|
+
// } else if (moment.isMoment(value)) {
|
|
245
|
+
// mem[key] = value.format(SERVER_DATE_FROMAT)
|
|
246
|
+
// } else mem[key] = value
|
|
247
|
+
// return mem
|
|
248
|
+
// }, {} as T)
|
|
249
|
+
// }
|
|
250
|
+
// export function normalizeSearchParams(params: IndexType) {
|
|
251
|
+
// if (params.startDate || params.endDate) {
|
|
252
|
+
// params = {
|
|
253
|
+
// ...omit(params, ['startDate', 'endDate']),
|
|
254
|
+
// dateRange: [
|
|
255
|
+
// params.startDate && moment(params.startDate),
|
|
256
|
+
// params.endDate && moment(params.endDate),
|
|
257
|
+
// ],
|
|
258
|
+
// }
|
|
259
|
+
// }
|
|
260
|
+
// Object.entries(params).forEach(([key, value]) => {
|
|
261
|
+
// if (typeof value === 'string' && value.includes(',')) {
|
|
262
|
+
// params[key] = 'all'
|
|
263
|
+
// }
|
|
264
|
+
// })
|
|
265
|
+
// return params
|
|
266
|
+
// }
|
|
272
267
|
const format10k = (n) => formatCash(n / 10000);
|
|
273
268
|
const format10kNil = withDefaultNil(format10k);
|
|
274
|
-
const formatCreditEnhanced = formatBool('增信');
|
|
275
269
|
// null == undefined
|
|
276
270
|
const isNil = (val) => val == null || val === '';
|
|
277
271
|
const NIL_STRING = '——';
|
|
@@ -280,7 +274,10 @@ const getValueWithNil = (val) => (isNil(val) ? NIL_STRING : val);
|
|
|
280
274
|
function digitCnUppercase(n) {
|
|
281
275
|
var fraction = ['角', '分'];
|
|
282
276
|
var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
283
|
-
var unit = [
|
|
277
|
+
var unit = [
|
|
278
|
+
['元', '万', '亿'],
|
|
279
|
+
['', '拾', '佰', '仟'],
|
|
280
|
+
];
|
|
284
281
|
var head = n < 0 ? '欠' : '';
|
|
285
282
|
n = Math.abs(n);
|
|
286
283
|
var s = '';
|
|
@@ -310,7 +307,7 @@ const formatDateNil = withDefaultNil(formatDate);
|
|
|
310
307
|
const unit = {
|
|
311
308
|
d: '天',
|
|
312
309
|
m: '个月',
|
|
313
|
-
y: '年'
|
|
310
|
+
y: '年',
|
|
314
311
|
};
|
|
315
312
|
function formatDuration(period) {
|
|
316
313
|
if (!period)
|
|
@@ -516,4 +513,45 @@ class WS {
|
|
|
516
513
|
}
|
|
517
514
|
}
|
|
518
515
|
|
|
519
|
-
|
|
516
|
+
function disableBrowserZoom() {
|
|
517
|
+
// @ts-ignore
|
|
518
|
+
document.addEventListener('keydown', function (event) {
|
|
519
|
+
if ((event.ctrlKey === true || event.metaKey === true) &&
|
|
520
|
+
(event.which === 61 ||
|
|
521
|
+
event.which === 107 ||
|
|
522
|
+
event.which === 173 ||
|
|
523
|
+
event.which === 109 ||
|
|
524
|
+
event.which === 187 ||
|
|
525
|
+
event.which === 189)) {
|
|
526
|
+
event.preventDefault();
|
|
527
|
+
}
|
|
528
|
+
}, false);
|
|
529
|
+
// @ts-ignore
|
|
530
|
+
window.addEventListener('mousewheel', function (event) {
|
|
531
|
+
// @ts-ignore
|
|
532
|
+
if (event.ctrlKey === true || event.metaKey) {
|
|
533
|
+
event.preventDefault();
|
|
534
|
+
}
|
|
535
|
+
}, {
|
|
536
|
+
passive: false,
|
|
537
|
+
});
|
|
538
|
+
window.addEventListener('DOMMouseScroll', function (event) {
|
|
539
|
+
// @ts-ignore
|
|
540
|
+
if (event.ctrlKey === true || event.metaKey) {
|
|
541
|
+
event.preventDefault();
|
|
542
|
+
}
|
|
543
|
+
}, {
|
|
544
|
+
passive: false,
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function copyToClipboard(txt) {
|
|
549
|
+
var textarea = document.createElement('textarea');
|
|
550
|
+
textarea.value = txt;
|
|
551
|
+
document.body.appendChild(textarea);
|
|
552
|
+
textarea.select();
|
|
553
|
+
document.execCommand('copy');
|
|
554
|
+
document.body.removeChild(textarea);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
export { DATE_FORMAT, FORMAT_DATE, FORMAT_TIME, NIL_STRING, WS, accAdd, accDiv, accMul, accSub, copyToClipboard, cutTimeFn, digitCnUppercase, disableBrowserZoom, download, fileReaderToBase64, format10k, format10kNil, formatCash, formatCash2, formatCashInt, formatCashIntNil, formatCashNil, 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, 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.14",
|
|
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": "fbb1ea34dd1cea2f1261f1606b57f6ba63c6a0af"
|
|
39
39
|
}
|