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/dist/a2bei4.utils.cjs.js +415 -110
- package/dist/a2bei4.utils.cjs.js.map +1 -1
- package/dist/a2bei4.utils.cjs.min.js +1 -1
- package/dist/a2bei4.utils.cjs.min.js.map +1 -1
- package/dist/a2bei4.utils.esm.js +408 -107
- package/dist/a2bei4.utils.esm.js.map +1 -1
- package/dist/a2bei4.utils.esm.min.js +1 -1
- package/dist/a2bei4.utils.esm.min.js.map +1 -1
- package/dist/a2bei4.utils.umd.js +415 -110
- package/dist/a2bei4.utils.umd.js.map +1 -1
- package/dist/a2bei4.utils.umd.min.js +1 -1
- package/dist/a2bei4.utils.umd.min.js.map +1 -1
- package/dist/date.cjs +191 -100
- package/dist/date.cjs.map +1 -1
- package/dist/date.js +186 -97
- package/dist/date.js.map +1 -1
- package/dist/menu.cjs +202 -0
- package/dist/menu.cjs.map +1 -0
- package/dist/menu.js +200 -0
- package/dist/menu.js.map +1 -0
- package/dist/tree.cjs +21 -6
- package/dist/tree.cjs.map +1 -1
- package/dist/tree.js +21 -7
- package/dist/tree.js.map +1 -1
- package/package.json +12 -7
- package/types/date.d.ts +186 -47
- package/types/index.d.ts +259 -48
- package/types/menu.d.ts +62 -0
- package/types/tree.d.ts +14 -2
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
|
-
* @
|
|
25
|
-
* @
|
|
26
|
-
* @
|
|
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
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @
|
|
39
|
-
* @
|
|
40
|
-
* @
|
|
41
|
-
* @
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*
|
|
45
|
-
* @
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
*
|
|
50
|
+
* 将毫秒转换为时间持续对象。
|
|
62
51
|
*
|
|
63
|
-
* @param {number}
|
|
64
|
-
* @param {
|
|
65
|
-
* @
|
|
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
|
|
80
|
+
declare function millisecond2DurationMaxDay(milliseconds: number): DurationMaxDayObject;
|
|
68
81
|
/**
|
|
69
|
-
*
|
|
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
|
-
* @
|
|
72
|
-
*
|
|
73
|
-
*
|
|
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
|
|
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 {
|
|
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
|
-
* @
|
|
470
|
-
*
|
|
471
|
-
*
|
|
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
|
|
474
|
-
days: number;
|
|
475
|
-
hours: string;
|
|
476
|
-
minutes: string;
|
|
477
|
-
seconds: string;
|
|
478
|
-
};
|
|
586
|
+
declare function millisecond2DurationMaxDay(milliseconds: number): DurationMaxDayObject;
|
|
479
587
|
/**
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
* @
|
|
484
|
-
* @
|
|
485
|
-
* @
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
|
|
489
|
-
|
|
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
|
-
*
|
|
599
|
+
* 将秒转换为时间持续对象。
|
|
507
600
|
*
|
|
508
|
-
* @param {number}
|
|
509
|
-
* @param {
|
|
510
|
-
* @
|
|
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
|
|
629
|
+
declare function second2DurationMaxDay(seconds: number): DurationMaxDayObject;
|
|
513
630
|
/**
|
|
514
|
-
*
|
|
515
|
-
*
|
|
516
|
-
* @
|
|
517
|
-
* @
|
|
518
|
-
* @
|
|
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
|
|
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
|
|
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,
|
|
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 };
|
package/types/menu.d.ts
ADDED
|
@@ -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 };
|