a2bei4-utils 1.0.3 → 1.0.5

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/types/date.d.ts CHANGED
@@ -19,60 +19,119 @@ declare function toDate(val: any): Date | null;
19
19
  */
20
20
  declare function randomDateInRange(date1: Date, date2: Date): Date;
21
21
  /**
22
- * 计算两个时间之间的剩余/已过时长(天-时-分-秒),返回带补零的展示对象。
23
- *
24
- * @param {string|number|Date} originalTime - 原始时间(可转 Date 的任意值)
25
- * @param {Date} [currentTime=new Date()] - 基准时间,默认当前
26
- * @returns {{days:number,hours:string,minutes:string,seconds:string}}
22
+ * 时间持续对象(完整版本,包含年月日时分秒毫秒)
23
+ * @typedef {Object} DurationObject
24
+ * @property {number} years - 年数
25
+ * @property {number} months - 月数(0-11)
26
+ * @property {number} days - 天数(0-29,取决于 monthDays)
27
+ * @property {number} hours - 小时数(0-23)
28
+ * @property {number} minutes - 分钟数(0-59)
29
+ * @property {number} seconds - 秒数(0-59)
30
+ * @property {number} milliseconds - 毫秒数(0-999)
27
31
  */
28
- declare function calcTimeDifference(originalTime: string | number | Date, currentTime?: Date): {
29
- days: number;
30
- hours: string;
31
- minutes: string;
32
- seconds: string;
33
- };
34
32
  /**
35
- * 将总秒数格式化成人类可读的时间段文本。
36
- * 固定进制:1 年=365 天,1 月=30 天。
37
- *
38
- * @param {number} totalSeconds - 非负总秒数
39
- * @param {object} [options] - 格式化选项
40
- * @param {Partial<{year:string,month:string,day:string,hour:string,minute:string,second:string}>} [options.labels] - 各单位的自定义文本
41
- * @param {('year'|'month'|'day'|'hour'|'minute'|'second')} [options.maxUnit] - 最大输出单位
42
- * @param {('year'|'month'|'day'|'hour'|'minute'|'second')} [options.minUnit] - 最小输出单位
43
- * @param {boolean} [options.showZero] - 是否强制显示 0 秒
44
- * @returns {string} 拼接后的时长文本,如“1天 02小时 30分钟”
45
- * @throws {TypeError} 当 totalSeconds 为非数字或负数时抛出
46
- */
47
- declare function formatDuration(totalSeconds: number, options?: {
48
- labels?: Partial<{
49
- year: string;
50
- month: string;
51
- day: string;
52
- hour: string;
53
- minute: string;
54
- second: string;
55
- }> | undefined;
56
- maxUnit?: "year" | "month" | "day" | "hour" | "minute" | "second" | undefined;
57
- minUnit?: "year" | "month" | "day" | "hour" | "minute" | "second" | undefined;
58
- showZero?: boolean | undefined;
59
- }): string;
33
+ * 时间持续对象(最大单位为天)
34
+ * @typedef {Object} DurationMaxDayObject
35
+ * @property {number} days - 天数
36
+ * @property {number} hours - 小时数(0-23)
37
+ * @property {number} minutes - 分钟数(0-59)
38
+ * @property {number} seconds - 秒数(0-59)
39
+ * @property {number} milliseconds - 毫秒数(0-999)
40
+ */
41
+ /**
42
+ * 时间持续对象(最大单位为小时)
43
+ * @typedef {Object} DurationMaxHourObject
44
+ * @property {number} hours - 小时数
45
+ * @property {number} minutes - 分钟数(0-59)
46
+ * @property {number} seconds - 秒数(0-59)
47
+ * @property {number} milliseconds - 毫秒数(0-999)
48
+ */
60
49
  /**
61
- * 快捷调用 {@link formatDuration},最大单位到“天”。
50
+ * 将毫秒转换为时间持续对象。
62
51
  *
63
- * @param {number} totalSeconds
64
- * @param {Omit<Parameters<typeof formatDuration>[1],'maxUnit'>} [options]
65
- * @returns {string}
52
+ * @param {number} milliseconds - 毫秒数(非负整数)
53
+ * @param {Object} [options] - 选项对象。
54
+ * @param {number} [options.yearDays=365] - 一年的天数。
55
+ * @param {number} [options.monthDays=30] - 一月的天数。
56
+ * @returns {DurationObject} 时间持续对象
57
+ * @throws {TypeError} 当 milliseconds 不是有效数字
58
+ * @throws {RangeError} 当 milliseconds 为负数
59
+ * @throws {RangeError} 当 yearDays 或 monthDays 不是正整数
60
+ *
61
+ * @example
62
+ * // 基本用法
63
+ * millisecond2Duration(42070000500);
64
+ * // 返回: { years: 1, months: 4, days: 1, hours: 22, minutes: 6, seconds: 40, milliseconds: 500 }
65
+ */
66
+ declare function millisecond2Duration(milliseconds: number, options?: {
67
+ yearDays?: number | undefined;
68
+ monthDays?: number | undefined;
69
+ }): DurationObject;
70
+ /**
71
+ * 将毫秒转换为时间持续对象(最大单位为天)。
72
+ * @param {number} milliseconds - 毫秒数(非负整数)
73
+ * @returns {DurationMaxDayObject} 包含天、小时、分钟、秒、毫秒的时间持续对象
74
+ * @throws {TypeError} 当 milliseconds 不是有效数字时抛出
75
+ * @throws {RangeError} 当 milliseconds 为负数时抛出
76
+ * @example
77
+ * // 返回 { days: 486, hours: 22, minutes: 6, seconds: 40, milliseconds: 500 }
78
+ * millisecond2DurationMaxDay(42070000500);
66
79
  */
67
- declare function formatDurationMaxDay(totalSeconds: number, options?: Omit<Parameters<typeof formatDuration>[1], "maxUnit">): string;
80
+ declare function millisecond2DurationMaxDay(milliseconds: number): DurationMaxDayObject;
68
81
  /**
69
- * 快捷调用 {@link formatDuration},最大单位到“小时”。
82
+ * 将毫秒转换为时间持续对象(最大单位为小时)。
83
+ * @param {number} milliseconds - 毫秒数(非负整数)
84
+ * @returns {DurationMaxHourObject} 包含小时、分钟、秒、毫秒的时间持续对象
85
+ * @throws {TypeError} 当 milliseconds 不是有效数字时抛出
86
+ * @throws {RangeError} 当 milliseconds 为负数时抛出
87
+ * @example
88
+ * // 返回 { hours: 11686, minutes: 6, seconds: 40, milliseconds: 500 }
89
+ * millisecond2DurationMaxHour(42070000500);
90
+ */
91
+ declare function millisecond2DurationMaxHour(milliseconds: number): DurationMaxHourObject;
92
+ /**
93
+ * 将秒转换为时间持续对象。
94
+ *
95
+ * @param {number} seconds - 秒数(非负整数)
96
+ * @param {Object} [options] - 选项对象。
97
+ * @param {number} [options.yearDays=365] - 一年的天数。
98
+ * @param {number} [options.monthDays=30] - 一月的天数。
99
+ * @returns {DurationObject} 时间持续对象
100
+ * @throws {TypeError} 当 seconds 不是有效数字
101
+ * @throws {RangeError} 当 seconds 为负数
102
+ * @throws {RangeError} 当 yearDays 或 monthDays 不是正整数
70
103
  *
71
- * @param {number} totalSeconds
72
- * @param {Omit<Parameters<typeof formatDuration>[1],'maxUnit'>} [options]
73
- * @returns {string}
104
+ * @example
105
+ * // 基本用法
106
+ * second2Duration(42070000.5);
107
+ * // 返回: { years: 1, months: 4, days: 1, hours: 22, minutes: 6, seconds: 40, milliseconds: 500 }
74
108
  */
75
- declare function formatDurationMaxHour(totalSeconds: number, options?: Omit<Parameters<typeof formatDuration>[1], "maxUnit">): string;
109
+ declare function second2Duration(seconds: number, options?: {
110
+ yearDays?: number | undefined;
111
+ monthDays?: number | undefined;
112
+ }): DurationObject;
113
+ /**
114
+ * 将秒转换为时间持续对象(最大单位为天)。
115
+ * @param {number} seconds - 秒数(非负整数)
116
+ * @returns {DurationMaxDayObject} 包含天、小时、分钟、秒、毫秒的时间持续对象
117
+ * @throws {TypeError} 当 seconds 不是有效数字时抛出
118
+ * @throws {RangeError} 当 seconds 为负数时抛出
119
+ * @example
120
+ * // 返回 { days: 486, hours: 22, minutes: 6, seconds: 40, milliseconds: 500 }
121
+ * second2DurationMaxDay(42070000.5);
122
+ */
123
+ declare function second2DurationMaxDay(seconds: number): DurationMaxDayObject;
124
+ /**
125
+ * 将秒转换为时间持续对象(最大单位为小时)。
126
+ * @param {number} seconds - 秒数(非负整数)
127
+ * @returns {DurationMaxHourObject} 包含小时、分钟、秒、毫秒的时间持续对象
128
+ * @throws {TypeError} 当 seconds 不是有效数字时抛出
129
+ * @throws {RangeError} 当 seconds 为负数时抛出
130
+ * @example
131
+ * // 返回 { hours: 11686, minutes: 6, seconds: 40, milliseconds: 500 }
132
+ * second2DurationMaxHour(42070000.5);
133
+ */
134
+ declare function second2DurationMaxHour(seconds: number): DurationMaxHourObject;
76
135
  /**
77
136
  * 根据小时数返回对应的时间段名称。
78
137
  *
@@ -132,5 +191,85 @@ declare function formatTimeForLocale(timestamp: number, locales?: {
132
191
  } | undefined;
133
192
  weekDays?: string[] | undefined;
134
193
  }): string;
194
+ /**
195
+ * 时间持续对象(完整版本,包含年月日时分秒毫秒)
196
+ */
197
+ type DurationObject = {
198
+ /**
199
+ * - 年数
200
+ */
201
+ years: number;
202
+ /**
203
+ * - 月数(0-11)
204
+ */
205
+ months: number;
206
+ /**
207
+ * - 天数(0-29,取决于 monthDays)
208
+ */
209
+ days: number;
210
+ /**
211
+ * - 小时数(0-23)
212
+ */
213
+ hours: number;
214
+ /**
215
+ * - 分钟数(0-59)
216
+ */
217
+ minutes: number;
218
+ /**
219
+ * - 秒数(0-59)
220
+ */
221
+ seconds: number;
222
+ /**
223
+ * - 毫秒数(0-999)
224
+ */
225
+ milliseconds: number;
226
+ };
227
+ /**
228
+ * 时间持续对象(最大单位为天)
229
+ */
230
+ type DurationMaxDayObject = {
231
+ /**
232
+ * - 天数
233
+ */
234
+ days: number;
235
+ /**
236
+ * - 小时数(0-23)
237
+ */
238
+ hours: number;
239
+ /**
240
+ * - 分钟数(0-59)
241
+ */
242
+ minutes: number;
243
+ /**
244
+ * - 秒数(0-59)
245
+ */
246
+ seconds: number;
247
+ /**
248
+ * - 毫秒数(0-999)
249
+ */
250
+ milliseconds: number;
251
+ };
252
+ /**
253
+ * 时间持续对象(最大单位为小时)
254
+ */
255
+ type DurationMaxHourObject = {
256
+ /**
257
+ * - 小时数
258
+ */
259
+ hours: number;
260
+ /**
261
+ * - 分钟数(0-59)
262
+ */
263
+ minutes: number;
264
+ /**
265
+ * - 秒数(0-59)
266
+ */
267
+ seconds: number;
268
+ /**
269
+ * - 毫秒数(0-999)
270
+ */
271
+ milliseconds: number;
272
+ };
135
273
 
136
- export { calcTimeDifference, formatDuration, formatDurationMaxDay, formatDurationMaxHour, formatTimeForLocale, getTimePeriodName, randomDateInRange, toDate };
274
+ export { formatTimeForLocale, getTimePeriodName, millisecond2Duration, millisecond2DurationMaxDay, millisecond2DurationMaxHour, randomDateInRange, second2Duration, second2DurationMaxDay, second2DurationMaxHour, toDate };
275
+ export type { DurationMaxDayObject, DurationMaxHourObject, DurationObject };
package/types/index.d.ts CHANGED
@@ -1,3 +1,64 @@
1
+ /**
2
+ * 处理数据库菜单项,生成 UI 菜单树和路由配置。
3
+ *
4
+ * @param {Array<Object>} menuItems - 原始菜单项数组,树形结构
5
+ * @param {Object} [options] - 配置选项
6
+ * @param {string} [options.idKey='id'] - 数据源 ID 键名
7
+ * @param {string} [options.codeKey='code'] - 数据源编码键名, 用于拼接路由名称和路由路径
8
+ * @param {string} [options.labelKey='text'] - 数据源标签键名
9
+ * @param {string} [options.childrenKey='children'] - 数据源子节点键名
10
+ * @param {string} [options.extendKey='extend'] - 数据源扩展对象键名
11
+ * @param {string} [options.menuIdKey='key'] - 输出菜单 ID 键名
12
+ * @param {string} [options.menuLabelKey='label'] - 输出菜单标签键名
13
+ * @param {string} [options.menuChildrenKey='children'] - 输出菜单子节点键名
14
+ * @param {string} [options.menuExtendKey='extend'] - 输出菜单扩展对象键名
15
+ * @param {string} [options.routeNameKey='name'] - 路由名称键名
16
+ * @param {string} [options.routePathKey='path'] - 路由路径键名
17
+ * @param {string} [options.routeMetaKey='meta'] - 路由元数据键名
18
+ * @param {Function} [options.handleNodeItem] - 节点处理钩子,参数:(nodeSimple) => void
19
+ * @param {Function} [options.handleMenuItem] - 菜单项处理钩子,参数:(uiMenuItem, nodeSimple) => void
20
+ * @param {Function} [options.handleRouteItem] - 路由项处理钩子,参数:(routeItem, nodeSimple) => void
21
+ *
22
+ * @returns {Object} 处理结果
23
+ * @returns {Array<Object>} returns.uiMenuItems - UI 菜单树形结构数组
24
+ * @returns {Array<Object>} returns.routeItems - 扁平化路由配置数组
25
+ * @returns {Map<string, Object>} returns.nodeMap - 节点 ID 到节点数据的映射表
26
+ *
27
+ * @example
28
+ * const menuItems = [
29
+ * { id: '1', code: 'system', text: '系统管理', children: [
30
+ * { id: '1-1', code: 'user', text: '用户管理' }
31
+ * ]}
32
+ * ];
33
+ *
34
+ * const result = handleDbMenuItems(menuItems, {
35
+ * handleRouteItem: (route, node) => {
36
+ * route.component = () => import(`./views/${node.code}.vue`);
37
+ * }
38
+ * });
39
+ *
40
+ * // result.uiMenuItems: [{ key: '1', label: '系统管理', children: [...] }]
41
+ * // result.routeItems: [{ name: 'system.user', path: '/system/user', meta: { id: '1-1' } }]
42
+ * // result.nodeMap: Map { '1' => {...}, '1-1' => {...} }
43
+ */
44
+ declare function handleDbMenuItems(menuItems: Array<Object>, options?: {
45
+ idKey?: string | undefined;
46
+ codeKey?: string | undefined;
47
+ labelKey?: string | undefined;
48
+ childrenKey?: string | undefined;
49
+ extendKey?: string | undefined;
50
+ menuIdKey?: string | undefined;
51
+ menuLabelKey?: string | undefined;
52
+ menuChildrenKey?: string | undefined;
53
+ menuExtendKey?: string | undefined;
54
+ routeNameKey?: string | undefined;
55
+ routePathKey?: string | undefined;
56
+ routeMetaKey?: string | undefined;
57
+ handleNodeItem?: Function | undefined;
58
+ handleMenuItem?: Function | undefined;
59
+ handleRouteItem?: Function | undefined;
60
+ }): Object;
61
+
1
62
  /**
2
63
  * 基于 `setTimeout` 的“间隔循环”定时器。
3
64
  * 每次任务执行完成后才计算下一次间隔,避免任务堆积。
@@ -464,60 +525,119 @@ declare function toDate(val: any): Date | null;
464
525
  */
465
526
  declare function randomDateInRange(date1: Date, date2: Date): Date;
466
527
  /**
467
- * 计算两个时间之间的剩余/已过时长(天-时-分-秒),返回带补零的展示对象。
528
+ * 时间持续对象(完整版本,包含年月日时分秒毫秒)
529
+ * @typedef {Object} DurationObject
530
+ * @property {number} years - 年数
531
+ * @property {number} months - 月数(0-11)
532
+ * @property {number} days - 天数(0-29,取决于 monthDays)
533
+ * @property {number} hours - 小时数(0-23)
534
+ * @property {number} minutes - 分钟数(0-59)
535
+ * @property {number} seconds - 秒数(0-59)
536
+ * @property {number} milliseconds - 毫秒数(0-999)
537
+ */
538
+ /**
539
+ * 时间持续对象(最大单位为天)
540
+ * @typedef {Object} DurationMaxDayObject
541
+ * @property {number} days - 天数
542
+ * @property {number} hours - 小时数(0-23)
543
+ * @property {number} minutes - 分钟数(0-59)
544
+ * @property {number} seconds - 秒数(0-59)
545
+ * @property {number} milliseconds - 毫秒数(0-999)
546
+ */
547
+ /**
548
+ * 时间持续对象(最大单位为小时)
549
+ * @typedef {Object} DurationMaxHourObject
550
+ * @property {number} hours - 小时数
551
+ * @property {number} minutes - 分钟数(0-59)
552
+ * @property {number} seconds - 秒数(0-59)
553
+ * @property {number} milliseconds - 毫秒数(0-999)
554
+ */
555
+ /**
556
+ * 将毫秒转换为时间持续对象。
557
+ *
558
+ * @param {number} milliseconds - 毫秒数(非负整数)
559
+ * @param {Object} [options] - 选项对象。
560
+ * @param {number} [options.yearDays=365] - 一年的天数。
561
+ * @param {number} [options.monthDays=30] - 一月的天数。
562
+ * @returns {DurationObject} 时间持续对象
563
+ * @throws {TypeError} 当 milliseconds 不是有效数字
564
+ * @throws {RangeError} 当 milliseconds 为负数
565
+ * @throws {RangeError} 当 yearDays 或 monthDays 不是正整数
468
566
  *
469
- * @param {string|number|Date} originalTime - 原始时间(可转 Date 的任意值)
470
- * @param {Date} [currentTime=new Date()] - 基准时间,默认当前
471
- * @returns {{days:number,hours:string,minutes:string,seconds:string}}
567
+ * @example
568
+ * // 基本用法
569
+ * millisecond2Duration(42070000500);
570
+ * // 返回: { years: 1, months: 4, days: 1, hours: 22, minutes: 6, seconds: 40, milliseconds: 500 }
571
+ */
572
+ declare function millisecond2Duration(milliseconds: number, options?: {
573
+ yearDays?: number | undefined;
574
+ monthDays?: number | undefined;
575
+ }): DurationObject;
576
+ /**
577
+ * 将毫秒转换为时间持续对象(最大单位为天)。
578
+ * @param {number} milliseconds - 毫秒数(非负整数)
579
+ * @returns {DurationMaxDayObject} 包含天、小时、分钟、秒、毫秒的时间持续对象
580
+ * @throws {TypeError} 当 milliseconds 不是有效数字时抛出
581
+ * @throws {RangeError} 当 milliseconds 为负数时抛出
582
+ * @example
583
+ * // 返回 { days: 486, hours: 22, minutes: 6, seconds: 40, milliseconds: 500 }
584
+ * millisecond2DurationMaxDay(42070000500);
472
585
  */
473
- declare function calcTimeDifference(originalTime: string | number | Date, currentTime?: Date): {
474
- days: number;
475
- hours: string;
476
- minutes: string;
477
- seconds: string;
478
- };
586
+ declare function millisecond2DurationMaxDay(milliseconds: number): DurationMaxDayObject;
479
587
  /**
480
- * 将总秒数格式化成人类可读的时间段文本。
481
- * 固定进制:1 年=365 天,1 月=30 天。
482
- *
483
- * @param {number} totalSeconds - 非负总秒数
484
- * @param {object} [options] - 格式化选项
485
- * @param {Partial<{year:string,month:string,day:string,hour:string,minute:string,second:string}>} [options.labels] - 各单位的自定义文本
486
- * @param {('year'|'month'|'day'|'hour'|'minute'|'second')} [options.maxUnit] - 最大输出单位
487
- * @param {('year'|'month'|'day'|'hour'|'minute'|'second')} [options.minUnit] - 最小输出单位
488
- * @param {boolean} [options.showZero] - 是否强制显示 0 秒
489
- * @returns {string} 拼接后的时长文本,如“1天 02小时 30分钟”
490
- * @throws {TypeError} 当 totalSeconds 为非数字或负数时抛出
491
- */
492
- declare function formatDuration(totalSeconds: number, options?: {
493
- labels?: Partial<{
494
- year: string;
495
- month: string;
496
- day: string;
497
- hour: string;
498
- minute: string;
499
- second: string;
500
- }> | undefined;
501
- maxUnit?: "year" | "month" | "day" | "hour" | "minute" | "second" | undefined;
502
- minUnit?: "year" | "month" | "day" | "hour" | "minute" | "second" | undefined;
503
- showZero?: boolean | undefined;
504
- }): string;
588
+ * 将毫秒转换为时间持续对象(最大单位为小时)。
589
+ * @param {number} milliseconds - 毫秒数(非负整数)
590
+ * @returns {DurationMaxHourObject} 包含小时、分钟、秒、毫秒的时间持续对象
591
+ * @throws {TypeError} milliseconds 不是有效数字时抛出
592
+ * @throws {RangeError} milliseconds 为负数时抛出
593
+ * @example
594
+ * // 返回 { hours: 11686, minutes: 6, seconds: 40, milliseconds: 500 }
595
+ * millisecond2DurationMaxHour(42070000500);
596
+ */
597
+ declare function millisecond2DurationMaxHour(milliseconds: number): DurationMaxHourObject;
505
598
  /**
506
- * 快捷调用 {@link formatDuration},最大单位到“天”。
599
+ * 将秒转换为时间持续对象。
507
600
  *
508
- * @param {number} totalSeconds
509
- * @param {Omit<Parameters<typeof formatDuration>[1],'maxUnit'>} [options]
510
- * @returns {string}
601
+ * @param {number} seconds - 秒数(非负整数)
602
+ * @param {Object} [options] - 选项对象。
603
+ * @param {number} [options.yearDays=365] - 一年的天数。
604
+ * @param {number} [options.monthDays=30] - 一月的天数。
605
+ * @returns {DurationObject} 时间持续对象
606
+ * @throws {TypeError} 当 seconds 不是有效数字
607
+ * @throws {RangeError} 当 seconds 为负数
608
+ * @throws {RangeError} 当 yearDays 或 monthDays 不是正整数
609
+ *
610
+ * @example
611
+ * // 基本用法
612
+ * second2Duration(42070000.5);
613
+ * // 返回: { years: 1, months: 4, days: 1, hours: 22, minutes: 6, seconds: 40, milliseconds: 500 }
614
+ */
615
+ declare function second2Duration(seconds: number, options?: {
616
+ yearDays?: number | undefined;
617
+ monthDays?: number | undefined;
618
+ }): DurationObject;
619
+ /**
620
+ * 将秒转换为时间持续对象(最大单位为天)。
621
+ * @param {number} seconds - 秒数(非负整数)
622
+ * @returns {DurationMaxDayObject} 包含天、小时、分钟、秒、毫秒的时间持续对象
623
+ * @throws {TypeError} 当 seconds 不是有效数字时抛出
624
+ * @throws {RangeError} 当 seconds 为负数时抛出
625
+ * @example
626
+ * // 返回 { days: 486, hours: 22, minutes: 6, seconds: 40, milliseconds: 500 }
627
+ * second2DurationMaxDay(42070000.5);
511
628
  */
512
- declare function formatDurationMaxDay(totalSeconds: number, options?: Omit<Parameters<typeof formatDuration>[1], "maxUnit">): string;
629
+ declare function second2DurationMaxDay(seconds: number): DurationMaxDayObject;
513
630
  /**
514
- * 快捷调用 {@link formatDuration},最大单位到“小时”。
515
- *
516
- * @param {number} totalSeconds
517
- * @param {Omit<Parameters<typeof formatDuration>[1],'maxUnit'>} [options]
518
- * @returns {string}
631
+ * 将秒转换为时间持续对象(最大单位为小时)。
632
+ * @param {number} seconds - 秒数(非负整数)
633
+ * @returns {DurationMaxHourObject} 包含小时、分钟、秒、毫秒的时间持续对象
634
+ * @throws {TypeError} 当 seconds 不是有效数字时抛出
635
+ * @throws {RangeError} 当 seconds 为负数时抛出
636
+ * @example
637
+ * // 返回 { hours: 11686, minutes: 6, seconds: 40, milliseconds: 500 }
638
+ * second2DurationMaxHour(42070000.5);
519
639
  */
520
- declare function formatDurationMaxHour(totalSeconds: number, options?: Omit<Parameters<typeof formatDuration>[1], "maxUnit">): string;
640
+ declare function second2DurationMaxHour(seconds: number): DurationMaxHourObject;
521
641
  /**
522
642
  * 根据小时数返回对应的时间段名称。
523
643
  *
@@ -577,6 +697,85 @@ declare function formatTimeForLocale(timestamp: number, locales?: {
577
697
  } | undefined;
578
698
  weekDays?: string[] | undefined;
579
699
  }): string;
700
+ /**
701
+ * 时间持续对象(完整版本,包含年月日时分秒毫秒)
702
+ */
703
+ type DurationObject = {
704
+ /**
705
+ * - 年数
706
+ */
707
+ years: number;
708
+ /**
709
+ * - 月数(0-11)
710
+ */
711
+ months: number;
712
+ /**
713
+ * - 天数(0-29,取决于 monthDays)
714
+ */
715
+ days: number;
716
+ /**
717
+ * - 小时数(0-23)
718
+ */
719
+ hours: number;
720
+ /**
721
+ * - 分钟数(0-59)
722
+ */
723
+ minutes: number;
724
+ /**
725
+ * - 秒数(0-59)
726
+ */
727
+ seconds: number;
728
+ /**
729
+ * - 毫秒数(0-999)
730
+ */
731
+ milliseconds: number;
732
+ };
733
+ /**
734
+ * 时间持续对象(最大单位为天)
735
+ */
736
+ type DurationMaxDayObject = {
737
+ /**
738
+ * - 天数
739
+ */
740
+ days: number;
741
+ /**
742
+ * - 小时数(0-23)
743
+ */
744
+ hours: number;
745
+ /**
746
+ * - 分钟数(0-59)
747
+ */
748
+ minutes: number;
749
+ /**
750
+ * - 秒数(0-59)
751
+ */
752
+ seconds: number;
753
+ /**
754
+ * - 毫秒数(0-999)
755
+ */
756
+ milliseconds: number;
757
+ };
758
+ /**
759
+ * 时间持续对象(最大单位为小时)
760
+ */
761
+ type DurationMaxHourObject = {
762
+ /**
763
+ * - 小时数
764
+ */
765
+ hours: number;
766
+ /**
767
+ * - 分钟数(0-59)
768
+ */
769
+ minutes: number;
770
+ /**
771
+ * - 秒数(0-59)
772
+ */
773
+ seconds: number;
774
+ /**
775
+ * - 毫秒数(0-999)
776
+ */
777
+ milliseconds: number;
778
+ };
580
779
 
581
780
  /**
582
781
  * 通过动态创建 `<a>` 标签触发浏览器下载。
@@ -743,6 +942,18 @@ declare function flatCompleteTree2NestedTree<T>(nodes: T[], parentId?: number |
743
942
  parentKey?: string | undefined;
744
943
  childrenKey?: string | undefined;
745
944
  }): (T & { [k in typeof childrenKey]: T[]; })[];
945
+ /**
946
+ * 在嵌套树中按 `id` 递归查找节点,并返回其指定属性值。
947
+ *
948
+ * @template T extends Record<PropertyKey, any>
949
+ * @param {string | number} id - 要查找的 id
950
+ * @param {T[]} arr - 嵌套树森林
951
+ * @param {string} [resultKey='name'] - 需要返回的字段
952
+ * @param {string} [idKey='id'] - 主键字段
953
+ * @param {string} [childrenKey='children'] - 子节点字段
954
+ * @returns {any} 找到的值;未找到返回 `undefined`
955
+ */
956
+ declare function findObjAttrValueById<T>(id: string | number, arr: T[], resultKey?: string, idKey?: string, childrenKey?: string): any;
746
957
  /**
747
958
  * 从服务端返回的已选 id 数组里,提取出
748
959
  * 1. 叶子节点
@@ -759,6 +970,6 @@ declare function extractFullyCheckedKeys(treeData: any[], selectedKeys: any[], i
759
970
  checked: string[];
760
971
  halfChecked: string[];
761
972
  };
762
- declare function findObjAttrValueById<T>(id: string | number, arr: T[], resultKey?: string, idKey?: string, childrenKey?: string): any;
973
+ declare function findTreeNodeById<T>(id: string | number, arr: T[], idKey?: string, childrenKey?: string): any;
763
974
 
764
- export { AudioStreamResampler, IntervalTimer, MyEvent, MyEvent_CrossPagePlugin, MyId, WebSocketManager, assignExisting, calcTimeDifference, debounce, deepCloneByJSON, downloadByBlob, downloadByData, downloadByUrl, downloadExcel, downloadJSON, extractFullyCheckedKeys, fetchOrDownloadByUrl, findObjAttrValueById, flatCompleteTree2NestedTree, formatDuration, formatDurationMaxDay, formatDurationMaxHour, formatTimeForLocale, getAllSearchParams, getDataType, getFunctionArgNames, getGUID, getSearchParam, getTimePeriodName, getViewportSize, isBlob, isDate, isFunction, isNonEmptyString, isPlainObject, isPromise, moveItem, nestedTree2IdMap, pcmToWavBlob, randomDateInRange, randomEnLetter, randomHan, randomHanOrEn, randomIntInRange, readBlobAsText, shuffle, throttle, toDate };
975
+ export { AudioStreamResampler, IntervalTimer, MyEvent, MyEvent_CrossPagePlugin, MyId, WebSocketManager, assignExisting, debounce, deepCloneByJSON, downloadByBlob, downloadByData, downloadByUrl, downloadExcel, downloadJSON, extractFullyCheckedKeys, fetchOrDownloadByUrl, findObjAttrValueById, findTreeNodeById, flatCompleteTree2NestedTree, formatTimeForLocale, getAllSearchParams, getDataType, getFunctionArgNames, getGUID, getSearchParam, getTimePeriodName, getViewportSize, handleDbMenuItems, isBlob, isDate, isFunction, isNonEmptyString, isPlainObject, isPromise, millisecond2Duration, millisecond2DurationMaxDay, millisecond2DurationMaxHour, moveItem, nestedTree2IdMap, pcmToWavBlob, randomDateInRange, randomEnLetter, randomHan, randomHanOrEn, randomIntInRange, readBlobAsText, second2Duration, second2DurationMaxDay, second2DurationMaxHour, shuffle, throttle, toDate };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * 处理数据库菜单项,生成 UI 菜单树和路由配置。
3
+ *
4
+ * @param {Array<Object>} menuItems - 原始菜单项数组,树形结构
5
+ * @param {Object} [options] - 配置选项
6
+ * @param {string} [options.idKey='id'] - 数据源 ID 键名
7
+ * @param {string} [options.codeKey='code'] - 数据源编码键名, 用于拼接路由名称和路由路径
8
+ * @param {string} [options.labelKey='text'] - 数据源标签键名
9
+ * @param {string} [options.childrenKey='children'] - 数据源子节点键名
10
+ * @param {string} [options.extendKey='extend'] - 数据源扩展对象键名
11
+ * @param {string} [options.menuIdKey='key'] - 输出菜单 ID 键名
12
+ * @param {string} [options.menuLabelKey='label'] - 输出菜单标签键名
13
+ * @param {string} [options.menuChildrenKey='children'] - 输出菜单子节点键名
14
+ * @param {string} [options.menuExtendKey='extend'] - 输出菜单扩展对象键名
15
+ * @param {string} [options.routeNameKey='name'] - 路由名称键名
16
+ * @param {string} [options.routePathKey='path'] - 路由路径键名
17
+ * @param {string} [options.routeMetaKey='meta'] - 路由元数据键名
18
+ * @param {Function} [options.handleNodeItem] - 节点处理钩子,参数:(nodeSimple) => void
19
+ * @param {Function} [options.handleMenuItem] - 菜单项处理钩子,参数:(uiMenuItem, nodeSimple) => void
20
+ * @param {Function} [options.handleRouteItem] - 路由项处理钩子,参数:(routeItem, nodeSimple) => void
21
+ *
22
+ * @returns {Object} 处理结果
23
+ * @returns {Array<Object>} returns.uiMenuItems - UI 菜单树形结构数组
24
+ * @returns {Array<Object>} returns.routeItems - 扁平化路由配置数组
25
+ * @returns {Map<string, Object>} returns.nodeMap - 节点 ID 到节点数据的映射表
26
+ *
27
+ * @example
28
+ * const menuItems = [
29
+ * { id: '1', code: 'system', text: '系统管理', children: [
30
+ * { id: '1-1', code: 'user', text: '用户管理' }
31
+ * ]}
32
+ * ];
33
+ *
34
+ * const result = handleDbMenuItems(menuItems, {
35
+ * handleRouteItem: (route, node) => {
36
+ * route.component = () => import(`./views/${node.code}.vue`);
37
+ * }
38
+ * });
39
+ *
40
+ * // result.uiMenuItems: [{ key: '1', label: '系统管理', children: [...] }]
41
+ * // result.routeItems: [{ name: 'system.user', path: '/system/user', meta: { id: '1-1' } }]
42
+ * // result.nodeMap: Map { '1' => {...}, '1-1' => {...} }
43
+ */
44
+ declare function handleDbMenuItems(menuItems: Array<Object>, options?: {
45
+ idKey?: string | undefined;
46
+ codeKey?: string | undefined;
47
+ labelKey?: string | undefined;
48
+ childrenKey?: string | undefined;
49
+ extendKey?: string | undefined;
50
+ menuIdKey?: string | undefined;
51
+ menuLabelKey?: string | undefined;
52
+ menuChildrenKey?: string | undefined;
53
+ menuExtendKey?: string | undefined;
54
+ routeNameKey?: string | undefined;
55
+ routePathKey?: string | undefined;
56
+ routeMetaKey?: string | undefined;
57
+ handleNodeItem?: Function | undefined;
58
+ handleMenuItem?: Function | undefined;
59
+ handleRouteItem?: Function | undefined;
60
+ }): Object;
61
+
62
+ export { handleDbMenuItems };