@zero-library/common 2.1.11 → 2.2.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.
package/dist/index.d.ts CHANGED
@@ -3,8 +3,9 @@ import * as react from 'react';
3
3
  import { ReactNode } from 'react';
4
4
  import dayjs from 'dayjs';
5
5
  import Decimal from 'decimal.js';
6
+ import { RuleObject } from 'antd/es/form';
7
+ import * as axios from 'axios';
6
8
  import { AxiosRequestConfig } from 'axios';
7
- import { ThemeConfig } from 'antd/lib';
8
9
 
9
10
  /**
10
11
  * 音频播放器组件属性接口
@@ -18,7 +19,7 @@ interface AudioPlayerProps {
18
19
  * 提供基本的音频播放功能
19
20
  * @param props - 组件属性
20
21
  */
21
- declare const _default$b: ({ fileUrl }: AudioPlayerProps) => react_jsx_runtime.JSX.Element;
22
+ declare const _default$m: ({ fileUrl }: AudioPlayerProps) => react_jsx_runtime.JSX.Element;
22
23
 
23
24
  /**
24
25
  * 文件图标组件属性接口
@@ -44,7 +45,7 @@ interface FileIconProps {
44
45
  * @param props - 组件属性
45
46
  * @returns 对应文件类型的图标
46
47
  */
47
- declare const _default$a: ({ suffix, fontSize }: FileIconProps) => react_jsx_runtime.JSX.Element;
48
+ declare const _default$l: ({ suffix, fontSize }: FileIconProps) => react_jsx_runtime.JSX.Element;
48
49
 
49
50
  /**
50
51
  * 文件预览组件属性接口
@@ -79,7 +80,7 @@ interface FilePreviewProps {
79
80
  * 支持图片、PDF、视频、音频、Markdown等文件格式的预览
80
81
  * @param props - 组件属性
81
82
  */
82
- declare const _default$9: ({ suffix, fileUrl, pdfParams, password, searchValue }: FilePreviewProps) => react_jsx_runtime.JSX.Element;
83
+ declare const _default$k: ({ suffix, fileUrl, pdfParams, password, searchValue }: FilePreviewProps) => react_jsx_runtime.JSX.Element;
83
84
 
84
85
  /**
85
86
  * 文件预览抽屉组件属性接口
@@ -130,7 +131,7 @@ interface FilePreviewDrawerProps {
130
131
  * @param props - 组件属性
131
132
  * @returns 文件预览抽屉组件
132
133
  */
133
- declare const _default$8: ({ open, fileUrl, suffix, title, onClose, password, fileParams, pdfParams, onSetPassSuccess }: FilePreviewDrawerProps) => react_jsx_runtime.JSX.Element;
134
+ declare const _default$j: ({ open, fileUrl, suffix, title, onClose, password, fileParams, pdfParams, onSetPassSuccess }: FilePreviewDrawerProps) => react_jsx_runtime.JSX.Element;
134
135
 
135
136
  /**
136
137
  * Markdown预览组件属性接口
@@ -146,7 +147,7 @@ interface MarkdownPreviewProps {
146
147
  * 从指定URL获取Markdown内容并渲染显示
147
148
  * @param props - 组件属性
148
149
  */
149
- declare const _default$7: ({ fileUrl, searchValue }: MarkdownPreviewProps) => react_jsx_runtime.JSX.Element;
150
+ declare const _default$i: ({ fileUrl, searchValue }: MarkdownPreviewProps) => react_jsx_runtime.JSX.Element;
150
151
 
151
152
  /**
152
153
  * PDF预览组件属性接口
@@ -173,7 +174,7 @@ interface PdfPreviewProps {
173
174
  * 支持密码保护、缩略图、缩放、页面导航等功能
174
175
  * @param props - 组件属性
175
176
  */
176
- declare const _default$6: ({ password, fileUrl, pageNo, scale, isHasThumbnails, onSetPassword, onSetPageNo }: PdfPreviewProps) => react_jsx_runtime.JSX.Element;
177
+ declare const _default$h: ({ password, fileUrl, pageNo, scale, isHasThumbnails, onSetPassword, onSetPageNo }: PdfPreviewProps) => react_jsx_runtime.JSX.Element;
177
178
 
178
179
  /**
179
180
  * 视频播放器组件属性接口
@@ -187,12 +188,14 @@ interface VideoPlayerProps {
187
188
  * 提供基本的视频播放功能
188
189
  * @param props - 组件属性
189
190
  */
190
- declare const _default$5: ({ fileUrl }: VideoPlayerProps) => react_jsx_runtime.JSX.Element;
191
+ declare const _default$g: ({ fileUrl }: VideoPlayerProps) => react_jsx_runtime.JSX.Element;
191
192
 
192
193
  /**
193
194
  * Iframe组件属性接口
194
195
  */
195
196
  interface IframeProps {
197
+ /** 默认主源 */
198
+ defaultMainSource?: string;
196
199
  /** iframe ID */
197
200
  id?: string;
198
201
  /** iframe源地址 */
@@ -207,7 +210,7 @@ interface IframeProps {
207
210
  * 支持加载状态、URL参数处理、防缓存等功能
208
211
  * @param props - 组件属性
209
212
  */
210
- declare const _default$4: react.ForwardRefExoticComponent<IframeProps & react.RefAttributes<HTMLIFrameElement>>;
213
+ declare const _default$f: react.ForwardRefExoticComponent<IframeProps & react.RefAttributes<HTMLIFrameElement>>;
211
214
 
212
215
  /**
213
216
  * 组件映射类型,用于延时加载
@@ -232,7 +235,7 @@ interface LazyComponentProps {
232
235
  * 使用示例:<LazyComponent type="renderMarkdown" data={{}} loading={true} />
233
236
  * @param props - 组件属性
234
237
  */
235
- declare const _default$3: ({ type, customComponents, ...rest }: LazyComponentProps) => react_jsx_runtime.JSX.Element;
238
+ declare const _default$e: ({ type, customComponents, ...rest }: LazyComponentProps) => react_jsx_runtime.JSX.Element;
236
239
 
237
240
  /**
238
241
  * Markdown编辑器组件属性接口
@@ -263,7 +266,7 @@ interface MarkdownEditorProps {
263
266
  * 提供丰富的编辑功能:格式化、链接、图片、表格、高亮等
264
267
  * @param props - 组件属性
265
268
  */
266
- declare const _default$2: ({ value, onChange, onScrollPage, searchValue, disabled, extraNav, showToolbar, onQuote, onDownloadFile }: MarkdownEditorProps) => react_jsx_runtime.JSX.Element;
269
+ declare const _default$d: ({ value, onChange, onScrollPage, searchValue, disabled, extraNav, showToolbar, onQuote, onDownloadFile }: MarkdownEditorProps) => react_jsx_runtime.JSX.Element;
267
270
 
268
271
  /**
269
272
  * Markdown渲染组件属性接口
@@ -286,7 +289,7 @@ interface RenderMarkdownProps {
286
289
  * 支持自定义组件、搜索高亮、内容编辑等功能
287
290
  * @param RenderMarkdownProps - 组件属性
288
291
  */
289
- declare const _default$1: ({ content, searchValue, customComponents, onChange, onPartialChange }: RenderMarkdownProps) => react_jsx_runtime.JSX.Element;
292
+ declare const _default$c: ({ content, searchValue, customComponents, onChange, onPartialChange }: RenderMarkdownProps) => react_jsx_runtime.JSX.Element;
290
293
 
291
294
  /**
292
295
  * 渲染控制对象类型
@@ -338,7 +341,8 @@ interface RenderWrapperProps<C, P> {
338
341
  * @param props - 组件属性
339
342
  * @returns 渲染的组件或null
340
343
  */
341
- declare const RenderWrapper: react.ForwardRefExoticComponent<RenderWrapperProps<unknown, unknown> & react.RefAttributes<unknown>>;
344
+ declare const _default$b: react.ForwardRefExoticComponent<RenderWrapperProps<unknown, unknown> & react.RefAttributes<unknown>>;
345
+
342
346
  /**
343
347
  * 判断是否应该渲染组件
344
348
  * @param control - 渲染控制配置
@@ -373,24 +377,94 @@ interface UserAvatarProps {
373
377
  * 如果没有头像图片,则显示用户名首字母作为头像
374
378
  * @param props - 组件属性
375
379
  */
376
- declare const _default: ({ size, avatarSrc, userName }: UserAvatarProps) => react_jsx_runtime.JSX.Element;
380
+ declare const _default$a: ({ size, avatarSrc, userName }: UserAvatarProps) => react_jsx_runtime.JSX.Element;
377
381
 
382
+ /**
383
+ * iframe 消息参数类型
384
+ * 定义跨iframe通信时的参数结构
385
+ */
378
386
  type Params = Record<string, any>;
379
387
  /**
380
- * 通知当前页面的父页面或者顶级窗口
388
+ * 向父页面或顶级窗口发送消息
389
+ * @param type - 消息类型
390
+ * @param data - 消息数据
391
+ * @param to - 发送目标,默认为'top'
381
392
  */
382
393
  declare function emit(type: string, data?: Params, to?: 'parent' | 'top'): void;
383
394
  /**
384
- * 通知某个子 iframe 窗口(必须传入 iframe.contentWindow)
395
+ * 向子iframe发送消息
396
+ * @param iframeWindow - 目标iframe的contentWindow
397
+ * @param type - 消息类型
398
+ * @param data - 消息数据
399
+ * @param origin - 消息源,默认为'*'
385
400
  */
386
401
  declare function emitToChild(iframeWindow: Window | null, type: string, data?: Params, origin?: string): void;
387
402
 
403
+ /**
404
+ * 消息处理器函数类型定义
405
+ * @template P 参数类型,默认为 Params
406
+ * @param params 消息参数
407
+ * @param source 消息源窗口对象
408
+ * @param origin 消息来源
409
+ */
388
410
  type Handler<P = Params> = (params: P, source?: MessageEventSource | null, origin?: string) => void;
389
- declare function useIframeRelayBridge(allowedOrigins?: string[]): {
411
+ /**
412
+ * iframe 消息中继桥接 Hook
413
+ *
414
+ * 提供跨 iframe 消息通信的桥接功能,支持:
415
+ * - 消息监听与分发
416
+ * - 来源验证(白名单机制)
417
+ * - 消息类型处理
418
+ * - 父子窗口通信
419
+ * - 顶层窗口消息转发
420
+ *
421
+ * @param allowedOrigins 允许的消息来源域名列表,默认允许所有来源
422
+ *
423
+ * @example
424
+ * ```tsx
425
+ * const { on, off } = useIframeRelayBridge(['https://example.com'])
426
+ *
427
+ * // 监听消息
428
+ * const handleMessage = (params, source, origin) => {
429
+ * console.log('收到消息:', params)
430
+ * }
431
+ * on('custom-event', handleMessage)
432
+ *
433
+ * // 取消监听
434
+ * off('custom-event', handleMessage)
435
+ * ```
436
+ */
437
+ declare const _default$9: (allowedOrigins?: string[]) => {
390
438
  on: (type: string, handler: Handler<Params>) => void;
391
439
  off: (type: string, handler: Handler<Params>) => void;
392
440
  };
393
441
 
442
+ /**
443
+ * 通用的自动刷新 Hook
444
+ * 监听指定值的变化,当满足条件时自动触发回调函数
445
+ *
446
+ * @param listenValue - 要监听的值
447
+ * @param shouldRefresh - 判断是否需要触发回调的函数,接收 listenValue 作为参数
448
+ * @param callback - 执行刷新动作的异步方法
449
+ * @param delay - 延迟时间(毫秒),默认为 10000ms
450
+ * @returns 清理定时器的函数
451
+ */
452
+ declare const _default$8: <T>(listenValue: T, shouldRefresh: (listenValue: T) => boolean, callback: () => Promise<void>, delay?: number) => void;
453
+
454
+ /**
455
+ * 倒计时 Hook
456
+ * 提供倒计时功能,支持开始、暂停、完成回调等操作
457
+ *
458
+ * @param callback - 倒计时结束时的回调函数
459
+ * @returns 倒计时控制对象
460
+ */
461
+ declare const _default$7: (callback?: () => void) => {
462
+ count: number;
463
+ start: (initialValue?: number) => void;
464
+ pause: () => void;
465
+ startCount: number;
466
+ };
467
+
394
468
  /**
395
469
  * 通用的 Valtio Context 创建工厂 Hook
396
470
  * 创建 Valtio 状态管理的 Context 和 Provider
@@ -402,7 +476,7 @@ declare function useIframeRelayBridge(allowedOrigins?: string[]): {
402
476
  * @template T - Store 对象类型
403
477
  * @returns Valtio Context 相关的工具函数
404
478
  */
405
- declare function useCreateValtioContext<T extends object>(): {
479
+ declare const _default$6: <T extends object>() => {
406
480
  ValtioProvider: ({ store, children }: {
407
481
  store: T;
408
482
  children?: ReactNode;
@@ -419,7 +493,7 @@ declare function useCreateValtioContext<T extends object>(): {
419
493
  * @param wait - 延迟时间(毫秒),默认为400ms
420
494
  * @returns 防抖处理后的函数,包含 flush 和 cancel 方法
421
495
  */
422
- declare function useDebounce<A extends Array<any>, R = void>(func: (..._args: A) => R, wait?: number): {
496
+ declare const _default$5: <A extends Array<any>, R = void>(func: (..._args: A) => R, wait?: number) => {
423
497
  (..._args: A): Promise<R>;
424
498
  /** 添加额外方法到防抖函数 */
425
499
  flush: () => any;
@@ -433,7 +507,7 @@ declare function useDebounce<A extends Array<any>, R = void>(func: (..._args: A)
433
507
  * @param effect - 要执行的副作用函数
434
508
  * @param deps - 依赖项数组
435
509
  */
436
- declare function useDeepEffect(effect: React.EffectCallback, deps: any[]): void;
510
+ declare const _default$4: (effect: React.EffectCallback, deps: any[]) => void;
437
511
 
438
512
  /**
439
513
  * 创建同时具有 ref 和 state 特性的状态 Hook
@@ -442,7 +516,7 @@ declare function useDeepEffect(effect: React.EffectCallback, deps: any[]): void;
442
516
  * @param init - 初始值
443
517
  * @returns [state, setState, getState] 元组,包含状态值、设置函数和获取函数
444
518
  */
445
- declare function useRefState<T>(init: T): readonly [T, (newVal: T) => void, () => T];
519
+ declare const _default$3: <T>(init: T) => readonly [T, (newVal: T) => void, () => T];
446
520
 
447
521
  /**
448
522
  * 同步输入框组件和外部状态的 Hook
@@ -453,7 +527,7 @@ declare function useRefState<T>(init: T): readonly [T, (newVal: T) => void, () =
453
527
  * @param setStoreValue - 设置外部存储值的函数
454
528
  * @returns 包含 inputValue 和 setInputValue 的对象
455
529
  */
456
- declare const useSyncInput: <T>(storeValue: T, setStoreValue: (value: T) => void) => {
530
+ declare const _default$2: <T>(storeValue: T, setStoreValue: (value: T) => void) => {
457
531
  inputValue: T;
458
532
  setInputValue: (value: T) => void;
459
533
  };
@@ -468,166 +542,367 @@ declare const useSyncInput: <T>(storeValue: T, setStoreValue: (value: T) => void
468
542
  * @param wait - 节流间隔时间(毫秒)
469
543
  * @returns 节流处理后的函数,包含 flush 和 cancel 方法
470
544
  */
471
- declare function useThrottle<A extends Array<any>, R = void>(func: (..._args: A) => R, wait: number): {
545
+ declare const _default$1: <A extends Array<any>, R = void>(func: (..._args: A) => R, wait: number) => {
472
546
  (..._args: A): Promise<R>;
473
547
  /** 添加额外方法到节流函数 */
474
548
  flush: () => any;
475
549
  cancel: () => void;
476
550
  };
477
551
 
478
- interface UseWebSocketParams {
552
+ /**
553
+ * useWebSocket Hook 参数类型定义
554
+ */
555
+ interface WebSocketProps {
556
+ /** WebSocket 服务器地址 */
479
557
  url: string;
558
+ /** 接收到消息时的回调函数 */
480
559
  onMessage: (message: any) => void;
560
+ /** 连接关闭时的回调函数(可选) */
481
561
  onClose?: () => void;
562
+ /** 心跳间隔时间,单位毫秒,默认 30000ms */
482
563
  heartbeatInterval?: number;
564
+ /** 心跳消息内容,默认 'ping' */
483
565
  heartbeatMessage?: string;
566
+ /** 是否开启客户端心跳,默认 true */
484
567
  clientHeartbeat?: boolean;
568
+ /** 重连间隔时间,单位毫秒,默认 5000ms */
485
569
  reconnectInterval?: number;
570
+ /** 最大重连尝试次数,不设置则无限重连 */
486
571
  maxReconnectAttempts?: number;
572
+ /** 是否开启重连机制,默认 true */
487
573
  isReconnect?: boolean;
488
574
  }
489
- interface UseWebSocketReturn {
575
+ /**
576
+ * useWebSocket Hook 返回值类型定义
577
+ */
578
+ interface WebSocketType {
579
+ /** 发送消息的方法 */
490
580
  sendMessage: (message: string) => void;
581
+ /** WebSocket 连接状态,对应 WebSocket.readyState */
491
582
  socketReadyState: number | null;
492
583
  }
493
- declare const useWebSocket: ({ url, onMessage, onClose, heartbeatInterval, heartbeatMessage, clientHeartbeat, reconnectInterval, maxReconnectAttempts, isReconnect }: UseWebSocketParams) => UseWebSocketReturn;
584
+ /**
585
+ * WebSocket 连接管理 Hook
586
+ *
587
+ * 提供完整的 WebSocket 连接管理功能,包括:
588
+ * - 自动重连机制
589
+ * - 心跳检测
590
+ * - 页面可见性监听
591
+ * - 连接状态管理
592
+ * - 消息发送与接收
593
+ *
594
+ * @example
595
+ * ```tsx
596
+ * const { sendMessage, socketReadyState } = useWebSocket({
597
+ * url: 'ws://localhost:8080',
598
+ * onMessage: (message) => console.log('收到消息:', message),
599
+ * heartbeatInterval: 30000,
600
+ * maxReconnectAttempts: 5
601
+ * })
602
+ * ```
603
+ */
604
+ declare const _default: ({ url, onMessage, onClose, heartbeatInterval, heartbeatMessage, clientHeartbeat, reconnectInterval, maxReconnectAttempts, isReconnect }: WebSocketProps) => WebSocketType;
494
605
 
495
606
  /**
496
607
  * 深拷贝函数
608
+ *
609
+ * @template T
497
610
  * @param obj - 要拷贝的对象
498
- * @param isJson - 是否使用 JSON 方式深拷贝,默认为 true
611
+ * @param isJson - 是否使用 JSON 深拷贝(默认 true
499
612
  * @returns 拷贝后的新对象
613
+ *
614
+ * @example
615
+ * const a = { x: { y: 1 } }
616
+ * const b = deepCopy(a)
617
+ * b.x.y = 2
618
+ * console.log(a.x.y) // 1
619
+ *
620
+ * @remarks
621
+ * - JSON 深拷贝会丢失:函数、Map、Set、RegExp、Date 等信息
622
+ * - isJson = false 时使用递归版本,性能差但支持大部分类型,支持循环引用
623
+ * - 不处理 Symbol、getter/setter 属性
500
624
  */
501
- declare const deepCopy: <T>(arg: T, isJson?: boolean) => T;
625
+ declare const deepCopy: <T>(obj: T, isJson?: boolean) => T;
502
626
  /**
503
627
  * 深度比较两个对象是否相等
504
- * 支持 Date、RegExp、Map、Set、Array、Function、Object 等类型
628
+ *
505
629
  * @param a - 第一个对象
506
630
  * @param b - 第二个对象
507
631
  * @returns 是否相等
632
+ *
633
+ * @example
634
+ * deepEqual({ a: 1 }, { a: 1 }) // true
635
+ * deepEqual([1, 2], [1, 2]) // true
636
+ * deepEqual(new Date(1), new Date(1)) // true
637
+ * deepEqual(new Set([1]), new Set([1])) // true
638
+ *
639
+ * @remarks
640
+ * - 支持 Date、RegExp、Map、Set、Array、Function(仅作引用比较)、Object
641
+ * - 支持循环引用检测
642
+ * - 不处理不可枚举属性、getter/setter 和 Symbol
508
643
  */
509
644
  declare function deepEqual(a: any, b: any): boolean;
510
645
  /**
511
- * 深度合并两个对象,对于对象类型进行递归合并
646
+ * 深度合并两个对象
647
+ *
648
+ * @template T
512
649
  * @param base - 基础对象
513
650
  * @param override - 覆盖对象
514
651
  * @returns 合并后的新对象
652
+ *
653
+ * @example
654
+ * deepMerge(
655
+ * { a: 1, b: { x: 1 } },
656
+ * { b: { x: 2, y: 3 } }
657
+ * )
658
+ * // => { a: 1, b: { x: 2, y: 3 } }
659
+ *
660
+ * @remarks
661
+ * - 数组不进行合并,只会被直接覆盖
662
+ * - 内部使用递归,性能良好
663
+ * - 只处理普通对象的深度合并,特殊对象(如 Date、RegExp、Map、Set 等)会被直接覆盖
664
+ * - undefined 值会被忽略,不会覆盖原有值
515
665
  */
516
666
  declare const deepMerge: <T extends Record<string, any>>(base: T, override: Partial<T>) => T;
517
667
  /**
518
- * 将键值对象转换为选项数组格式
668
+ * 将对象或者数组转换为下拉选项数组
669
+ *
519
670
  * @param obj - 键值对象
520
- * @returns 选项数组,包含 label 和 value 属性
671
+ * @param filter - 可选的过滤函数,用于过滤不需要的项
672
+ * @returns label/value 数组,value根据键的类型智能转换:数字字符串转为数字,其他保持为字符串
673
+ *
674
+ * @example
675
+ * objToOptions({ 1: '男', 2: '女' })
676
+ * // => [ { label: '男', value: 1 }, { label: '女', value: 2 } ]
677
+ *
678
+ * @example
679
+ * objToOptions({ admin: '管理员', user: '用户' })
680
+ * // => [ { label: '管理员', value: 'admin' }, { label: '用户', value: 'user' } ]
681
+ *
682
+ * @example
683
+ * objToOptions({ '1': '男', '2': '女', '0': '未知' }, (key) => Number(key) > 0)
684
+ * // => [ { label: '男', value: 1 }, { label: '女', value: 2 } ]
521
685
  */
522
- declare const objToOptions: (obj: ObjectType<string>) => {
523
- label: string;
524
- value: number;
686
+ declare const objToOptions: (obj: Record<string, string> | string[], filter?: (key: string, value: string) => boolean) => {
687
+ label: any;
688
+ value: string | number;
525
689
  }[];
526
690
  /**
527
- * 将数组转换为以指定字段为键的对象
528
- * @param arr - 要转换的数组
529
- * @param key - 用作对象键的字段名
691
+ * 将数组按照某个 key 转换为对象
692
+ *
693
+ * @template T
694
+ * @param arr - 数组
695
+ * @param key - 作为对象 key 的字段名
530
696
  * @returns 转换后的对象
697
+ *
698
+ * @example
699
+ * arrToObj([{ id: 1, name: 'a' }], 'id')
700
+ * // => { "1": { id: 1, name: "a" } }
531
701
  */
532
702
  declare const arrToObj: <T>(arr: T[], key: string) => {
533
703
  [key: string]: T;
534
704
  };
535
- interface NsSetIntervalReturnType {
536
- /** 检查是否正在运行 */
537
- isRun: () => boolean;
538
- /** 取消定时器 */
539
- cancel: () => void;
540
- }
541
705
  /**
542
- * 使用 setTimeout 模拟 setInterval 的返回类型接口
543
- * 避免 setInterval 的内存泄漏问题
544
- * @param fn - 要重复执行的函数
545
- * @param t - 间隔时间(毫秒)
546
- * @returns 控制对象,包含 isRun 和 cancel 方法
706
+ * 使用 setTimeout 模拟 setInterval,避免堆积
707
+ *
708
+ * @param fn - 要执行的函数(允许 async)
709
+ * @param t - 间隔毫秒数
710
+ * @returns 控制对象
711
+ *
712
+ * @example
713
+ * const timer = setInterval(() => console.log('run'), 1000)
714
+ *
715
+ * setTimeout(() => timer.cancel(), 5000)
716
+ *
717
+ * @remarks
718
+ * - 可以确保执行 fn 时间不影响下一次调用,天然避免 setInterval 的堆积问题
547
719
  */
548
- declare const nsSetInterval: (fn: () => void, t: number) => NsSetIntervalReturnType;
720
+ declare const setInterval: (fn: () => void | Promise<void>, t: number) => {
721
+ isRun: () => boolean;
722
+ cancel: () => void;
723
+ };
549
724
  /**
550
- * 生成不重复的唯一ID
551
- * @returns 唯一ID字符串
725
+ * 生成唯一的 UUID v4 格式 ID
726
+ * 使用 crypto.randomUUID() 生成符合 RFC 4122 标准的 UUID
727
+ *
728
+ * @returns 符合 UUID v4 格式的唯一标识符字符串
729
+ *
730
+ * @example
731
+ * const id = genNonDuplicateID()
732
+ * console.log(id) // 输出类似: "f8c8e6d2-35a2-4f4d-9d53-994f2b6e1c2d"
552
733
  */
553
- declare const genNonDuplicateID: () => string;
734
+ declare const genNonDuplicateID: () => `${string}-${string}-${string}-${string}-${string}`;
554
735
  /**
555
736
  * 复制文本到剪贴板
556
- * 优先使用 navigator.clipboard API,降级使用 execCommand
557
- * @param text - 要复制的文本
558
- * @param prompt - 提示语
559
- * @returns void
737
+ *
738
+ * @param text - 文本
739
+ * @param prompt - 提示语(默认"复制成功")
740
+ *
741
+ * @example
742
+ * copyText('HELLO')
560
743
  */
561
- declare const copyText: (text: string, prompt?: string) => void;
744
+ declare const copyText: (text: string, prompt?: string) => Promise<void>;
562
745
  /**
563
- * 把后台接口字段,返回的关于金额的数字,转换为千分符号分隔的数字
564
- * return string
746
+ * 数字千分位格式化
747
+ *
748
+ * @param number - 数字或字符串
749
+ * @returns 格式化字符串
750
+ *
751
+ * @example
752
+ * formatNumberWithCommas(1234567) // "1,234,567"
565
753
  */
566
754
  declare function formatNumberWithCommas(number: number | string): string | number;
567
755
  /**
568
- * 生成指定范围内的不重复随机数
756
+ * 生成范围内的不重复随机数
757
+ *
569
758
  * @param min - 最小值
570
759
  * @param max - 最大值
571
760
  * @param count - 生成数量
572
761
  * @returns 不重复的随机数数组
762
+ *
763
+ * @example
764
+ * generateRandomNumbers(1, 100, 3)
765
+ * // => [13, 77, 54]
573
766
  */
574
767
  declare const generateRandomNumbers: (min: number, max: number, count: number) => number[];
575
768
  /**
576
- * 从文件路径中提取文件名
577
- * @param filePath - 文件路径
769
+ * 根据文件路径提取文件名
770
+ *
771
+ * @param filePath - 路径
578
772
  * @returns 文件名
773
+ *
774
+ * @example
775
+ * getFileName('/a/b/c.png?xxx') // "c.png"
579
776
  */
580
777
  declare const getFileName: (filePath: string) => string;
581
778
  /**
582
- * 从文件名中获取文件扩展名
779
+ * 获取文件后缀
780
+ *
583
781
  * @param fileName - 文件名
584
- * @returns 文件扩展名
782
+ * @returns 后缀
783
+ *
784
+ * @example
785
+ * getFileSuffixName('a.png') // "png"
585
786
  */
586
787
  declare const getFileSuffixName: (fileName: string) => string;
587
788
  /**
588
- * 将文本中的换行符转换为 HTML 换行标签
589
- * @param con - 要转换的文本
590
- * @returns 转换后的 HTML 字符串
789
+ * 将换行转换为 <br/>
790
+ *
791
+ * @param con - 文本
792
+ * @returns HTML 字符串
793
+ *
794
+ * @example
795
+ * convertNewlineToBr("a\nb")
796
+ * // => "a<br/>b"
591
797
  */
592
- declare const textAreaView: (con?: string) => string;
798
+ declare const convertNewlineToBr: (con?: string) => string;
593
799
  /**
594
- * 将对象转换为 URL 查询参数字符串
595
- * @param obj - 要转换的对象
596
- * @param url - 要拼接的 URL,如果未提供,则返回查询参数字符串
597
- * @returns URL 查询参数字符串
800
+ * 获取 URL 中所有参数
801
+ * @param url - URL
802
+ * @returns Record<string, string | string[]> 返回参数键值对对象,对于同名参数会以数组形式存储
803
+ *
804
+ * @example
805
+ * getAllUrlParams("http://example.com?a=1&b=2")
806
+ * // => { a: "1", b: "2" }
807
+ *
808
+ * @example
809
+ * getAllUrlParams("http://example.com?a=1&a=2&b=3")
810
+ * // => { a: ["1", "2"], b: "3" }
598
811
  */
599
- declare const buildUrlParams: (obj: Record<string, any>, url?: string) => string;
812
+ declare const getAllUrlParams: (url?: string) => Record<string, string | string[]>;
600
813
  /**
601
- * 下载文件到本地
602
- * @param url - 文件下载地址
603
- * @param name - 下载文件名,默认为'图片下载'
814
+ * 构建 URL 查询参数
815
+ *
816
+ * @param obj - 参数对象
817
+ * @param url - 可选,拼接到某个 URL 上
818
+ * @param format - 数组格式化方式,'repeat' | 'comma'; 默认为 'repeat'
819
+ * @returns 最终字符串
820
+ *
821
+ * @example
822
+ * buildUrlParams({ a: 1, b: [2, 3] })
823
+ * // "a=1&b=2&b=3"
824
+ *
825
+ * buildUrlParams({ a: 1 }, "/api")
826
+ * // "/api?a=1"
827
+ *
828
+ * buildUrlParams({ a: [1, 2] }, "/api", "comma")
829
+ * // "/api?a=1,2"
830
+ */
831
+ declare const buildUrlParams: (obj: Record<string, any>, url?: string, format?: "repeat" | "comma") => string;
832
+ /**
833
+ * 触发浏览器下载文件
834
+ *
835
+ * @param url - 文件地址
836
+ * @param name - 文件名 默认 "图片下载"
837
+ *
838
+ * @example
839
+ * downloadFile("/xx/a.png", "头像.png")
604
840
  */
605
841
  declare const downloadFile: (url: string, name?: string) => void;
606
842
  /**
607
- * 给URL路径最后添加斜杠
608
- * @param url - 要处理的URL,默认为空字符串
609
- * @returns 处理后的URL
843
+ * 给 URL 最后追加斜杠
844
+ *
845
+ * @param url - URL
846
+ * @returns 新 URL
847
+ *
848
+ * @example
849
+ * addUrlLastSlash("/api/user") // "/api/user/"
610
850
  */
611
851
  declare const addUrlLastSlash: (url?: string) => string;
612
852
  /**
613
853
  * 给URL增加mainSource参数
614
- * @param url - 目标URL
615
- * @param preHref - 参考URL,用于获取mainSource参数
616
- * @returns 处理后的URL
854
+ *
855
+ * 此函数用于在URL中添加或保留mainSource查询参数,主要用于追踪来源。
856
+ * 如果URL中已经存在mainSource参数,则不会修改该URL。
857
+ * 如果不存在,则会从preHref参数中提取mainSource值,如果preHref中也没有,
858
+ * 则使用默认值defaultMainSource。
859
+ *
860
+ * @param url - 需要处理的目标URL
861
+ * @param preHref - 可选,参考URL,用于从中提取mainSource参数值
862
+ * @param defaultMainSource - 可选,mainSource默认值,默认为'cube-uc'
863
+ * @returns 添加了mainSource参数的URL字符串
864
+ *
865
+ * @example
866
+ * // URL中已有mainSource参数,直接返回原URL
867
+ * setUrlMainSource('https://example.com/page?mainSource=adwords')
868
+ * // => 'https://example.com/page?mainSource=adwords'
869
+ *
870
+ * @example
871
+ * // URL中没有mainSource参数,preHref中有mainSource参数
872
+ * setUrlMainSource('https://example.com/page', 'https://referrer.com/?mainSource=facebook')
873
+ * // => 'https://example.com/page?mainSource=facebook'
874
+ *
875
+ * @example
876
+ * // URL和preHref中都没有mainSource参数,使用默认值
877
+ * setUrlMainSource('https://example.com/page')
878
+ * // => 'https://example.com/page?mainSource=defaultMainSource'
617
879
  */
618
- declare const getUrlMainSource: (url: string, preHref?: string) => string;
880
+ declare const setUrlMainSource: (url: string, preHref?: string, defaultMainSource?: string) => string;
619
881
  /**
620
- * 获取 WebSocket 连接地址
621
- * @param path - WebSocket 服务路径,比如 "/ws" 或 "/socket"
622
- * @param customHost - 可选,指定 host:port;默认取当前 window.location.host
623
- * @returns 完整的 WebSocket URL
882
+ * 构建 WebSocket 地址
883
+ *
884
+ * @param path - WS 路径
885
+ * @param customHost - 可选 host; 默认使用当前页面的 host
886
+ * @returns 完整 WS 地址
887
+ *
888
+ * @example
889
+ * getWebSocketUrl("/ws") // "ws://xxx/ws"
624
890
  */
625
891
  declare const getWebSocketUrl: (path: string, customHost?: string) => string;
626
892
  /**
627
- * 对象转换函数,将源对象转换为目标对象
893
+ * 按照字段映射转换对象
894
+ *
895
+ * @template T, U
628
896
  * @param source - 源对象
629
- * @param fieldMap - 字段映射配置
630
- * @returns 转换后的目标对象
897
+ * @param fieldMap - 字段映射表
898
+ * @returns 转换结果
899
+ *
900
+ * @example
901
+ * transform(
902
+ * { a: 1, b: 2 },
903
+ * { x: 'a', y: (s) => s.b + 1 }
904
+ * )
905
+ * // => { x: 1, y: 3 }
631
906
  */
632
907
  declare function transform<T extends object, U extends object>(source: T, fieldMap: {
633
908
  [K in keyof U]: keyof T | ((source: T) => U[K]) | U[K];
@@ -637,278 +912,1255 @@ declare function transform<T extends object, U extends object>(source: T, fieldM
637
912
  * @param sources - 源对象数组
638
913
  * @param fieldMap - 字段映射配置
639
914
  * @returns 转换后的目标对象数组
915
+ *
916
+ * @example
917
+ * transforms([{ a: 1 }], { x: 'a' })
918
+ * // => [{ x: 1 }]
640
919
  */
641
920
  declare function transforms<T extends object, U extends object>(sources: T[], fieldMap: {
642
921
  [K in keyof U]: keyof T | ((source: T) => U[K]) | U[K];
643
922
  }): U[];
923
+ /**
924
+ * 将数字金额转换为中文大写金额
925
+ *
926
+ * 该函数将阿拉伯数字表示的金额转换为中文大写形式,常用于财务票据、合同等正式场合
927
+ * 支持处理整数和小数部分,最大处理金额不超过 999,999,999,999,999.9999
928
+ *
929
+ * @param money - 需要转换的金额,可以是数字或字符串形式的数字
930
+ * @returns 中文大写金额字符串
931
+ *
932
+ * @example
933
+ * convertCurrency(123456.78)
934
+ * // => "壹拾贰万叁仟肆佰伍拾陆圆柒角捌分"
935
+ *
936
+ * @example
937
+ * convertCurrency("1000")
938
+ * // => "壹仟圆整"
939
+ *
940
+ * @example
941
+ * convertCurrency(-123.45)
942
+ * // => "(负数)壹佰贰拾叁圆肆角伍分"
943
+ */
944
+ declare const convertCurrency: (money?: string | number) => string;
945
+ /**
946
+ * 计算表格中指定列的行合并数量
947
+ *
948
+ * 该函数通常用于表格渲染中,根据某一列的相同值进行行合并(rowspan)
949
+ * 它会将连续相同的值分为一组,并返回目标位置所在的组的大小
950
+ *
951
+ * @param data - 数据数组,每一项应为对象
952
+ * @param key - 需要检查的字段名,用于比较值是否相同
953
+ * @param target - 目标索引位置,函数将返回该位置所在组的大小
954
+ * @returns 目标位置所在组的大小,如果是组的第一个元素则返回组大小,否则返回0
955
+ *
956
+ * @example
957
+ * const data = [
958
+ * { name: 'Alice', dept: 'IT' },
959
+ * { name: 'Bob', dept: 'IT' },
960
+ * { name: 'Charlie', dept: 'HR' },
961
+ * { name: 'David', dept: 'HR' },
962
+ * { name: 'Eve', dept: 'HR' }
963
+ * ]
964
+ *
965
+ * getRowSpanCount(data, 'dept', 0) // 返回 2 (IT部门有2人)
966
+ * getRowSpanCount(data, 'dept', 1) // 返回 0 (IT部门第2个人)
967
+ * getRowSpanCount(data, 'dept', 2) // 返回 3 (HR部门有3人)
968
+ * getRowSpanCount(data, 'dept', 3) // 返回 0 (HR部门第2个人)
969
+ * getRowSpanCount(data, 'dept', 4) // 返回 0 (HR部门第3个人)
970
+ */
971
+ declare const getRowSpanCount: (data: any[], key: string, target: number) => any;
972
+ /**
973
+ * 动态加载第三方文件(JavaScript 或 CSS)
974
+ *
975
+ * 该函数用于在运行时动态加载外部资源文件,支持 JavaScript 和 CSS 文件
976
+ * 主要用于按需加载第三方库或样式文件,避免在页面初始加载时引入所有资源
977
+ *
978
+ * @param document - DOM 文档对象,用于创建和插入元素
979
+ * @param path - 文件路径,支持相对路径或绝对路径
980
+ *
981
+ * @example
982
+ * // 加载 JavaScript 文件
983
+ * importThirdPartyFile(document, 'https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.js')
984
+ *
985
+ * @example
986
+ * // 加载 CSS 文件
987
+ * importThirdPartyFile(document, '/assets/styles/third-party.css')
988
+ *
989
+ * @example
990
+ * // 加载本地 JavaScript 文件
991
+ * importThirdPartyFile(document, './libs/custom-lib.js')
992
+ *
993
+ * @remarks
994
+ * - 根据文件扩展名自动识别文件类型(.js 为脚本文件,其他为样式文件)
995
+ * - JavaScript 文件会异步加载(async = true)
996
+ * - CSS 文件会作为 stylesheet 添加到文档头部
997
+ * - 需要确保 document.head 存在才会添加元素
998
+ */
999
+ declare const importThirdPartyFile: (document: Document, path: string) => void;
1000
+ /**
1001
+ * 主要用于处理需要设置key的数组数据
1002
+ *
1003
+ * 该函数用于过滤和处理项目数组,主要功能包括:
1004
+ * 1. 过滤掉标记为隐藏的项目(hidden 为 true 的项目)
1005
+ * 2. 为每个项目添加唯一的 key 属性(使用数组索引)
1006
+ *
1007
+ * @template T - 项目类型,hidden 属性(可选)
1008
+ * @param items - 需要处理的项目数组
1009
+ * @returns 处理后的项目数组,已过滤隐藏项并添加了 key 属性(优先使用数组项自身的key属性)
1010
+ *
1011
+ * @example
1012
+ * // 过滤带有 hidden 标记的菜单项
1013
+ * const menuItems = [
1014
+ * { name: '首页', path: '/', hidden: true },
1015
+ * { name: '关于', path: '/about' },
1016
+ * { name: '联系', path: '/contact', hidden: false }
1017
+ * ];
1018
+ * const processedItems = processItemList(menuItems);
1019
+ * // 结果: [{ key: 0, name: '关于', path: '/about' }, { key: 1, name: '联系', path: '/contact', hidden: false }]
1020
+ *
1021
+ * @remarks
1022
+ * - 该函数不会修改原始数组,而是返回一个新的处理后的数组
1023
+ * - key 值基于过滤后的数组索引生成,不是原始数组的索引
1024
+ * - hidden 属性为 true 的项目会被过滤掉,其他情况(false、undefined、null等)都会保留
1025
+ */
1026
+ declare const processItemList: <T extends {
1027
+ hidden?: boolean;
1028
+ }>(items: T[]) => (T & {
1029
+ key: number;
1030
+ })[];
1031
+ /**
1032
+ * 执行安全的脚本代码
1033
+ *
1034
+ * @param script - 需要执行的脚本代码字符串
1035
+ * @param params - 传递给脚本的参数对象,键为参数名,值为参数值
1036
+ *
1037
+ * @example
1038
+ * // 执行简单的数学运算脚本
1039
+ * executeScript('return a + b;', { a: 1, b: 2 });
1040
+ *
1041
+ * @example
1042
+ * // 执行带条件逻辑的脚本
1043
+ * executeScript(`
1044
+ * if (age >= 18) {
1045
+ * return "成年人";
1046
+ * } else {
1047
+ * return "未成年人";
1048
+ * }
1049
+ * `, { age: 20 });
1050
+ *
1051
+ * @example
1052
+ * // 执行数组处理脚本
1053
+ * executeScript(`
1054
+ * return numbers.map(n => n * 2).filter(n => n > 5);
1055
+ * `, { numbers: [1, 2, 3, 4, 5] });
1056
+ *
1057
+ * @remarks
1058
+ * - 函数会先调用 isScriptSafe 检查脚本安全性,只有安全的脚本才会被执行
1059
+ * - 使用 Function 构造器而非 eval,相对更安全
1060
+ * - 参数通过解构方式传递给脚本函数
1061
+ * - 脚本中可以直接使用 params 对象中的键作为变量名
1062
+ * - 如果脚本执行出错,会在控制台输出错误信息
1063
+ *
1064
+ * @security
1065
+ * - 脚本执行在 JavaScript 运行时环境中,仍可能访问全局对象
1066
+ * - 应确保传入的脚本来自可信源
1067
+ * - 仅依赖 isScriptSafe 检查不足以防范所有安全风险
1068
+ */
1069
+ declare const executeScript: (script: string, params: {
1070
+ [key: string]: any;
1071
+ }) => any;
1072
+ /**
1073
+ * AES 加密
1074
+ * @param data - 需要加密的数据
1075
+ * @param key - 加密密钥
1076
+ * @returns 加密后的字符串
1077
+ * @throws 当密钥为空或加密过程失败时抛出错误
1078
+ */
1079
+ declare function aesEncrypt<T = any>(data: T, key: string): string;
1080
+ /**
1081
+ * AES 解密
1082
+ * @param data - 加密后的字符串
1083
+ * @param key - 解密密钥
1084
+ * @returns 解密后的数据,解密失败时返回null
1085
+ */
1086
+ declare function aesDecrypt<T = any>(data: string, key: string): T | null;
644
1087
 
645
1088
  type DateType = string | number | Date | dayjs.Dayjs | null;
646
1089
  /** 默认日期时间格式:年-月-日 时:分:秒 */
647
- declare const DateFormatType = "YYYY-MM-DD HH:mm:ss";
1090
+ declare const DEFAULT_DATE_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
648
1091
  /** 默认日期格式:年-月-日 */
649
- declare const DateFormatType2 = "YYYY-MM-DD";
1092
+ declare const DEFAULT_DATE_FORMAT = "YYYY-MM-DD";
1093
+ /** 年月中文格式:**年**月 */
1094
+ declare const DEFAULT_YEAR_MONTH_FORMAT = "YYYY\u5E74MM\u6708";
1095
+ /** 年月日格式:**年**月**日 */
1096
+ declare const DEFAULT_YEAR_MONTH_DAY_FORMAT = "YYYY\u5E74MM\u6708DD\u65E5";
650
1097
  /**
651
- * 获取一天的最早时间 '2023/10/17 00:00:00' 的时间戳
1098
+ * 获取指定日期开始时间戳 (如: '2023/10/17 00:00:00')
1099
+ * @param date 日期
1100
+ * @param unit 时间单位,默认为 'date' (天)
1101
+ * @returns 时间戳
652
1102
  */
653
1103
  declare const getStartOfTimestamp: (date?: DateType, unit?: dayjs.OpUnitType) => number;
654
1104
  /**
655
- * 获取一天的最晚时间 '2023/10/17 23:59:59' 的时间戳
1105
+ * 获取指定日期结束时间戳 (如: '2023/10/17 23:59:59')
1106
+ * @param date 日期
1107
+ * @param unit 时间单位,默认为 'date' (天)
1108
+ * @returns 时间戳
656
1109
  */
657
1110
  declare const getEndOfTimestamp: (date?: DateType, unit?: dayjs.OpUnitType) => number;
1111
+ /**
1112
+ * 格式化日期
1113
+ * @param date 待格式化的日期
1114
+ * @param format 格式字符串,默认为 'YYYY-MM-DD HH:mm:ss'
1115
+ * @returns 格式化后的日期字符串
1116
+ */
658
1117
  declare const formatDate: (date: Date | number | string, fmt?: string) => string;
1118
+ /**
1119
+ * 获取日期的时间戳
1120
+ * @param date 日期,默认当前时间
1121
+ * @returns 时间戳
1122
+ */
659
1123
  declare const getTimestamp: (date?: DateType) => number;
1124
+ /**
1125
+ * 检查日期是否已过期
1126
+ * @param date 待检查的日期, 默认当前时间
1127
+ * @returns 是否过期
1128
+ */
660
1129
  declare const isExpire: (date?: DateType) => boolean;
661
1130
 
662
1131
  /**
663
1132
  * 类型判断函数
1133
+ *
664
1134
  * @param val - 要判断的值
665
1135
  * @param type - 目标类型名
666
1136
  * @returns 是否为目标类型
1137
+ *
1138
+ * @example
1139
+ * ```typescript
1140
+ * is({}, 'Object') // true
1141
+ * is([], 'Array') // true
1142
+ * is(123, 'Number') // true
1143
+ * ```
667
1144
  */
668
1145
  declare function is(val: unknown, type: string): boolean;
669
1146
  /**
670
1147
  * 判断值是否为 undefined
1148
+ *
671
1149
  * @param val - 要判断的值
672
1150
  * @returns 是否为 undefined
1151
+ *
1152
+ * @example
1153
+ * ```typescript
1154
+ * isUnDef(undefined) // true
1155
+ * isUnDef(null) // false
1156
+ * isUnDef(0) // false
1157
+ * ```
673
1158
  */
674
1159
  declare function isUnDef<T = unknown>(val?: T): val is T;
675
1160
  /**
676
1161
  * 判断值是否已定义(非 undefined)
1162
+ *
677
1163
  * @param val - 要判断的值
678
1164
  * @returns 是否已定义
1165
+ *
1166
+ * @example
1167
+ * ```typescript
1168
+ * isDef(null) // true
1169
+ * isDef(0) // true
1170
+ * isDef('') // true
1171
+ * isDef(undefined) // false
1172
+ * ```
679
1173
  */
680
1174
  declare function isDef<T = unknown>(val?: T): val is T;
681
1175
  /**
682
- * 判断值是否为对象(不包括 FormData 等)
1176
+ * 判断值是否为纯对象
1177
+ *
683
1178
  * @param val - 要判断的值
684
- * @returns 是否为对象
1179
+ * @returns 是否为纯对象
1180
+ *
1181
+ * @example
1182
+ * ```typescript
1183
+ * isObject({}) // true
1184
+ * isObject([]) // false
1185
+ * isObject(null) // false
1186
+ * isObject(new Date()) // false
1187
+ * ```
685
1188
  */
686
1189
  declare function isObject(val: any): val is Record<any, any>;
687
1190
  /**
688
1191
  * 判断对象是否为空对象
1192
+ *
689
1193
  * @param val - 要判断的值
690
1194
  * @returns 是否为空对象
1195
+ *
1196
+ * @example
1197
+ * ```typescript
1198
+ * isEmptyObj({}) // true
1199
+ * isEmptyObj({ a: 1 }) // false
1200
+ * isEmptyObj([]) // false
1201
+ * isEmptyObj(null) // false
1202
+ * ```
691
1203
  */
692
1204
  declare function isEmptyObj<T = unknown>(val: T): boolean;
693
1205
  /**
694
1206
  * 判断值是否为 Date 对象
1207
+ *
695
1208
  * @param val - 要判断的值
696
1209
  * @returns 是否为 Date 对象
1210
+ *
1211
+ * @example
1212
+ * ```typescript
1213
+ * isDate(new Date()) // true
1214
+ * isDate('2023-01-01') // false
1215
+ * isDate({}) // false
1216
+ * ```
697
1217
  */
698
1218
  declare function isDate(val: unknown): val is Date;
1219
+ /**
1220
+ * 判断值是否为 null
1221
+ *
1222
+ * @param val - 要判断的值
1223
+ * @returns 是否为 null
1224
+ *
1225
+ * @example
1226
+ * ```typescript
1227
+ * isNull(null) // true
1228
+ * isNull(undefined) // false
1229
+ * isNull(0) // false
1230
+ * ```
1231
+ */
699
1232
  declare function isNull(val: unknown): val is null;
1233
+ /**
1234
+ * 判断值是否为 null 或 undefined
1235
+ *
1236
+ * @param val - 要判断的值
1237
+ * @returns 是否为 null 或 undefined
1238
+ *
1239
+ * @example
1240
+ * ```typescript
1241
+ * isNullOrUnDef(null) // true
1242
+ * isNullOrUnDef(undefined) // true
1243
+ * isNullOrUnDef(0) // false
1244
+ * isNullOrUnDef('') // false
1245
+ * ```
1246
+ */
700
1247
  declare function isNullOrUnDef(val: unknown): val is null | undefined;
1248
+ /**
1249
+ * 判断值是否为数字(包括 NaN)
1250
+ *
1251
+ * @param val - 要判断的值
1252
+ * @returns 是否为数字类型
1253
+ *
1254
+ * @example
1255
+ * ```typescript
1256
+ * isNumber(123) // true
1257
+ * isNumber('123') // false
1258
+ * isNumber(NaN) // true
1259
+ * ```
1260
+ */
701
1261
  declare function isNumber(val: unknown): val is number;
1262
+ /**
1263
+ * 判断值是否为有效数字(不包括 NaN)
1264
+ *
1265
+ * @param val - 要判断的值
1266
+ * @returns 是否为有效数字
1267
+ *
1268
+ * @example
1269
+ * ```typescript
1270
+ * isNumberNoNaN(123) // true
1271
+ * isNumberNoNaN(NaN) // false
1272
+ * isNumberNoNaN('123') // false
1273
+ * ```
1274
+ */
702
1275
  declare function isNumberNoNaN(val: unknown): val is number;
1276
+ /**
1277
+ * 判断值是否为字符串
1278
+ *
1279
+ * @param val - 要判断的值
1280
+ * @returns 是否为字符串
1281
+ *
1282
+ * @example
1283
+ * ```typescript
1284
+ * isString('hello') // true
1285
+ * isString(123) // false
1286
+ * isString(new String('hello')) // true
1287
+ * ```
1288
+ */
703
1289
  declare function isString(val: unknown): val is string;
1290
+ /**
1291
+ * 判断值是否为函数
1292
+ *
1293
+ * @param val - 要判断的值
1294
+ * @returns 是否为函数
1295
+ *
1296
+ * @example
1297
+ * ```typescript
1298
+ * isFunction(() => {}) // true
1299
+ * isFunction(function() {}) // true
1300
+ * isFunction('function') // false
1301
+ * isFunction({}) // false
1302
+ * ```
1303
+ */
704
1304
  declare function isFunction(val: unknown): boolean;
1305
+ /**
1306
+ * 判断值是否为 Promise 对象
1307
+ *
1308
+ * @param val - 要判断的值
1309
+ * @returns 是否为 Promise
1310
+ *
1311
+ * @example
1312
+ * ```typescript
1313
+ * isPromise(Promise.resolve()) // true
1314
+ * isPromise({ then: () => {}, catch: () => {} }) // false
1315
+ * isPromise({}) // false
1316
+ * ```
1317
+ */
705
1318
  declare function isPromise<T = any>(val: unknown): val is Promise<T>;
1319
+ /**
1320
+ * 判断值是否为布尔值
1321
+ *
1322
+ * @param val - 要判断的值
1323
+ * @returns 是否为布尔值
1324
+ *
1325
+ * @example
1326
+ * ```typescript
1327
+ * isBoolean(true) // true
1328
+ * isBoolean(false) // true
1329
+ * isBoolean(1) // false
1330
+ * isBoolean('true') // false
1331
+ * ```
1332
+ */
706
1333
  declare function isBoolean(val: unknown): val is boolean;
1334
+ /**
1335
+ * 判断值是否为正则表达式
1336
+ *
1337
+ * @param val - 要判断的值
1338
+ * @returns 是否为正则表达式
1339
+ *
1340
+ * @example
1341
+ * ```typescript
1342
+ * isRegExp(/test/) // true
1343
+ * isRegExp(new RegExp('test')) // true
1344
+ * isRegExp('/test/') // false
1345
+ * isRegExp({}) // false
1346
+ * ```
1347
+ */
707
1348
  declare function isRegExp(val: unknown): val is RegExp;
708
- declare function isArray(val: any): val is Array<any>;
709
- declare function isEmpty<T = unknown>(val: T): val is T;
1349
+ /**
1350
+ * 判断值是否为数组
1351
+ *
1352
+ * @param val - 要判断的值
1353
+ * @returns 是否为数组
1354
+ *
1355
+ * @example
1356
+ * ```typescript
1357
+ * isArray([]) // true
1358
+ * isArray([1, 2, 3]) // true
1359
+ * isArray({}) // false
1360
+ * isArray('array') // false
1361
+ * ```
1362
+ */
1363
+ declare function isArray<T = any>(val: unknown): val is Array<T>;
1364
+ /**
1365
+ * 判断值是否为空值
1366
+ *
1367
+ * @param val - 要判断的值
1368
+ * @returns 是否为空值
1369
+ *
1370
+ * @example
1371
+ * ```typescript
1372
+ * isEmpty('') // true
1373
+ * isEmpty([]) // true
1374
+ * isEmpty({}) // true
1375
+ * isEmpty(null) // true
1376
+ * isEmpty(undefined) // true
1377
+ * isEmpty(0) // false
1378
+ * isEmpty(false) // false
1379
+ * ```
1380
+ */
1381
+ declare function isEmpty<T = unknown>(val: T): boolean;
1382
+ /**
1383
+ * 判断值是否为 Window 对象
1384
+ *
1385
+ * @param val - 要判断的值
1386
+ * @returns 是否为 Window 对象
1387
+ *
1388
+ * @example
1389
+ * ```typescript
1390
+ * isWindow(window) // true
1391
+ * isWindow({}) // false
1392
+ * isWindow(global) // false
1393
+ * ```
1394
+ */
710
1395
  declare function isWindow(val: any): val is Window;
1396
+ /**
1397
+ * 判断值是否为 DOM 元素
1398
+ *
1399
+ * @param val - 要判断的值
1400
+ * @returns 是否为 DOM 元素
1401
+ *
1402
+ * @example
1403
+ * ```typescript
1404
+ * isElement(document.body) // true
1405
+ * isElement(document.createElement('div')) // true
1406
+ * isElement({ tagName: 'div' }) // false
1407
+ * isElement('div') // false
1408
+ * ```
1409
+ */
711
1410
  declare function isElement(val: unknown): val is Element;
712
- declare function isMap(val: unknown): val is Map<any, any>;
713
- /** 判断是否为服务端环境(无 window 对象) */
714
- declare const isServer: boolean;
715
- /** 判断是否为客户端环境(有 window 对象) */
716
- declare const isClient: boolean;
717
1411
  /**
718
- * 判断是否是外链
719
- * @param {string} path
720
- * @returns {Boolean}
721
- * @author LiQingSong
1412
+ * 判断值是否为 Map 对象
1413
+ *
1414
+ * @param val - 要判断的值
1415
+ * @returns 是否为 Map
1416
+ *
1417
+ * @example
1418
+ * ```typescript
1419
+ * isMap(new Map()) // true
1420
+ * isMap(new WeakMap()) // false
1421
+ * isMap({}) // false
1422
+ * ```
1423
+ */
1424
+ declare function isMap<K = any, V = any>(val: unknown): val is Map<K, V>;
1425
+ /**
1426
+ * 判断值是否为 Set 对象
1427
+ *
1428
+ * @param val - 要判断的值
1429
+ * @returns 是否为 Set
1430
+ *
1431
+ * @example
1432
+ * ```typescript
1433
+ * isSet(new Set()) // true
1434
+ * isSet(new WeakSet()) // false
1435
+ * isSet([]) // false
1436
+ * ```
1437
+ */
1438
+ declare function isSet<T = any>(val: unknown): val is Set<T>;
1439
+ /**
1440
+ * 判断是否为外部链接
1441
+ *
1442
+ * @param path - 路径字符串
1443
+ * @returns 是否为外部链接
1444
+ *
1445
+ * @example
1446
+ * ```typescript
1447
+ * isExternal('https://example.com') // true
1448
+ * isExternal('mailto:test@example.com') // true
1449
+ * isExternal('tel:123456789') // true
1450
+ * isExternal('/home') // false
1451
+ * isExternal('http://localhost:3000') // true
1452
+ * ```
722
1453
  */
723
1454
  declare const isExternal: (path: string) => boolean;
724
- declare const isBlob: (val: unknown) => boolean;
725
- declare const isLocalhost: (host?: string) => boolean;
726
-
727
1455
  /**
728
- * 设置当前用户信息到 sessionStorage(AES 加密存储)
729
- * @param userInfo - 用户信息对象
1456
+ * 判断值是否为 Blob 对象
1457
+ *
1458
+ * @param val - 要判断的值
1459
+ * @returns 是否为 Blob
1460
+ *
1461
+ * @example
1462
+ * ```typescript
1463
+ * isBlob(new Blob()) // true
1464
+ * isBlob(new File([], 'test.txt')) // true
1465
+ * isBlob({}) // false
1466
+ * ```
730
1467
  */
731
- declare function setCurrentUser(userInfo: any): void;
1468
+ declare const isBlob: (val: unknown) => val is Blob;
732
1469
  /**
733
- * 从 sessionStorage 获取当前用户信息(AES 解密)
734
- * @returns 用户信息对象或 null
1470
+ * 判断是否为本地主机
1471
+ *
1472
+ * @param host - 主机名,默认取当前 location.host
1473
+ * @returns 是否为本地主机
1474
+ *
1475
+ * @example
1476
+ * ```typescript
1477
+ * isLocalhost() // 检查当前主机
1478
+ * isLocalhost('localhost:3000') // true
1479
+ * isLocalhost('127.0.0.1:3000') // true
1480
+ * isLocalhost('example.com') // false
1481
+ * ```
735
1482
  */
736
- declare function getCurrentUser(): any;
1483
+ declare const isLocalhost: (host?: string) => boolean;
737
1484
  /**
738
- * 清除 sessionStorage 中的用户信息
1485
+ * 判断值是否为引用类型(对象或函数)
1486
+ * 引用类型包括:Object, Array, Function, Date, RegExp, Map, Set 等
1487
+ *
1488
+ * @param val - 要判断的值
1489
+ * @returns 是否为引用类型
1490
+ *
1491
+ * @example
1492
+ * ```typescript
1493
+ * isReferenceType({}) // true
1494
+ * isReferenceType([]) // true
1495
+ * isReferenceType(function(){}) // true
1496
+ * isReferenceType(null) // false
1497
+ * isReferenceType(undefined) // false
1498
+ * isReferenceType(123) // false
1499
+ * isReferenceType('string') // false
1500
+ * ```
1501
+ */
1502
+ declare function isReferenceType(val: unknown): boolean;
1503
+ /**
1504
+ * 检查脚本字符串是否安全
1505
+ *
1506
+ * 该函数用于检测给定的脚本字符串是否包含潜在的不安全代码,
1507
+ * 主要用于防范 XSS(跨站脚本攻击)和其他安全风险。
1508
+ * 通过检测常见的危险关键字和全局对象来判断脚本的安全性。
1509
+ *
1510
+ * @param script - 需要检查的脚本字符串
1511
+ * @returns 如果脚本被认为是安全的则返回 true,否则返回 false
1512
+ *
1513
+ * @example
1514
+ * // 安全的脚本
1515
+ * isScriptSafe('const a = 1; console.log(a);') // true
1516
+ *
1517
+ * @example
1518
+ * // 不安全的脚本(包含 eval)
1519
+ * isScriptSafe('eval("alert(1)")') // false
1520
+ *
1521
+ * @example
1522
+ * // 不安全的脚本(访问全局对象)
1523
+ * isScriptSafe('window.location.href = "http://malicious.com"') // false
1524
+ *
1525
+ * @remarks
1526
+ * - 该函数仅做基础的关键字检测,不能保证 100% 安全
1527
+ * - 对于复杂的安全需求,应使用专门的沙箱环境或服务端验证
1528
+ * - 函数不区分大小写进行关键字匹配
1529
+ * - 关键字使用单词边界匹配,避免误判(如 'evaluation' 不会被误判为 'eval')
1530
+ *
1531
+ * @security
1532
+ * - 注意:这只是一个基础的安全检查,不应作为唯一的安全防护措施
1533
+ * - 生产环境中建议结合 Content Security Policy (CSP) 等多重安全机制
739
1534
  */
740
- declare function clearCurrentUser(): void;
1535
+ declare const isScriptSafe: (script: string) => boolean;
741
1536
  /**
742
- * 获取或生成设备唯一标识
743
- * @returns 设备ID字符串
1537
+ * 检查字符串是否为有效的 JSON 格式
1538
+ *
1539
+ * @param text - 需要检查的字符串,默认为空字符串
1540
+ * @returns 如果字符串是有效的 JSON 格式则返回 true,否则返回 false
1541
+ *
1542
+ * @example
1543
+ * isJson('{"name": "张三", "age": 25}') // true
1544
+ * isJson('[1, 2, 3]') // true
1545
+ * isJson('hello world') // false
1546
+ * isJson('true') // false (虽然 JSON.parse('true') 有效,但不是对象或数组)
1547
+ * isJson('') // false
1548
+ *
1549
+ * @remarks
1550
+ * - 该函数使用 try/catch 机制来捕获 JSON.parse 解析结果
1551
+ * - 只接受 JSON 对象 ({}) 或 JSON 数组 ([]),不接受基本类型值 (如: true, 123, "string")
744
1552
  */
745
- declare function getDeviceId(): string;
1553
+ declare const isJson: (text?: string) => boolean;
746
1554
 
747
1555
  /** 数学运算符类型 */
748
1556
  type OperatorType = '+' | '-' | '*' | '/';
749
1557
  /**
750
1558
  * 通用数学计算函数
1559
+ * 支持链式运算,对多个数值执行相同类型的运算
1560
+ *
1561
+ * 实现原理:
1562
+ * 1. 取第一个数值作为初始值
1563
+ * 2. 使用reduce对剩余数值依次进行运算
1564
+ * 3. 使用Decimal.js确保精度
1565
+ *
751
1566
  * @param operator - 运算符:+、-、*、/
752
- * @param args - 要计算的数值数组
1567
+ * @param args - 要计算的数值数组(可变参数)
753
1568
  * @returns 计算结果字符串
1569
+ *
1570
+ * @example
1571
+ * calculate('+', 0.1, 0.2) // 返回 "0.3"
1572
+ * calculate('*', 2, 3, 4) // 返回 "24"
754
1573
  */
755
1574
  declare const calculate: (operator: OperatorType, ...args: Decimal.Value[]) => string;
756
1575
  /**
757
1576
  * 精确加法运算
758
- * 调用:plus(arg1,arg2)
759
- * 返回值:arg1加arg2的精确结果
1577
+ * 解决JavaScript浮点数精度问题,支持多个数值相加
1578
+ *
1579
+ * @param args - 要相加的数值列表(可变参数)
1580
+ * @returns 相加结果字符串
1581
+ *
1582
+ * @example
1583
+ * plus(0.1, 0.2) // 返回 "0.3"
1584
+ * plus(1, 2, 3, 4, 5) // 返回 "15"
760
1585
  */
761
1586
  declare const plus: (...args: Decimal.Value[]) => string;
762
1587
  /**
763
1588
  * 精确减法运算
764
- * 调用:minus(arg1,arg2)
765
- * 返回值:arg1减arg2的精确结果
1589
+ * 解决JavaScript浮点数精度问题,支持多个数值连续相减
1590
+ *
1591
+ * @param args - 要相减的数值列表(可变参数)
1592
+ * @returns 相减结果字符串
1593
+ *
1594
+ * @example
1595
+ * minus(0.3, 0.1) // 返回 "0.2"
1596
+ * minus(10, 1, 2, 3) // 返回 "4" (10-1-2-3)
766
1597
  */
767
1598
  declare const minus: (...args: Decimal.Value[]) => string;
768
1599
  /**
769
1600
  * 精确乘法运算
770
- * 调用:times(arg1,arg2)
771
- * 返回值:arg1乘以arg2的精确结果
1601
+ * 解决JavaScript浮点数精度问题,支持多个数值连续相乘
1602
+ *
1603
+ * @param args - 要相乘的数值列表(可变参数)
1604
+ * @returns 相乘结果字符串
1605
+ *
1606
+ * @example
1607
+ * times(0.1, 0.2) // 返回 "0.02"
1608
+ * times(2, 3, 4) // 返回 "24"
772
1609
  */
773
1610
  declare const times: (...args: Decimal.Value[]) => string;
774
1611
  /**
775
1612
  * 精确除法运算
776
- * 调用:dividedBy(arg1,arg2)
777
- * 返回值:arg1除以arg2的精确结果
1613
+ * 解决JavaScript浮点数精度问题,支持多个数值连续相除
1614
+ *
1615
+ * @param args - 要相除的数值列表(可变参数)
1616
+ * @returns 相除结果字符串
1617
+ *
1618
+ * @example
1619
+ * dividedBy(0.3, 0.1) // 返回 "3"
1620
+ * dividedBy(100, 2, 5) // 返回 "10" (100/2/5)
778
1621
  */
779
1622
  declare const dividedBy: (...args: Decimal.Value[]) => string;
780
1623
  /**
781
1624
  * 查看小数位数(不计算小数点最后末尾的0)
1625
+ * 返回数值中小数点后非零数字的位数
1626
+ *
782
1627
  * @param arg1 - 要检查的数值
783
1628
  * @returns 小数位数
1629
+ *
1630
+ * @example
1631
+ * decimalPlaces(1.23) // 返回 2
1632
+ * decimalPlaces(1.2300) // 返回 2 (末尾的0不计入)
1633
+ * decimalPlaces(1) // 返回 0
784
1634
  */
785
1635
  declare const decimalPlaces: (arg1: Decimal.Value) => number;
786
1636
  /**
787
1637
  * 查看数值总位数(包括整数和小数部分)
1638
+ * 返回数值中所有有效数字的总位数
1639
+ *
788
1640
  * @param arg1 - 要检查的数值
789
1641
  * @returns 总位数
1642
+ *
1643
+ * @example
1644
+ * precision(1.23) // 返回 3
1645
+ * precision(123) // 返回 3
1646
+ * precision(0.01) // 返回 1
790
1647
  */
791
1648
  declare const precision: (arg1: Decimal.Value) => number;
792
1649
  /**
793
1650
  * 取绝对值
1651
+ * 返回数值的绝对值(非负值)
1652
+ *
794
1653
  * @param arg1 - 要处理的数值
795
1654
  * @returns 绝对值字符串
1655
+ *
1656
+ * @example
1657
+ * absVal(-5) // 返回 "5"
1658
+ * absVal(5) // 返回 "5"
1659
+ * absVal(-1.5) // 返回 "1.5"
796
1660
  */
797
1661
  declare const absVal: (arg1: Decimal.Value) => string;
798
1662
  /**
799
1663
  * 数值比较函数
1664
+ * 支持多种比较操作,解决浮点数比较精度问题
1665
+ *
800
1666
  * @param arg1 - 第一个数值
801
1667
  * @param arg2 - 第二个数值
802
1668
  * @param type - 比较类型:>、>=、<、<=、==
803
1669
  * @returns 比较结果布尔值
1670
+ *
1671
+ * @example
1672
+ * compareNum(0.1 + 0.2, 0.3, '==') // 返回 true
1673
+ * compareNum(1, 2, '<') // 返回 true
1674
+ * compareNum(2, 2, '>=') // 返回 true
804
1675
  */
805
1676
  declare const compareNum: (arg1: Decimal.Value, arg2: Decimal.Value, type: string) => boolean;
806
1677
  /**
807
1678
  * 四舍五入处理
1679
+ * 对数值进行指定小数位数的四舍五入处理(解决原始toFixed精度问题)
1680
+ *
808
1681
  * @param num - 要处理的数值
809
1682
  * @param decimals - 保留小数位数,默认为2
810
1683
  * @param fill - 是否补0,默认为true
811
1684
  * @returns 处理后的数字字符串
1685
+ *
1686
+ * @example
1687
+ * toFixed(1.2345) // 返回 "1.23"
1688
+ * toFixed(1.2345, 3) // 返回 "1.235"
1689
+ * toFixed(1.2, 2, true) // 返回 "1.20" (补0)
1690
+ * toFixed(1.2, 2, false) // 返回 "1.2" (不补0)
812
1691
  */
813
1692
  declare const toFixed: (num: Decimal.Value, decimals?: number, fill?: boolean) => string;
814
1693
  /**
815
1694
  * 判断是否为整数
1695
+ * 检查数值是否为整数(没有小数部分)
1696
+ *
816
1697
  * @param num - 要判断的数值
817
1698
  * @returns 是否为整数
1699
+ *
1700
+ * @example
1701
+ * isInteger(1) // 返回 true
1702
+ * isInteger(1.0) // 返回 true
1703
+ * isInteger(1.1) // 返回 false
818
1704
  */
819
1705
  declare const isInteger: (num: Decimal.Value) => boolean;
820
1706
  /**
821
1707
  * 判断是否为负数
1708
+ * 检查数值是否小于0
1709
+ *
822
1710
  * @param num - 要判断的数值
823
1711
  * @returns 是否为负数
1712
+ *
1713
+ * @example
1714
+ * isNegative(-1) // 返回 true
1715
+ * isNegative(0) // 返回 false
1716
+ * isNegative(1) // 返回 false
824
1717
  */
825
1718
  declare const isNegative: (num: Decimal.Value) => boolean;
826
1719
 
827
- /** HTTP 状态码常量:成功 */
828
- declare const OK = 200;
829
- /** HTTP 状态码常量:服务器错误 */
830
- declare const ERROR = 500;
831
- /** HTTP 状态码常量:缺少参数 */
832
- declare const MISSING_PARAMETER = 400;
833
- /** HTTP 状态码常量:未授权 */
834
- declare const UNAUTHORIZED = 401;
835
- /** HTTP 状态码常量:禁止访问 */
836
- declare const FORBIDDEN = 403;
837
- /** HTTP 状态码常量:未找到资源 */
838
- declare const NOT_FOUND = 404;
839
- /** 业务错误码常量:权限拒绝 */
840
- declare const PERMISSION_DENIED = 13001;
841
- /**
842
- * 创建 Axios 请求实例
843
- * @param baseURL - API 基础路径,默认为 '/api'
844
- * @returns 请求实例对象
845
- */
846
- declare function createRequest(baseURL?: string): {
1720
+ /**
1721
+ * 消息提示配置接口
1722
+ */
1723
+ interface Message {
1724
+ /** 消息标题 */
1725
+ title?: string;
1726
+ /** 消息内容 */
1727
+ content: string;
1728
+ /** 显示时长(秒),为0则不自动关闭 */
1729
+ duration?: number;
1730
+ /** 消息类型:成功、错误、警告、信息 */
1731
+ type?: 'success' | 'error' | 'warning' | 'info';
1732
+ /** 关闭回调 */
1733
+ onClose?: () => void;
1734
+ }
1735
+ /**
1736
+ * 缓存消息配置接口
1737
+ * 扩展基础消息接口,增加缓存控制
1738
+ */
1739
+ interface CacheMessage extends Message {
1740
+ /** 是否启用缓存机制 */
1741
+ isCache?: boolean;
1742
+ /** 是否为唯一消息 */
1743
+ isOnly?: boolean;
1744
+ }
1745
+ /**
1746
+ * 导出的缓存消息显示函数
1747
+ * 支持防重复显示、自动关闭、多种显示形式
1748
+ *
1749
+ * 使用示例:
1750
+ * ```typescript
1751
+ * // 基本用法
1752
+ * cachedMessage({ content: '操作成功', type: 'success' })
1753
+ *
1754
+ * // 长消息自动使用通知形式
1755
+ * cachedMessage({ title: '系统通知', content: '这是一条很长的通知内容,将会以notification形式显示...', type: 'info' })
1756
+ *
1757
+ * // 弹窗形式(duration=0)
1758
+ * cachedMessage({ title: '确认操作', content: '确定要删除这项数据吗?', duration: 0, type: 'warning' })
1759
+ *
1760
+ * // 防重复显示
1761
+ * cachedMessage({ content: '请先登录', type: 'error' })
1762
+ * cachedMessage({ content: '请先登录', type: 'error' }) // 此条不会显示
1763
+ *
1764
+ * // 强制重新显示(禁用缓存)
1765
+ * cachedMessage({ content: '请先登录', type: 'error', isCache: false })
1766
+ * ```
1767
+ */
1768
+ declare const cachedMessage: ({ title, content, type, duration, onClose, isCache, isOnly }: CacheMessage) => void;
1769
+
1770
+ /**
1771
+ * 手机号验证规则
1772
+ * 匹配以1开头,第二位为3-9的11位数字
1773
+ */
1774
+ declare const RegMobile: {
1775
+ pattern: RegExp;
1776
+ message: string;
1777
+ };
1778
+ /**
1779
+ * 固定电话验证规则
1780
+ * 匹配区号(0开头2-3位数字) + 连字符 + 7-8位号码
1781
+ */
1782
+ declare const RegFixedTelePhone: {
1783
+ pattern: RegExp;
1784
+ message: string;
1785
+ };
1786
+ /**
1787
+ * 通用电话号码验证规则
1788
+ * 匹配包含数字及常见电话符号(+、-、()、()、 )的1-20位字符串
1789
+ */
1790
+ declare const RegTelePhone: {
1791
+ pattern: RegExp;
1792
+ message: string;
1793
+ };
1794
+ /**
1795
+ * 税号验证规则
1796
+ * 匹配15位、18位或20位的大写字母和数字组合
1797
+ */
1798
+ declare const RegTaxNo: {
1799
+ pattern: RegExp;
1800
+ message: string;
1801
+ };
1802
+ /**
1803
+ * 银行卡号验证规则
1804
+ * 匹配纯数字组成的字符串
1805
+ */
1806
+ declare const RegBankCardNo: {
1807
+ pattern: RegExp;
1808
+ message: string;
1809
+ };
1810
+ /**
1811
+ * 身份证号验证规则
1812
+ * 匹配15位数字、18位数字或17位数字加X/x的格式
1813
+ */
1814
+ declare const RegIdentityCardNo: {
1815
+ pattern: RegExp;
1816
+ message: string;
1817
+ };
1818
+ /**
1819
+ * 数字验证规则
1820
+ * 匹配纯数字组成的字符串
1821
+ */
1822
+ declare const RegNumNo: {
1823
+ pattern: RegExp;
1824
+ message: string;
1825
+ };
1826
+ /**
1827
+ * 短信验证码验证规则
1828
+ * 匹配6位数字
1829
+ */
1830
+ declare const RegSmsCode: {
1831
+ pattern: RegExp;
1832
+ message: string;
1833
+ };
1834
+ /**
1835
+ * 邮箱验证规则
1836
+ * 匹配标准邮箱格式:用户名@域名.顶级域名
1837
+ */
1838
+ declare const RegEmail: {
1839
+ pattern: RegExp;
1840
+ message: string;
1841
+ };
1842
+ /**
1843
+ * 详细地址验证规则
1844
+ * 必须包含地址相关关键词(街、路、村、乡、镇、道、巷、号)
1845
+ */
1846
+ declare const RegDetailAddress: {
1847
+ pattern: RegExp;
1848
+ message: string;
1849
+ };
1850
+ /**
1851
+ * 手机号或固定电话验证器
1852
+ * 验证输入是否符合手机号或固定电话格式
1853
+ *
1854
+ * @param errMessage - 自定义错误消息
1855
+ * @returns Ant Design 表单验证规则对象
1856
+ *
1857
+ * @example
1858
+ * // 基本使用
1859
+ * <Form.Item name="phone" rules={[PhoneOrMobileValidator()]}>
1860
+ * <Input />
1861
+ * </Form.Item>
1862
+ *
1863
+ * @example
1864
+ * // 自定义错误消息
1865
+ * <Form.Item name="phone" rules={[PhoneOrMobileValidator('请输入正确的联系电话')]}>
1866
+ * <Input />
1867
+ * </Form.Item>
1868
+ */
1869
+ declare const PhoneOrMobileValidator: (errMessage?: string) => {
1870
+ validator: (_: RuleObject, value: string) => Promise<void>;
1871
+ };
1872
+ /**
1873
+ * 数值范围验证器
1874
+ * 验证输入数值是否在指定范围内
1875
+ *
1876
+ * @param options - 验证选项
1877
+ * @param options.min - 最小值
1878
+ * @param options.max - 最大值
1879
+ * @param options.equalMin - 是否可等于最小值,默认false
1880
+ * @param options.equalMax - 是否可等于最大值,默认false
1881
+ * @param options.errMessage - 通用错误消息
1882
+ * @param options.maxErrMessage - 最大值错误消息
1883
+ * @param options.minErrMessage - 最小值错误消息
1884
+ * @returns Ant Design 表单验证规则对象
1885
+ *
1886
+ * @example
1887
+ * // 验证年龄在0-150之间
1888
+ * <Form.Item name="age" rules={[ThanNumValidator({ min: 0, max: 150, equalMin: true, equalMax: true })]}>
1889
+ * <InputNumber />
1890
+ * </Form.Item>
1891
+ *
1892
+ * @example
1893
+ * // 验证价格大于0
1894
+ * <Form.Item name="price" rules={[ThanNumValidator({ min: 0, equalMin: false })]}>
1895
+ * <InputNumber />
1896
+ * </Form.Item>
1897
+ */
1898
+ declare const ThanNumValidator: ({ min, max, equalMin, equalMax, errMessage, maxErrMessage, minErrMessage }: {
1899
+ min?: number | string;
1900
+ max?: number | string;
1901
+ equalMin?: boolean;
1902
+ equalMax?: boolean;
1903
+ maxErrMessage?: string;
1904
+ minErrMessage?: string;
1905
+ errMessage?: string;
1906
+ }) => {
1907
+ validator: (_: RuleObject, value: string) => Promise<void>;
1908
+ };
1909
+ /**
1910
+ * 数值位数验证器
1911
+ * 验证输入数值的总位数、整数位数和小数位数是否符合要求
1912
+ *
1913
+ * @param options - 验证选项
1914
+ * @param options.length - 总位数限制
1915
+ * @param options.decimalsLength - 小数位数限制
1916
+ * @param options.integerLength - 整数位数限制
1917
+ * @param options.lengthErrMessage - 总位数错误消息
1918
+ * @param options.decimalsLengthErrMessage - 小数位数错误消息
1919
+ * @param options.integerLengthErrMessage - 整数位数错误消息
1920
+ * @returns Ant Design 表单验证规则对象
1921
+ *
1922
+ * @example
1923
+ * // 验证金额最多8位,其中小数点后2位
1924
+ * <Form.Item name="amount" rules={[ThanNumLengthValidator({ length: 8, decimalsLength: 2 })]}>
1925
+ * <InputNumber />
1926
+ * </Form.Item>
1927
+ *
1928
+ * @example
1929
+ * // 验证百分比最多3位整数,最多2位小数
1930
+ * <Form.Item name="percent" rules={[ThanNumLengthValidator({ integerLength: 3, decimalsLength: 2 })]}>
1931
+ * <InputNumber />
1932
+ * </Form.Item>
1933
+ */
1934
+ declare const ThanNumLengthValidator: ({ length, decimalsLength, integerLength, lengthErrMessage, decimalsLengthErrMessage, integerLengthErrMessage }: {
1935
+ length?: number;
1936
+ decimalsLength?: number;
1937
+ integerLength?: number;
1938
+ lengthErrMessage?: string;
1939
+ decimalsLengthErrMessage?: string;
1940
+ integerLengthErrMessage?: string;
1941
+ }) => {
1942
+ validator: (_: RuleObject, value: string) => Promise<void>;
1943
+ };
1944
+ /**
1945
+ * 多邮箱验证器
1946
+ * 验证逗号分隔的多个邮箱地址是否都符合格式要求
1947
+ *
1948
+ * @param max - 最大邮箱数量
1949
+ * @returns Ant Design 表单验证规则对象
1950
+ *
1951
+ * @example
1952
+ * // 最多允许输入5个邮箱
1953
+ * <Form.Item name="emails" rules={[MultiEmailValidator(5)]}>
1954
+ * <Input placeholder="多个邮箱用逗号分隔" />
1955
+ * </Form.Item>
1956
+ */
1957
+ declare const MultiEmailValidator: (max: number) => {
1958
+ validator: (_: RuleObject, value: string) => Promise<void>;
1959
+ };
1960
+
1961
+ /**
1962
+ * HTTP 错误状态码常量映射
1963
+ * 用于定义常见的 HTTP 错误响应状态码
1964
+ */
1965
+ declare const HttpStatus: {
1966
+ /** 服务器错误 */
1967
+ readonly ERROR: 500;
1968
+ /** 缺少参数或参数错误 */
1969
+ readonly MISSING_PARAMETER: 400;
1970
+ /** 未授权,需要用户验证 */
1971
+ readonly UNAUTHORIZED: 401;
1972
+ /** 禁止访问,服务器理解请求但拒绝执行 */
1973
+ readonly FORBIDDEN: 403;
1974
+ /** 请求的资源未找到 */
1975
+ readonly NOT_FOUND: 404;
1976
+ };
1977
+ /**
1978
+ * 业务码常量映射
1979
+ * 用于定义应用层面的业务逻辑码
1980
+ */
1981
+ declare const BusinessCode: {
1982
+ /** 请求成功 */
1983
+ readonly OK: 200;
1984
+ /** 权限拒绝,没有足够的权限执行操作 */
1985
+ readonly PERMISSION_DENIED: 13001;
1986
+ };
1987
+ /**
1988
+ * 扩展的请求配置接口
1989
+ * 继承自 AxiosRequestConfig,并增加了控制错误提示的选项
1990
+ */
1991
+ interface RequestConfig extends AxiosRequestConfig {
1992
+ showError?: boolean;
1993
+ }
1994
+ /**
1995
+ * 创建一个配置好的 HTTP 请求实例
1996
+ * @param config - 可选的默认配置项
1997
+ * @returns 包含各种 HTTP 方法的对象
1998
+ */
1999
+ declare function createRequest(config?: RequestConfig): {
847
2000
  /**
848
- * GET 请求方法
2001
+ * 返回原始 axios 实例
2002
+ * 可以用于添加拦截器等
2003
+ */
2004
+ instance: axios.AxiosInstance;
2005
+ /**
2006
+ * 发送 GET 请求
849
2007
  * @param url - 请求地址
850
2008
  * @param params - 查询参数
851
- * @param options - Axios 配置选项
852
- * @returns 响应数据
2009
+ * @param options - 额外的请求配置
2010
+ * @returns Promise<any> 响应数据
853
2011
  */
854
- get: (url: string, params?: any, options?: AxiosRequestConfig) => Promise<any>;
2012
+ get: (url: string, params?: any, options?: RequestConfig) => Promise<any>;
855
2013
  /**
856
- * POST 请求方法
2014
+ * 发送 POST 请求
857
2015
  * @param url - 请求地址
858
- * @param data - 请求数据
859
- * @param options - Axios 配置选项
860
- * @returns 响应数据
2016
+ * @param data - 请求体数据
2017
+ * @param options - 额外的请求配置
2018
+ * @returns Promise<any> 响应数据
861
2019
  */
862
- post: (url: string, data?: any, options?: AxiosRequestConfig) => Promise<any>;
2020
+ post: (url: string, data?: any, options?: RequestConfig) => Promise<any>;
863
2021
  /**
864
- * PUT 请求方法
2022
+ * 发送 PUT 请求
865
2023
  * @param url - 请求地址
866
- * @param data - 请求数据
867
- * @param options - Axios 配置选项
868
- * @returns 响应数据
2024
+ * @param data - 请求体数据
2025
+ * @param options - 额外的请求配置
2026
+ * @returns Promise<any> 响应数据
869
2027
  */
870
- put: (url: string, data?: any, options?: AxiosRequestConfig) => Promise<any>;
2028
+ put: (url: string, data?: any, options?: RequestConfig) => Promise<any>;
871
2029
  /**
872
- * DELETE 请求方法
2030
+ * 发送 DELETE 请求
873
2031
  * @param url - 请求地址
874
- * @param data - 请求数据
875
- * @param options - Axios 配置选项
876
- * @returns 响应数据
2032
+ * @param data - 请求体数据
2033
+ * @param options - 额外的请求配置
2034
+ * @returns Promise<any> 响应数据
877
2035
  */
878
- delete: (url: string, data?: any, options?: AxiosRequestConfig) => Promise<any>;
2036
+ delete: (url: string, data?: any, options?: RequestConfig) => Promise<any>;
879
2037
  };
880
2038
 
881
- /** Token 存储键名 */
882
- declare const TOKEN_KEY = "NS-TOKEN";
883
- /**
884
- * 设置访问令牌到 localStorage
885
- * @param accessToken - 访问令牌
886
- */
887
- declare function setToken(accessToken: string): void;
888
2039
  /**
889
- * 从 URL 查询参数中获取 Token
890
- * @returns Token 字符串或空字符串
891
- */
892
- declare function getUrlToken(): string;
893
- /**
894
- * 获取当前有效的访问令牌
895
- * 优先从 URL 参数获取,其次从 localStorage 获取
896
- * @returns Token 字符串或空字符串
897
- */
898
- declare function getToken(): string;
2040
+ * 获取或生成设备唯一标识
2041
+ *
2042
+ * 该函数用于获取设备的唯一标识符,如果本地存储中不存在则会生成一个新的唯一ID
2043
+ * 主要用途:
2044
+ * 1. 跟踪用户设备(不涉及个人隐私)
2045
+ * 2. 设备统计分析
2046
+ * 3. 防止重复提交等场景
2047
+ *
2048
+ * 实现逻辑:
2049
+ * 1. 首先尝试从localStorage中获取已存储的设备ID
2050
+ * 2. 如果存在,则直接返回该设备ID
2051
+ * 3. 如果不存在,则生成一个新的唯一ID
2052
+ * 4. 将新生成的ID存储到localStorage中,以便下次使用
2053
+ * 5. 返回设备ID
2054
+ *
2055
+ * @param DEVICEID_KEY - 设备ID在localStorage中的存储键名
2056
+ * @returns 设备唯一标识字符串
2057
+ *
2058
+ * @example
2059
+ * // 使用自定义键名获取设备ID
2060
+ * const deviceId = getDeviceId('MY-APP-DEVICE-ID')
2061
+ *
2062
+ * 注意事项:
2063
+ * 1. 设备ID存储在localStorage中,清除浏览器数据会导致重新生成
2064
+ * 2. 不同域名下会有不同的设备ID
2065
+ * 3. 该ID不包含任何个人身份信息,仅用于设备识别
2066
+ */
2067
+ declare function getDeviceId(DEVICEID_KEY: string): string;
2068
+ interface SecureManagerProps {
2069
+ /** 存储键名 */
2070
+ key: string;
2071
+ /** AES加密密钥;(不传则明文存储) */
2072
+ aesKey?: string;
2073
+ /** 存储类型,默认为localStorage */
2074
+ storage?: Storage;
2075
+ }
899
2076
  /**
900
- * 清除 localStorage 中的 Token
901
- */
902
- declare function clearToken(): void;
2077
+ * 创建安全存储管理器
2078
+ *
2079
+ * 提供统一的数据存储接口,支持加密和明文两种存储模式
2080
+ *
2081
+ * 特性:
2082
+ * 1. 灵活存储:支持sessionStorage和localStorage
2083
+ * 2. 可选加密:通过aesKey参数控制是否加密存储
2084
+ * 3. 自动处理:根据是否提供aesKey自动切换加密/明文模式
2085
+ * 4. 类型安全:支持泛型,可指定存储数据的类型
2086
+ *
2087
+ * @param options 安全存储配置选项
2088
+ * @returns 安全存储管理器对象
2089
+ *
2090
+ * @example
2091
+ * // 加密存储(提供aesKey时自动启用加密)
2092
+ * const secureManager = createSecureManager({
2093
+ * key: 'user-profile',
2094
+ * aesKey: 'my-secret-key'
2095
+ * })
2096
+ * secureManager.set({ name: 'John', id: 123 })
2097
+ *
2098
+ * @example
2099
+ * // 明文存储(不提供aesKey时使用明文存储)
2100
+ * const plainManager = createSecureManager({
2101
+ * key: 'app-settings'
2102
+ * })
2103
+ * plainManager.set({ theme: 'dark', lang: 'en' })
2104
+ *
2105
+ * @example
2106
+ * // 自定义存储类型
2107
+ * const localManager = createSecureManager({
2108
+ * key: 'local-data',
2109
+ * aesKey: 'secret-key',
2110
+ * storage: localStorage
2111
+ * })
2112
+ */
2113
+ declare function createSecureManager<T>({ key, storage, aesKey }: SecureManagerProps): {
2114
+ set: (data: T) => void;
2115
+ get: () => T | null;
2116
+ clear: () => void;
2117
+ };
2118
+ interface TokenManagerProps {
2119
+ /** token在存储中的键名 */
2120
+ key: string;
2121
+ /** 存储类型,支持localStorage和sessionStorage,默认为localStorage */
2122
+ storage?: Storage;
2123
+ }
903
2124
  /**
904
- * 获取登录页面路径
905
- * @returns 登录路径,默认为 '/sign-in'
906
- */
907
- declare function getSignPath(): string;
908
-
909
- /** 项目主色调 */
910
- declare const LgPrimaryColor: string;
911
- /** Ant Design 主题配置 */
912
- declare const themeConfig: ThemeConfig;
2125
+ * 创建token管理器
2126
+ *
2127
+ * 提供统一的token管理功能,支持从URL参数或存储中获取、设置和清除token
2128
+ *
2129
+ * 设计特点:
2130
+ * 1. 自动同步:从URL获取token时会自动同步到存储中
2131
+ * 2. 灵活存储:支持localStorage和sessionStorage
2132
+ * 3. 优先级获取:优先使用URL参数中的token
2133
+ * 4. 简洁API:提供完整的token管理操作
2134
+ *
2135
+ * @param options token管理器配置选项
2136
+ * @returns token管理器对象
2137
+ *
2138
+ * @example
2139
+ * // 创建基于localStorage的token管理器
2140
+ * const tokenManager = createTokenManager({
2141
+ * key: 'ACCESS_TOKEN'
2142
+ * })
2143
+ *
2144
+ * // 从URL参数或localStorage获取token
2145
+ * const token = tokenManager.get()
2146
+ *
2147
+ * // 设置token
2148
+ * tokenManager.set('new-token-value')
2149
+ *
2150
+ * // 清除token
2151
+ * tokenManager.clear()
2152
+ *
2153
+ * @example
2154
+ * // 创建基于sessionStorage的token管理器
2155
+ * const tokenManager = createTokenManager({
2156
+ * key: 'SESSION_TOKEN',
2157
+ * storage: sessionStorage
2158
+ * })
2159
+ */
2160
+ declare function createTokenManager({ key, storage }: TokenManagerProps): {
2161
+ set: (data: string) => void;
2162
+ get: () => string;
2163
+ clear: () => void;
2164
+ };
913
2165
 
914
- export { _default$b as AudioPlayer, type AudioPlayerProps, type ComponentMapType, DateFormatType, DateFormatType2, ERROR, FORBIDDEN, _default$a as FileIcon, type FileIconProps, _default$9 as FilePreview, _default$8 as FilePreviewDrawer, type FilePreviewDrawerProps, type FilePreviewProps, _default$4 as Iframe, type IframeProps, _default$3 as LazyComponent, type LazyComponentProps, LgPrimaryColor, MISSING_PARAMETER, _default$2 as MarkdownEditor, type MarkdownEditorProps, _default$7 as MarkdownPreview, type MarkdownPreviewProps, NOT_FOUND, type NsSetIntervalReturnType, OK, PERMISSION_DENIED, type Params, _default$6 as PdfPreview, type PdfPreviewProps, type RenderControl, type RenderControlObj, _default$1 as RenderMarkdown, type RenderMarkdownProps, RenderWrapper, type RenderWrapperProps, TOKEN_KEY, UNAUTHORIZED, _default as UserAvatar, type UserAvatarProps, _default$5 as VideoPlayer, type VideoPlayerProps, absVal, addUrlLastSlash, arrToObj, buildUrlParams, calculate, clearCurrentUser, clearToken, compareNum, copyText, createRequest, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, formatDate, formatNumberWithCommas, genNonDuplicateID, generateRandomNumbers, getCurrentUser, getDeviceId, getEndOfTimestamp, getFileName, getFileSuffixName, getSignPath, getStartOfTimestamp, getTimestamp, getToken, getUrlMainSource, getUrlToken, getWebSocketUrl, is, isArray, isBlob, isBoolean, isClient, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isLocalhost, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isRegExp, isServer, isString, isUnDef, isWindow, minus, nsSetInterval, objToOptions, plus, precision, propsMerge, setCurrentUser, setToken, shouldRender, textAreaView, themeConfig, times, toFixed, transform, transforms, useCreateValtioContext, useDebounce, useDeepEffect, useIframeRelayBridge, useRefState, useSyncInput, useThrottle, useWebSocket };
2166
+ export { _default$m as AudioPlayer, type AudioPlayerProps, BusinessCode, type CacheMessage, type ComponentMapType, DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, DEFAULT_YEAR_MONTH_DAY_FORMAT, DEFAULT_YEAR_MONTH_FORMAT, _default$l as FileIcon, type FileIconProps, _default$k as FilePreview, _default$j as FilePreviewDrawer, type FilePreviewDrawerProps, type FilePreviewProps, HttpStatus, _default$f as Iframe, type IframeProps, _default$e as LazyComponent, type LazyComponentProps, _default$d as MarkdownEditor, type MarkdownEditorProps, _default$i as MarkdownPreview, type MarkdownPreviewProps, MultiEmailValidator, _default$h as PdfPreview, type PdfPreviewProps, PhoneOrMobileValidator, RegBankCardNo, RegDetailAddress, RegEmail, RegFixedTelePhone, RegIdentityCardNo, RegMobile, RegNumNo, RegSmsCode, RegTaxNo, RegTelePhone, type RenderControl, _default$c as RenderMarkdown, type RenderMarkdownProps, _default$b as RenderWrapper, type RenderWrapperProps, type RequestConfig, type SecureManagerProps, ThanNumLengthValidator, ThanNumValidator, type TokenManagerProps, _default$a as UserAvatar, type UserAvatarProps, _default$g as VideoPlayer, type VideoPlayerProps, type WebSocketProps, type WebSocketType, absVal, addUrlLastSlash, aesDecrypt, aesEncrypt, arrToObj, buildUrlParams, cachedMessage, calculate, compareNum, convertCurrency, convertNewlineToBr, copyText, createRequest, createSecureManager, createTokenManager, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, executeScript, formatDate, formatNumberWithCommas, genNonDuplicateID, generateRandomNumbers, getAllUrlParams, getDeviceId, getEndOfTimestamp, getFileName, getFileSuffixName, getRowSpanCount, getStartOfTimestamp, getTimestamp, getWebSocketUrl, importThirdPartyFile, is, isArray, isBlob, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isJson, isLocalhost, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isReferenceType, isRegExp, isScriptSafe, isSet, isString, isUnDef, isWindow, minus, objToOptions, plus, precision, processItemList, propsMerge, setInterval, setUrlMainSource, shouldRender, times, toFixed, transform, transforms, _default$8 as useAutoRefresh, _default$7 as useCountDown, _default$6 as useCreateValtioContext, _default$5 as useDebounce, _default$4 as useDeepEffect, _default$9 as useIframeRelayBridge, _default$3 as useRefState, _default$2 as useSyncInput, _default$1 as useThrottle, _default as useWebSocket };