cc1-js 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1478 @@
1
+ interface ArrayUtilInter {
2
+ /**
3
+ * 数组元素交换位置
4
+ * @param {array} arr 数组
5
+ * @param {number} index1 添加项目的位置
6
+ * @param {number} index2 删除项目的位置
7
+ * index1和index2分别是两个数组的索引值,即是两个要交换元素位置的索引值,如1,5就是数组中下标为1和5的两个元素交换位置
8
+ */
9
+ swapArray: (arr: Array<any>, index1: number, index2: number) => any[];
10
+ /**
11
+ * 上移
12
+ * @param arr
13
+ * @param index
14
+ */
15
+ zIndexUp: (arr: Array<any>, index: number) => void;
16
+ /**
17
+ * 下移
18
+ * @param arr
19
+ * @param index
20
+ */
21
+ zIndexDown: (arr: Array<any>, index: number) => void;
22
+ /**
23
+ * 置顶
24
+ * @param arr
25
+ * @param index
26
+ */
27
+ zIndexTop: (arr: Array<any>, index: number) => void;
28
+ /**
29
+ * 置底
30
+ * @param arr
31
+ * @param index
32
+ */
33
+ zIndexBottom: (arr: Array<any>, index: number) => void;
34
+ /**
35
+ * 获取差集
36
+ * @param arr1
37
+ * @param arr2
38
+ * @returns
39
+ */
40
+ diff: (arr1: Array<any>, arr2: Array<any>) => any[];
41
+ }
42
+ declare var ArrayUtil: ArrayUtilInter;
43
+ interface Base64UtilInter {
44
+ /**
45
+ * 加密字符串为base64
46
+ * @param input
47
+ * @returns
48
+ */
49
+ encode: (input: any) => string;
50
+ /**
51
+ * 解密base64为字符串
52
+ * @param input
53
+ * @returns
54
+ */
55
+ decode: (input: any) => string;
56
+ /**
57
+ * 检查一个字符串是否为Base64编码
58
+ * @param str 待检测的字符串
59
+ * @returns 是否为Base64编码
60
+ */
61
+ doCheck(str: string): boolean;
62
+ }
63
+ declare var Base64Util: Base64UtilInter;
64
+ interface ByteUtilInter {
65
+ /**
66
+ * 将byte数组转为字符串
67
+ * @param str
68
+ * @returns
69
+ */
70
+ byteToString: (arr: any) => string;
71
+ /**
72
+ * 将字符串转为byte数组
73
+ * @param str
74
+ * @returns
75
+ */
76
+ stringToByte: (str: any) => any[];
77
+ /**
78
+ * 将Uint8Array转为字符串
79
+ * @param fileData
80
+ * @returns
81
+ */
82
+ uint8ArrayToString(fileData: any): string;
83
+ /**
84
+ * 将字符串转为Uint8Array
85
+ * @param str
86
+ * @returns
87
+ */
88
+ stringToUint8Array(str: any): Uint8Array;
89
+ }
90
+ declare var ByteUtil: ByteUtilInter;
91
+ /**
92
+ * 全局事件管理
93
+ */
94
+ interface CEventInter {
95
+ eventbean: CEventBeanInter;
96
+ /**
97
+ * 注册-On-cycle
98
+ * @param key 注册名称
99
+ * @param callback 执行回调
100
+ * @param vm 附带信息
101
+ * @returns 返回唯一注册id
102
+ */
103
+ on(key: any, callback: (data: any) => any, vm?: any): string;
104
+ /**
105
+ * 只注册一次-Once-cycle
106
+ * @param key 注册名称
107
+ * @param callback 执行回调
108
+ * @param vm 附带信息
109
+ * @returns 返回唯一注册id
110
+ */
111
+ once(key: any, callback: (data: any) => any, vm?: any): string;
112
+ /**
113
+ * 调用
114
+ * @param key 注册名称
115
+ * @param data 回调函数传入参数
116
+ * @param emitAll 通知所有事件对象(CEvent和所有new CEventBean()),默认为true
117
+ */
118
+ emit(key: any, data?: any, emitAll?: boolean): void;
119
+ /**
120
+ * 销毁-Offload
121
+ * @mode 模式1:多id或者key名称传入-off('onid1')、off('onid1','getData'...)
122
+ * @mode 模式2:on方法传入的key和方法-off('getData',fun)
123
+ * @param uids-传入的是id或者key加方法清理的是key的单个注册,传入的是key清理key所有注册
124
+ */
125
+ off(...uids: any): void;
126
+ /**
127
+ * 清空
128
+ */
129
+ clear(): void;
130
+ }
131
+ declare var CEvent: CEventInter;
132
+ /**
133
+ * 事件管理对象
134
+ */
135
+ interface CEventBeanInter {
136
+ /**
137
+ * 提供默认的挂载验证事件,默认为通过,需要手动销毁事件
138
+ * 返回为true或者1为运行,false或者0为停止并销毁事件对象,-1或者任意值为暂停执行函数,但不会销毁事件对象
139
+ * @returns
140
+ * @example
141
+ * //在vue3中使用
142
+ import { getCurrentInstance } from 'vue'
143
+ const findTopTag = (el: any, tag: string = 'html'): any => {
144
+ if (!el?.parentElement) return null
145
+ if (el.parentElement.tagName.toLocaleLowerCase() === tag) return el.parentElement
146
+ else return findTopTag(el.parentElement, tag)
147
+ }
148
+ CEvent.eventbean.vm = function () {
149
+ const _vm = getCurrentInstance()
150
+ return () => findTopTag(_vm?.vnode.el?.parentElement)
151
+ }
152
+ */
153
+ vm: () => () => boolean;
154
+ eventMap: Map<any, any>;
155
+ id: string;
156
+ tag: string;
157
+ /**
158
+ * 注册
159
+ * @param key 注册名称
160
+ * @param callback 执行回调
161
+ * @param vm 挂载信息
162
+ * @returns 返回唯一注册id
163
+ */
164
+ on: (key: any, callback: (data: any) => any, vm?: any) => string;
165
+ /**
166
+ * 只注册一次
167
+ * @param key 注册名称
168
+ * @param callback 执行回调
169
+ * @param vm 挂载信息
170
+ * @returns 返回唯一注册id
171
+ */
172
+ once: (key: any, callback: (data: any) => any, vm?: any) => string;
173
+ /**
174
+ * 调用
175
+ * @param key 注册名称
176
+ * @param data 回调函数传入参数
177
+ * @param emitAll 通知所有事件对象(CEvent和所有new CEventBean()),默认为true
178
+ */
179
+ emit: (key: any, data?: any, emitAll?: boolean) => void;
180
+ /**
181
+ * 销毁
182
+ * @mode 模式1:多id或者key名称传入-off('onid1')、off('onid1','getData'...)
183
+ * @mode 模式2:on方法传入的key和方法-off('getData',fun)
184
+ * @param uids-传入的是id或者key加方法清理的是key的单个注册,传入的是key清理key所有注册
185
+ */
186
+ off: (...uids: any) => void;
187
+ clear: () => void;
188
+ }
189
+ interface CEventBeanObj { new ():CEventBeanInter}
190
+ declare var CEventBean: CEventBeanObj;
191
+ /**
192
+ * 事件管理中心,不应该调用此对象任何方法
193
+ */
194
+ interface CEventCoreInter {
195
+ id: number;
196
+ getId: () => string;
197
+ map: {
198
+ [key: string]: any;
199
+ };
200
+ /**
201
+ * 添加一个_CEventBean对象
202
+ * @param _CEventBean
203
+ */
204
+ add: (_CEventBean: any) => void;
205
+ /**
206
+ * 移除一个_CEventBean对象
207
+ * @param _CEventBean
208
+ */
209
+ remove: (...ids: any[]) => void;
210
+ }
211
+ declare var CEventCore: CEventCoreInter;
212
+ /**
213
+ * 缓存工具扩展,默认使用localStorage
214
+ * @param 说明 -将数据存入localStorage 如需修改存入对象,结构需要符合window.localStorage存在setItem、getItem、removeItem、clear方法
215
+ */
216
+ interface CookieInter {
217
+ /**
218
+ * 默认使用localStorage
219
+ * 如需修改,结构需要符合window.localStorage存在setItem、getItem、removeItem、clear方法
220
+ */
221
+ localStorage: Storage;
222
+ /**
223
+ * 默认添加有效时间 3600天
224
+ */
225
+ expire: number;
226
+ /**
227
+ * 默认添加有效单位 秒
228
+ */
229
+ expireUnit: number;
230
+ /**
231
+ * 设置
232
+ */
233
+ set(key: string, value: any, config?: {
234
+ /**
235
+ * 有效时间-秒
236
+ */
237
+ expire?: number;
238
+ }): void;
239
+ /**
240
+ * 获取指定值
241
+ */
242
+ get(key: string): any;
243
+ /**
244
+ * 移除指定值
245
+ */
246
+ remove(key: string): void;
247
+ /**
248
+ * 清空所有key和值
249
+ */
250
+ clear(): void;
251
+ }
252
+ declare var Cookie: CookieInter;
253
+ /**
254
+ * Cookie工具
255
+ */
256
+ interface CookieCInter {
257
+ /**
258
+ * 默认添加有效时间 3600天
259
+ */
260
+ expire: number;
261
+ /**
262
+ * 默认添加有效单位 秒
263
+ */
264
+ expireUnit: number;
265
+ /**
266
+ * 设置cookie
267
+ * @param name
268
+ * @param value
269
+ * @param config
270
+ */
271
+ set(name: string, value: any, config?: {
272
+ /**
273
+ * path-/
274
+ */
275
+ path?: string;
276
+ /**
277
+ * 有效时间-秒
278
+ */
279
+ expire?: number;
280
+ /**
281
+ * 域名
282
+ */
283
+ domain?: string;
284
+ /**
285
+ * 活动有效
286
+ */
287
+ session?: boolean;
288
+ }): void;
289
+ /**
290
+ * 获取cookie
291
+ * @param name
292
+ * @returns
293
+ */
294
+ get(name: string): any;
295
+ /**
296
+ * 删除cookie
297
+ * @param name
298
+ * @param domain
299
+ */
300
+ remove(name: string, domain?: string): void;
301
+ /**
302
+ * 清空所有key和值
303
+ */
304
+ clear(paths?: string[], domain?: string): void;
305
+ }
306
+ declare var CookieC: CookieCInter;
307
+ /**
308
+ * 缓存处理
309
+ * @param 说明 -对localStorage(CookieL)和cookie(Cookie)的数据处理
310
+ */
311
+ interface CookieValInter {
312
+ /**
313
+ * 存储
314
+ * @param value
315
+ * @returns
316
+ */
317
+ setValue: (value: any) => any;
318
+ /**
319
+ * 获取
320
+ * @param value
321
+ * @returns
322
+ */
323
+ getValue: (value: any) => any;
324
+ }
325
+ declare var CookieVal: CookieValInter;
326
+ interface DomUtilInter {
327
+ /**
328
+ * listener执行内容,传入移除监听事件的函数
329
+ */
330
+ listenerVm: (remove: () => void) => void;
331
+ /**
332
+ * 对节点添加监听事件和回调
333
+ * @param dom
334
+ * @param type
335
+ * @param listener
336
+ * @returns
337
+ */
338
+ listener: <K extends keyof GlobalEventHandlersEventMap>(dom: Node | Window, type: K, listener: (this: Node, ev: GlobalEventHandlersEventMap[K]) => any) => {
339
+ remove: () => void;
340
+ };
341
+ /**
342
+ * 获取管理点击或者触摸事件管理对象
343
+ * @returns
344
+ */
345
+ useTouch: () => {
346
+ getXY: (event: TouchEvent | Touch | Event | MouseEvent) => {
347
+ x: number;
348
+ y: number;
349
+ };
350
+ move: (event: TouchEvent | Touch | Event | MouseEvent) => void;
351
+ start: (event: TouchEvent | Touch | Event | MouseEvent) => void;
352
+ reset: () => void;
353
+ isVertical: () => boolean;
354
+ isHorizontal: () => boolean;
355
+ conf: {
356
+ /**
357
+ * start触发x坐标
358
+ */
359
+ startX: number;
360
+ /**
361
+ * start触发y坐标
362
+ */
363
+ startY: number;
364
+ /**
365
+ * 和起点startX的X偏移
366
+ */
367
+ deltaX: number;
368
+ /**
369
+ * 和起点startY的X偏移
370
+ */
371
+ deltaY: number;
372
+ /**
373
+ * 绝对值x偏移
374
+ */
375
+ offsetX: number;
376
+ /**
377
+ * 绝对值y偏移
378
+ */
379
+ offsetY: number;
380
+ /**
381
+ * 水平或者垂直
382
+ */
383
+ direction: string;
384
+ /**
385
+ * 触发时间
386
+ */
387
+ startTime: number;
388
+ /**
389
+ * 结束总耗时
390
+ */
391
+ endTime: number;
392
+ /**
393
+ * 当前所处x坐标
394
+ */
395
+ moveX: number;
396
+ /**
397
+ * 当前所处x坐标与上一次坐标偏移
398
+ */
399
+ moveOffsetX: number;
400
+ /**
401
+ * 当前所处y坐标
402
+ */
403
+ moveY: number;
404
+ /**
405
+ * 当前所处y坐标与上一次坐标偏移
406
+ */
407
+ moveOffsetY: number;
408
+ };
409
+ };
410
+ /**
411
+ *
412
+ * @param div 目标,需要是absolute
413
+ * @param fun 移动完毕之后的回调
414
+ */
415
+ moveDiv(div: HTMLDivElement, onmouseup?: (data: {
416
+ left: number;
417
+ top: number;
418
+ }) => any): void;
419
+ /**
420
+ * 获取滚动条宽度
421
+ */
422
+ getScrollbarWidth(): number;
423
+ /**
424
+ * 获取元素中的文本是否超出了父级
425
+ * @param element -dom对象
426
+ * @returns
427
+ * @example
428
+ *
429
+ 建议使用应用css以下内容的标签:
430
+ overflow: hidden;
431
+ overflow-wrap: break-word;
432
+ text-overflow: ellipsis;
433
+ white-space: nowrap;(必须,否则返回false)
434
+ width: 330px;
435
+ */
436
+ isTextOverflow: (element: any) => boolean;
437
+ }
438
+ declare var DomUtil: DomUtilInter;
439
+ /**
440
+ * @type protype
441
+ */
442
+ interface Array<T> {
443
+ /**
444
+ * 移除数组中的指定内容,用于不是对象素组
445
+ * @param str 删除内容
446
+ * @example
447
+ * let arr = new Array<string>()
448
+ * arr.push("1")
449
+ * arr.push("2")
450
+ * arr.remove("1")
451
+ */
452
+ remove(item: (val: T) => any): void;
453
+ /**
454
+ * 去重
455
+ * @param predicate 比较说明
456
+ * @returns
457
+ * @example
458
+ * const arr1 = arr.toSet()
459
+ * const arr2 = arr.toSet((next,pre)=>next.id===pre.id)
460
+ */
461
+ toSet(predicate?: (next: T, pre: T) => any): any[];
462
+ /**
463
+ * 随机排序
464
+ */
465
+ randSort(): void;
466
+ /**
467
+ * 累加
468
+ * @param field -对象字段名称
469
+ * @example
470
+ * const num = arr.sum()
471
+ * const num = arr.sum('num')
472
+ */
473
+ sum(field?: string): any;
474
+ }
475
+ /**
476
+ * @type protype
477
+ */
478
+ interface DOMRect {
479
+ /**
480
+ * x,y坐标是否处于矩形内
481
+ * @param x
482
+ * @param y
483
+ */
484
+ contains(x: number, y: number): boolean;
485
+ /**
486
+ * x坐标是否处于矩形内
487
+ * @param x
488
+ */
489
+ containX(x: number): boolean;
490
+ /**
491
+ * y坐标是否处于矩形内
492
+ * @param y
493
+ */
494
+ containY(y: number): boolean;
495
+ }
496
+ /**
497
+ * @type protype
498
+ */
499
+ interface Date {
500
+ /**
501
+ * 格式化时间
502
+ * @param fmt 时间字符串格式
503
+ * @param formatFail 格式化失败时返回的字符串
504
+ * @example
505
+ * new Date().Format('yyyy-MM-dd hh:mm:ss') //2021-12-17 11:30:00
506
+ */
507
+ Format(fmt?: any, formatFail?: string): string;
508
+ /**
509
+ * 格式化时间差
510
+ * @param fmt 时间字符串格式
511
+ * @example
512
+ * new Date().Format('yyyy-MM-dd hh:mm:ss') //2021-12-17 11:30:00
513
+ */
514
+ FormatDiff(fmt?: any): string;
515
+ /**
516
+ * 获取处理时差后的时间戳
517
+ */
518
+ getTimeDiff(): any;
519
+ }
520
+ /**
521
+ * @type protype
522
+ */
523
+ interface Function {
524
+ /**
525
+ * 获取参数列表
526
+ */
527
+ args(): string[];
528
+ }
529
+ /**
530
+ * @type protype
531
+ */
532
+ interface Map<K, V> {
533
+ /**
534
+ * 将map输出为json
535
+ */
536
+ toJson(): string;
537
+ }
538
+ /**
539
+ * 配置和控制管理
540
+ */
541
+ interface ESUtilInter {
542
+ /**
543
+ * 初始化函数,自动调用,调用此方法无任何效果
544
+ * @returns
545
+ */
546
+ init(): void;
547
+ /**
548
+ * 语言对象
549
+ */
550
+ langObj: {
551
+ HttpUtil: {
552
+ '0': string;
553
+ '404': string;
554
+ '405': string;
555
+ '500': string;
556
+ '504': string;
557
+ OtherException: string;
558
+ };
559
+ TimeUtil: {
560
+ Today: string;
561
+ Yesterday: string;
562
+ ThisWeek: string;
563
+ LastWeek: string;
564
+ ThisMonth: string;
565
+ JustNow: string;
566
+ };
567
+ };
568
+ /**
569
+ * 设置当前显示语言内容
570
+ * @param lang
571
+ */
572
+ setLang(lang: langObj): void;
573
+ }
574
+ type langObj = (typeof ESUtil)['langObj'];
575
+
576
+ declare var ESUtil: ESUtilInter;
577
+ interface r_DateInter {
578
+ init(): void;
579
+ }
580
+ declare var r_Date: r_DateInter;
581
+ /**
582
+ * 简单加解密工具
583
+ */
584
+ interface EnUtilInter {
585
+ /**
586
+ * 加密
587
+ * @param str
588
+ * @returns
589
+ */
590
+ encode: (str: string) => string;
591
+ /**
592
+ * 解密
593
+ * @param str
594
+ * @returns
595
+ */
596
+ decode: (str: string) => string;
597
+ }
598
+ declare var EnUtil: EnUtilInter;
599
+ /**
600
+ * 文件请求工具
601
+ */
602
+ interface FileUtilInter {
603
+ /**
604
+ * 使用的请求对象,可修改
605
+ */
606
+ httpBean: HttpInter;
607
+ /**
608
+ * 获取读取文件函数
609
+ * @param param -baseUrl-获取文件根地址,默认为/,outtime-超时时间,默认为30000
610
+ * @returns
611
+ */
612
+ getFileFun: (param?: TFileConfig) => (url: string) => Promise<any>;
613
+ /**
614
+ * 获取文件内容
615
+ * @param url
616
+ * @returns
617
+ */
618
+ getFile: (url: string, param?: TFileConfig) => Promise<any>;
619
+ }
620
+ type TFileConfig = Partial<FileConfigBean>;
621
+ /**
622
+ * 配置内容
623
+ */
624
+ type FileConfigBean = {
625
+ /**
626
+ * 根地址
627
+ */
628
+ base: string;
629
+ /**
630
+ * 超时时间
631
+ */
632
+ outtime: number;
633
+ /**
634
+ * 消息类型
635
+ */
636
+ responseType: XMLHttpRequestResponseType;
637
+ };
638
+
639
+ declare var FileUtil: FileUtilInter;
640
+ /**
641
+ * 对函数进行防抖、节流、加锁
642
+ */
643
+ interface FunUtilInter {
644
+ /**
645
+ * 定时器
646
+ */
647
+ timer: typeof Timer;
648
+ /**
649
+ * 防抖-在规定时间内只执行最后一次,默认500ms
650
+ */
651
+ debounce: (fn: Function, delay?: number) => void;
652
+ /**
653
+ * 节流-在规定时间内只执行第一次,默认500ms
654
+ */
655
+ throttle: (fn: Function, delay?: number, tip?: () => void) => void;
656
+ /**
657
+ * 触发节流限制提示,需要提示直接覆盖此方法
658
+ */
659
+ throttleTip: () => void;
660
+ /**
661
+ * 资源管理
662
+ */
663
+ /**
664
+ * 执行一个函数并返回结果,在未返回结果再次执行会等待第一个执行完毕,后续的执行获取到同一个结果
665
+ * @example
666
+ * //使用接口获取数据,连续调用三次,实际只会请求一次
667
+ * const getData = ()=>{
668
+ * const data = FunUtil.lock(async ()=>{
669
+ * return await http.get('/test')
670
+ * })
671
+ * return data
672
+ * }
673
+ * getData()
674
+ * getData()
675
+ * getData()
676
+ *
677
+ */
678
+ lock: (fn: Function) => Promise<any>;
679
+ }
680
+ declare var FunUtil: FunUtilInter;
681
+ interface H5UtilInter {
682
+ /**
683
+ * 设计尺寸宽度/也可以在head上添加属性design-width进行设置,默认750
684
+ */
685
+ remWidth: number;
686
+ /**
687
+ * 最大显示宽度(控制宽屏下的显示内容),可传入方法动态控制宽度限制:()=>{return 750},默认500
688
+ */
689
+ maxWidth: number | Function;
690
+ /**
691
+ * 设计字体大小-默认1
692
+ */
693
+ remFontSize: number;
694
+ /**
695
+ * rem手机适配
696
+ * @example
697
+ * //使用前需要在<head design-width="750">中修改设计尺寸或者使用H5Util.remWidth = 750修改,默认值为750
698
+ * //remFontSize默认为1或者使用H5Util.remFontSize = 100
699
+ * //需要使用 <body><div class="design-box"></div></body> 起到限制作用或自行写入样式
700
+ * //当使用默认开发,750rem等于750px
701
+ * @returns
702
+ */
703
+ rem(): void;
704
+ /** 刷新页面布局 */
705
+ refresh(): void;
706
+ /** 获取当前处于屏幕中的最大宽度 */
707
+ getDeviceWidth(): number;
708
+ /** rem转px */
709
+ rem2px(rem: number): number;
710
+ /** px转rem */
711
+ px2rem(px: number): number;
712
+ /**
713
+ * 最大宽高的比例限制 默认是 高915 / 宽412的值2.221
714
+ */
715
+ maxRatio: number;
716
+ /**
717
+ * 设计尺寸高度-默认1334
718
+ */
719
+ remHeight: number;
720
+ /** 获取当前处于屏幕中的最大宽高 */
721
+ getMaxBox(): {
722
+ height: number;
723
+ width: number;
724
+ };
725
+ /** 获取最大高度 */
726
+ getMaxHeight(): number;
727
+ /** 获取最大宽度 */
728
+ getMaxWidth(): number;
729
+ }
730
+ declare var H5Util: H5UtilInter;
731
+ /**
732
+ * HttpUtil覆盖原生方法工具
733
+ */
734
+ interface HttpUtilInter {
735
+ /**
736
+ * 初始化函数,自动调用,调用此方法无任何效果
737
+ * @returns
738
+ */
739
+ init(): void;
740
+ /**
741
+ * 对网址进行ping值拿到延迟
742
+ * @param url
743
+ * @param timeout
744
+ * @returns
745
+ */
746
+ ping(url: string, timeout?: number): Promise<unknown>;
747
+ }
748
+ declare var HttpUtil: HttpUtilInter;
749
+ /**
750
+ * iframe标签简单交互工具
751
+ */
752
+ interface IFrameUtilInter {
753
+ /**
754
+ * 发送数据
755
+ * @param data
756
+ * @param childrenId -传入id时向iframe子节点传输数据,反之向父级传输数据
757
+ */
758
+ sendMessage: (data: any, childrenId?: string) => void;
759
+ /**
760
+ * 注册接收数据
761
+ * @param fun
762
+ */
763
+ onMassage: (fun: (data: any) => void) => void;
764
+ /**
765
+ * 销毁接收数据
766
+ * @param fun
767
+ */
768
+ offMassage: (fun: (data: any) => void) => void;
769
+ }
770
+ declare var IFrameUtil: IFrameUtilInter;
771
+ /**
772
+ * 图片工具类
773
+ */
774
+ interface ImgUtilInter {
775
+ /**
776
+ * 全局处理图片src,将图片src替换为回调函数返回的值
777
+ * @param callback 回调函数
778
+ */
779
+ handleSrc(callback: (url: string) => string): void;
780
+ /**
781
+ * 加载图片资源
782
+ * @param param
783
+ * @returns
784
+ */
785
+ loadImage: (param: {
786
+ /**
787
+ * 图片地址
788
+ */
789
+ url: string;
790
+ /**
791
+ * 超时时间-默认没有超时时间
792
+ */
793
+ timeout?: number | undefined;
794
+ /**
795
+ * 图片扩展名-默认['.png', '.jpg', '.jpeg', '.webp', '.gif', '.svg']
796
+ */
797
+ extensions?: string[] | undefined;
798
+ /**
799
+ * 是否返回base64-默认false
800
+ */
801
+ base64?: boolean | undefined;
802
+ /**
803
+ * base64质量-默认1
804
+ */
805
+ base64Quality?: number | undefined;
806
+ /**
807
+ * 是否返回arrayBuffer-默认false
808
+ */
809
+ arrayBuffer?: boolean | undefined;
810
+ /**
811
+ * 加载完成回调
812
+ */
813
+ load?: ((img: HTMLImageElement, res: {
814
+ dataBase64: string;
815
+ dataArray: ImageData;
816
+ }) => void) | undefined;
817
+ /**
818
+ * 加载失败回调
819
+ */
820
+ error?: (() => void) | undefined;
821
+ }) => {
822
+ /**
823
+ * 图片对象
824
+ */
825
+ img: HTMLImageElement;
826
+ /**
827
+ * 取消加载-需要手动回调
828
+ */
829
+ abort: () => void;
830
+ } | undefined;
831
+ }
832
+ declare var ImgUtil: ImgUtilInter;
833
+ interface JSONUtilInter {
834
+ /**
835
+ * 复制json对象
836
+ */
837
+ cp<T>(obj: T): T;
838
+ /**
839
+ * 深度拷贝-对象、数组、时间、正则
840
+ * @param objT
841
+ * @param hash
842
+ * @returns
843
+ */
844
+ deepClone<T>(objT: T, hash?: WeakMap<object, any>): T;
845
+ /**
846
+ * 将json对象的所有能转对象的json字符串转为对象
847
+ * @param data -对象或者数组
848
+ */
849
+ strToObject: (data: {
850
+ [key: string]: any;
851
+ }) => void;
852
+ }
853
+ declare var JSONUtil: JSONUtilInter;
854
+ interface KeyUtilInter {
855
+ /**
856
+ * 监听组合键
857
+ * @param keys 组合键数组
858
+ * @param callback 触发回调函数
859
+ * @example
860
+ * //Ctrl+Q
861
+ * groupKey(['Ctrl','Q'],()=>{
862
+ * console.log('成功')
863
+ * })
864
+ * @returns
865
+ */
866
+ groupKey: (keys: string[], callback: Function) => () => void;
867
+ }
868
+ declare var KeyUtil: KeyUtilInter;
869
+ /**
870
+ * @desc 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。
871
+ *
872
+ * 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
873
+ */
874
+ type NumberType = number | string;
875
+ /**
876
+ * Correct the given number to specifying significant digits.
877
+ *
878
+ * @param num The input number
879
+ * @param precision An integer specifying the number of significant digits
880
+ *
881
+ * @example strip(0.09999999999999998) === 0.1 // true
882
+ */
883
+ declare function strip(num: NumberType, precision?: number): number;
884
+ /**
885
+ * Return digits length of a number.
886
+ *
887
+ * @param num The input number
888
+ */
889
+ declare function digitLength(num: NumberType): number;
890
+ /**
891
+ * Convert the given number to integer, support scientific notation.
892
+ * The number will be scale up if it is decimal.
893
+ *
894
+ * @param num The input number
895
+ */
896
+ declare function float2Fixed(num: NumberType): number;
897
+ /**
898
+ * Accurate rounding method.
899
+ *
900
+ * @param num The number to round
901
+ * @param decimal An integer specifying the decimal digits
902
+ */
903
+ declare function round(num: NumberType, decimal: number): number;
904
+ interface MathUtilInter {
905
+ /**
906
+ * 将所有值转换为float,转换不了的返回0
907
+ */
908
+ getNumber(val: any, fixed?: number): number;
909
+ /**
910
+ * 获取两个整数之间的随机数,可传入随机小数点后的随机值
911
+ */
912
+ getRandomInt(min: number, max: number, fixedMin?: number, fixedMax?: number): number;
913
+ /**
914
+ * 将给定的数字更正为指定有效数字。
915
+ * @param num — 数字
916
+ * @param precision — 指定有效位数的整数
917
+ * @example
918
+ * strip(0.09999999999999998) === 0.1 // true
919
+ */
920
+ strip: typeof strip;
921
+ /**
922
+ * 加法
923
+ */
924
+ plus: (...nums: NumberType[]) => number;
925
+ /**
926
+ * 减法
927
+ */
928
+ minus: (...nums: NumberType[]) => number;
929
+ /**
930
+ * 乘法
931
+ */
932
+ times: (...nums: NumberType[]) => number;
933
+ /**
934
+ * 除法
935
+ */
936
+ divide: (...nums: NumberType[]) => number;
937
+ /**
938
+ * 精确的四舍五入
939
+ */
940
+ round: typeof round;
941
+ /**
942
+ * 返回数字的长度
943
+ */
944
+ digitLength: typeof digitLength;
945
+ /**
946
+ * 将给定的数字转换为整数,支持科学记数法。如果是小数,这个数字将按比例增大。
947
+ */
948
+ float2Fixed: typeof float2Fixed;
949
+ }
950
+
951
+ declare var MathUtil: MathUtilInter;
952
+ interface ObjectUtilInter {
953
+ objectToString: () => string;
954
+ toTypeString: (value: unknown) => string;
955
+ isArray: (arg: any) => arg is any[];
956
+ isMap: (val: unknown) => val is Map<any, any>;
957
+ isSet: (val: unknown) => val is Set<any>;
958
+ isDate: (val: unknown) => val is Date;
959
+ isFunction: (val: unknown) => val is Function;
960
+ isString: (val: unknown) => val is string;
961
+ isSymbol: (val: unknown) => val is symbol;
962
+ isObject: (val: unknown) => val is Record<any, any>;
963
+ isPromise: <T = any>(val: unknown) => val is Promise<T>;
964
+ /**
965
+ * 遍历对象中的每一个key和value
966
+ * @param obj Object、Array
967
+ */
968
+ getObject: (obj: any, fun: (key: string, value: any, obj: any) => any) => boolean;
969
+ /**
970
+ * 遍历对象中的每一个对象,children为对象的子对象字段
971
+ * @param obj Object、Array
972
+ * @param fun 回调函数
973
+ * @param children 对象的子对象列表字段,默认['children']
974
+ */
975
+ getObjectByChildren: (obj: any, fun: (obj: any) => any, children?: string[]) => void;
976
+ /**
977
+ * 深度合并对象,老字段覆盖值或保留,新字段新增,返回合并后的对象,对原对象无影响
978
+ * @param obj1
979
+ * @param obj2
980
+ * @returns
981
+ *
982
+ * @example
983
+ * let a = {a:1,b:{n:2,c:2},c:{r:1,n:1}}
984
+ * let newa = {a:2,b:{c:3}}
985
+ * const c = deepMerge(newa,a)
986
+ */
987
+ deepMerge: (obj1: any, obj2: any) => any;
988
+ /**
989
+ * 深度合并对象,对传入的source进行覆盖式赋值,无返回值
990
+ * @param source 被覆盖对象
991
+ * @param assignObj 覆盖对象
992
+ * @example
993
+ * const source = { a: 1, b: { c: 2 } }
994
+ * const assignObj = { b: { c: 3 } }
995
+ * deepAssign(source, assignObj)
996
+ * console.log(source) // { a: 1, b: { c: 3 } }
997
+ */
998
+ deepAssign(source: any, assignObj: any): any;
999
+ /**
1000
+ * 使用路径获取对象的值
1001
+ * @param obj
1002
+ * @param path
1003
+ * @returns
1004
+ * @example
1005
+ * const a = {b:{c:6}}
1006
+ * console.log(getPathValue(a,'b.c'))//输出6
1007
+ */
1008
+ getPathValue: (obj: any, path: string, defaultVal?: any) => string;
1009
+ /**
1010
+ * 使用路径设置对象的值
1011
+ * @param obj
1012
+ * @param path
1013
+ * @param val
1014
+ * @param index
1015
+ */
1016
+ setPathVal(obj: any, path: any, val: any, index?: number): void;
1017
+ }
1018
+ declare var ObjectUtil: ObjectUtilInter;
1019
+ interface ScriptUtilInter {
1020
+ /**
1021
+ * 加载js文件到页面
1022
+ * @param url
1023
+ * @returns
1024
+ */
1025
+ scriptLoad(url: any): Promise<boolean>;
1026
+ }
1027
+ declare var ScriptUtil: ScriptUtilInter;
1028
+ interface StrUtilInter {
1029
+ /**
1030
+ * 获取uuid
1031
+ * @returns
1032
+ */
1033
+ uuid(): string;
1034
+ /**
1035
+ * 获取唯一递增id
1036
+ */
1037
+ getId: () => string;
1038
+ /**
1039
+ * 判断内容是否为空,null,undefined,NaN,空数组,空字符串返回true
1040
+ */
1041
+ isNull(str: any): boolean;
1042
+ /**
1043
+ * 清除所有换行、空格、回车字符
1044
+ */
1045
+ clearBlank(str: string): string;
1046
+ /**
1047
+ * 验证数字
1048
+ */
1049
+ isNumber(obj: any): boolean;
1050
+ /**
1051
+ * 获取url地址中的参数对象信息
1052
+ * @param url 如/list?pageSize=1&pageNum=2
1053
+ * @param return 如{pageSize:1,pageNum:2}不符合返回{}
1054
+ */
1055
+ getParam(url: any): any;
1056
+ /**
1057
+ * 复制字符串
1058
+ */
1059
+ copyText(text: string): Promise<boolean>;
1060
+ }
1061
+ declare var StrUtil: StrUtilInter;
1062
+ interface TimeUtilInter {
1063
+ /**
1064
+ * 获取倒计时
1065
+ * @param time 时间间隔(比如60000)
1066
+ * @returns
1067
+ */
1068
+ countdown: (time: number) => (string | number)[];
1069
+ /**
1070
+ * 获取某天的开始和结束时间-默认为今天
1071
+ * @param offset - 默认0是今天,1是明天,-1是昨天
1072
+ * @param standardDate - 默认是今天,传入指定日期比如7天后,offset为1获取的是8天后
1073
+ * @example
1074
+ * //获取近7天的开始和结束时间
1075
+ * const startTime = TimeUtil.somedayse()[0]
1076
+ * const endTime = TimeUtil.somedayse(6)[1]
1077
+ * @returns
1078
+ */
1079
+ somedayse: (offset?: number, standardDate?: Date) => number[];
1080
+ /**
1081
+ * 获取时间区间选择 今天、昨天、本周、上周、本月
1082
+ * @returns
1083
+ */
1084
+ getDateOptions(): {
1085
+ label: string;
1086
+ value: number[];
1087
+ key: string;
1088
+ }[];
1089
+ /**
1090
+ * 获取时间提示
1091
+ * @param time 时间戳
1092
+ * @returns 时间提示
1093
+ */
1094
+ getTimeTip: (time: number) => any;
1095
+ }
1096
+ declare var TimeUtil: TimeUtilInter;
1097
+ /**
1098
+ * 全局定时器
1099
+ */
1100
+ interface TimerInter {
1101
+ timerBean: TimerBeanInter;
1102
+ /**
1103
+ * 添加一个延时任务
1104
+ * @param fun
1105
+ * @param timeGap -延迟时间
1106
+ */
1107
+ once(fun: () => void, timeGap?: number, vm?: any): any;
1108
+ /**
1109
+ * 清理所有任务(任何地方调用都会清理)
1110
+ */
1111
+ clear: () => void;
1112
+ /**
1113
+ * 等待时间单位 1-毫秒 1000-秒
1114
+ */
1115
+ delayUnit: number;
1116
+ /**
1117
+ * 等待时间
1118
+ * @param millisecond
1119
+ * @returns
1120
+ */
1121
+ delay(millisecond?: number, delayUnit?: number): Promise<void>;
1122
+ /**
1123
+ * 添加一个循环任务
1124
+ * @param fun
1125
+ * @param timeGap -循环时间
1126
+ * @param firstRun -立即执行一次
1127
+ *
1128
+ */
1129
+ on(fun: () => void, timeGap: number, firstRun?: boolean, vm?: any): any;
1130
+ /**
1131
+ * 注销循环-Unload
1132
+ */
1133
+ un: (...ids: any[]) => void;
1134
+ }
1135
+ declare var Timer: TimerInter;
1136
+ /**
1137
+ * 定时器对象
1138
+ */
1139
+ interface TimerBeanInter {
1140
+ map: {
1141
+ [key: string]: TimerInfo;
1142
+ };
1143
+ /**
1144
+ * 提供默认的挂载验证事件,默认为通过,需要手动销毁定时时间对象
1145
+ * 返回为true或者1为运行,false或者0为停止并销毁定时器对象,-1或者任意值为暂停执行函数,但不会销毁定时器对象(只对循环定时器有效)
1146
+ * @returns
1147
+ * @example
1148
+ * //在vue3中使用
1149
+ import { getCurrentInstance } from 'vue'
1150
+ const findTopTag = (el: any, tag: string = 'html'): any => {
1151
+ if (!el?.parentElement) return null
1152
+ if (el.parentElement.tagName.toLocaleLowerCase() === tag) return el.parentElement
1153
+ else return findTopTag(el.parentElement, tag)
1154
+ }
1155
+ const timer = new TimerBean()
1156
+ timer.vm = function () {
1157
+ const _vm = getCurrentInstance()
1158
+ return () => findTopTag(_vm?.vnode.el?.parentElement)
1159
+ }
1160
+ */
1161
+ vm: () => () => boolean;
1162
+ /**
1163
+ * 添加一个延时任务
1164
+ * @param fun
1165
+ * @param timeGap -延迟时间
1166
+ */
1167
+ once: (fun: () => void, timeGap?: number, vm?: any) => any;
1168
+ /**
1169
+ * 清空任务-仅能清理TimerBean中的任务
1170
+ */
1171
+ clear: () => void;
1172
+ /**
1173
+ * 等待时间单位 1-毫秒 1000-秒
1174
+ */
1175
+ delayUnit: number;
1176
+ /**
1177
+ * 等待时间
1178
+ * @param millisecond
1179
+ * @returns
1180
+ */
1181
+ delay: (millisecond?: number, delayUnit?: number) => Promise<void>;
1182
+ /**
1183
+ * 添加一个循环任务
1184
+ * @param fun
1185
+ * @param timeGap -循环时间
1186
+ * @param firstRun -立即执行一次
1187
+ *
1188
+ */
1189
+ on: (fun: () => void, timeGap: number, firstRun?: boolean, vm?: any) => any;
1190
+ /**
1191
+ * 清理循环-仅能清理TimerBean中的任务
1192
+ */
1193
+ un: (...ids: any[]) => void;
1194
+ }
1195
+ interface TimerBeanObj { new ():TimerBeanInter}
1196
+ declare var TimerBean: TimerBeanObj;
1197
+ /**
1198
+ * 定时器核心
1199
+ */
1200
+ interface TimerCoreInter {
1201
+ id: number;
1202
+ getId: () => string;
1203
+ map: {
1204
+ [key: string]: TimerInfo;
1205
+ };
1206
+ add: (fun: () => void, timeGap: number, loop: boolean, vm: any) => TimerInfo;
1207
+ remove: (...ids: any[]) => void;
1208
+ removeAll: () => void;
1209
+ }
1210
+ declare var TimerCore: TimerCoreInter;
1211
+
1212
+
1213
+ interface DateConstructor {
1214
+ /**
1215
+ * 格式化时间
1216
+ * @param date 时间
1217
+ * @param format 时间字符串格式
1218
+ * @param formatFail 格式化失败时返回的字符串
1219
+ * @example
1220
+ * Date.Format(new Date(),'yyyy-MM-dd hh:mm:ss') //2021-12-17 11:30:00
1221
+ */
1222
+ Format(date: Date | string | number, format?: string, formatFail?: string): string;
1223
+
1224
+ /**
1225
+ * 格式化失败时返回的字符串
1226
+ */
1227
+ formatFail: string
1228
+
1229
+ /**
1230
+ * 格式化时差时间
1231
+ * @param date 时间
1232
+ * @param format 时间字符串格式
1233
+ * @example
1234
+ * Date.FormatDiff(new Date(),'yyyy-MM-dd hh:mm:ss') //2021-12-17 11:30:00
1235
+ */
1236
+ FormatDiff(date: Date | string | number, format?: string): string;
1237
+
1238
+ /**
1239
+ * 时差-主要用于处理时差,配合Date的getTimeDiff、FormatDiff使用
1240
+ */
1241
+ timeDiff: number;
1242
+ }
1243
+ /**
1244
+ * 传入参数和数据
1245
+ */
1246
+ type THttpReq = <T = any>(param: string | THttpReqParam, data?: {[key:string]:any}) => Promise<T>
1247
+
1248
+
1249
+ type THttpReqParam = {
1250
+ /**
1251
+ * 请求地址
1252
+ */
1253
+ url: string;
1254
+ /**
1255
+ * 请求类型-仅支持POST和GET
1256
+ */
1257
+ method?: "POST"|"GET"|"post"|"get";
1258
+ /**
1259
+ * 消息类型-默认text
1260
+ */
1261
+ responseType?: XMLHttpRequestResponseType
1262
+ /**
1263
+ * 超时时间-默认30000
1264
+ */
1265
+ timeout?: number;
1266
+ /**
1267
+ * 是否跨域传入cookie-默认false
1268
+ */
1269
+
1270
+ withCredentials?: boolean;
1271
+
1272
+ /**
1273
+ * 过期时间,对接口和参数的结果进行缓存,刷新页面后丢失,单位秒,当为0时,不缓存,为-1时,缓存1天
1274
+ */
1275
+ expire?:number;
1276
+ /**
1277
+ * 请求头
1278
+ */
1279
+ headers?:THttpReqHeaders
1280
+
1281
+ /**
1282
+ * 文件上传进度
1283
+ * @param percent 百分比
1284
+ * @param loaded 已上传大小
1285
+ * @param total 总大小
1286
+ */
1287
+ onProgress?: (percent:number,loaded:number,total:number) => void;
1288
+
1289
+ }
1290
+
1291
+
1292
+ interface callbackConfig<T = any,K = any> {
1293
+ /**
1294
+ * 请求头
1295
+ */
1296
+ headers: THttpReqHeaders;
1297
+ /**
1298
+ * 传入数据
1299
+ */
1300
+ data: T;
1301
+ /**
1302
+ * 传入参数
1303
+ */
1304
+ param: K;
1305
+ /**
1306
+ * 中断当前请求
1307
+ */
1308
+ stop: () => void;
1309
+ }
1310
+
1311
+ type THttpReqHeaders = {
1312
+ [key:string]:any
1313
+ /**
1314
+ * 内容类型
1315
+ */
1316
+ 'Content-Type'?:'application/json'|'multipart/form-data'|'text/plain' | 'application/x-www-form-urlencoded'
1317
+ }
1318
+
1319
+ interface THttpConfig {
1320
+ /**
1321
+ * 根地址,当传入的url以http开头,此地址无效
1322
+ */
1323
+ base: string;
1324
+ /**
1325
+ * 超时时间-默认30000
1326
+ */
1327
+ timeout: number;
1328
+ /**
1329
+ * 消息类型-默认text
1330
+ */
1331
+ responseType: XMLHttpRequestResponseType;
1332
+ /**
1333
+ * expire为-1时的最大过期时间,默认为1天
1334
+ */
1335
+ expireMaxTime:number;
1336
+ /**
1337
+ * 是否跨域传入cookie-默认false
1338
+ */
1339
+
1340
+ withCredentials: boolean;
1341
+ /**
1342
+ * 标头
1343
+ * @example
1344
+ * //默认
1345
+ * {
1346
+ Accept: '*',
1347
+ 'Content-Type': 'application/json'
1348
+ }
1349
+ */
1350
+ headers: THttpReqHeaders;
1351
+ /**
1352
+ * 请求前处理
1353
+ * @param config
1354
+ * @returns
1355
+ */
1356
+ before: (config: callbackConfig,xhr:XMLHttpRequest) => void | Promise<any>;
1357
+ /**
1358
+ * 请求后处理
1359
+ * @param xhr
1360
+ * @returns
1361
+ */
1362
+ after: (xhr:{
1363
+ /**
1364
+ * 获取数据
1365
+ */
1366
+ data: any;
1367
+ /**
1368
+ * 消息类型
1369
+ */
1370
+ responseType: XMLHttpRequestResponseType;
1371
+ /**
1372
+ * 状态码
1373
+ */
1374
+ status: number;
1375
+
1376
+ /**
1377
+ * 当前请求对象
1378
+ */
1379
+ xhr:XMLHttpRequest;
1380
+ },config:callbackConfig) => void | Promise<any>;
1381
+ /**
1382
+ * 异常处理
1383
+ * @param e
1384
+ * @returns
1385
+ */
1386
+ error: (status:number,config:callbackConfig,xhr:{data:any,responseType:XMLHttpRequestResponseType,status:number,xhr:XMLHttpRequest}) => void;
1387
+ }
1388
+
1389
+ /**
1390
+ * 全局请求对象
1391
+ */
1392
+ interface HttpInter {
1393
+ /**
1394
+ * 数据缓存
1395
+ */
1396
+ dataCache:{
1397
+ /**
1398
+ * 数据
1399
+ */
1400
+ [key:string]:{
1401
+ /**
1402
+ * 数据
1403
+ */
1404
+ data:any;
1405
+ /**
1406
+ * 过期时间
1407
+ */
1408
+ expire:number;
1409
+ }
1410
+ };
1411
+ /**
1412
+ * 请求管理器
1413
+ */
1414
+ xhr: {
1415
+ [key: string]: XMLHttpRequest;
1416
+ };
1417
+ /**
1418
+ * get请求
1419
+ */
1420
+ get: THttpReq;
1421
+ /**
1422
+ * post请求
1423
+ */
1424
+ post: THttpReq;
1425
+ /**
1426
+ * 中断所有请求
1427
+ */
1428
+ stop: () => void;
1429
+
1430
+ /**
1431
+ * 配置信息
1432
+ */
1433
+ config: THttpConfig;
1434
+
1435
+ /**
1436
+ * 设置配置信息
1437
+ */
1438
+ setConfig:(config?:Partial<THttpConfig>)=>void
1439
+ }
1440
+
1441
+ /**
1442
+ * 全局请求对象
1443
+ */
1444
+ declare var http:HttpInter;
1445
+
1446
+ /**
1447
+ * 获取一个http请求对象
1448
+ */
1449
+ declare var httpBean:(config?:Partial<THttpConfig>)=>HttpInter;type TimerInfo = {
1450
+ /**
1451
+ * 任务内容
1452
+ * @returns
1453
+ */
1454
+ fun: () => void
1455
+ /**
1456
+ * 挂载节点验证
1457
+ */
1458
+ vm: any
1459
+
1460
+ /**
1461
+ * 任务id
1462
+ */
1463
+ id: string
1464
+
1465
+ /**
1466
+ * 清理
1467
+ */
1468
+ remove: () => void
1469
+ }
1470
+
1471
+ interface Window {
1472
+ [key:string]:any
1473
+ }
1474
+
1475
+ /**
1476
+ * 字符串、数组、数字判空
1477
+ */
1478
+ declare var isNull: (str: any)=> boolean;