joy-admin-components 0.2.88 → 0.2.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,440 @@
1
+ import { Ref } from 'vue';
2
+ // 验证工具类型
3
+ export interface ValidatorOptions {
4
+ /** 是否在表单中使用,默认 true */
5
+ inForm?: boolean;
6
+ /** 是否必填,默认 true */
7
+ required?: boolean;
8
+ /** 要验证的值(非表单模式) */
9
+ value?: string;
10
+ /** 错误提示信息 */
11
+ msg?: string;
12
+ }
13
+
14
+ /**
15
+ * 创建表单验证器
16
+ * @param type 验证类型:'phone' | 'password' | 'email'
17
+ * @param opt 验证选项
18
+ */
19
+ export function creatValidator(
20
+ type: 'phone' | 'password' | 'email',
21
+ opt?: ValidatorOptions
22
+ ): boolean | ((rule: any, value: any, callback: any) => void);
23
+
24
+
25
+ // Excel 工具类型
26
+ export interface ImportExcelOptions {
27
+ /** 其他选项 */
28
+ [key: string]: any;
29
+ }
30
+
31
+ export interface ExportExcelOptions {
32
+ /** 其他选项 */
33
+ [key: string]: any;
34
+ }
35
+
36
+ /**
37
+ * 导入 Excel 文件
38
+ * @param file Excel 文件对象
39
+ * @param options 导入选项
40
+ */
41
+ export function importExcel(file: File, options?: ImportExcelOptions): Promise<any>;
42
+
43
+ /**
44
+ * 导出 Excel 文件
45
+ * @param tableName 表格名称
46
+ * @param tableHeader 表头配置
47
+ * @param tableData 表格数据
48
+ * @param options 导出选项
49
+ */
50
+ export function exportExcel(
51
+ tableName: string,
52
+ tableHeader: any[],
53
+ tableData?: any[],
54
+ options?: ExportExcelOptions
55
+ ): Promise<void>;
56
+
57
+ /**
58
+ * 多 sheet 导入 Excel 配置
59
+ */
60
+ export interface ImportExcelMuiltiOptions {
61
+ /** 按 sheet 名称映射字段配置 */
62
+ fields: Record<string, Record<string, string>>;
63
+ /** 有效数据起始行,默认 1 */
64
+ range?: number;
65
+ /** 是否读取图片 */
66
+ withImages?: boolean;
67
+ }
68
+
69
+ /**
70
+ * 多 sheet 导入 Excel 文件
71
+ * @param file Excel 文件对象
72
+ * @param options 导入选项
73
+ * @returns 返回按 sheet 名称组织的数据对象
74
+ */
75
+ export function importExcelMuilti(
76
+ file: File,
77
+ options: ImportExcelMuiltiOptions
78
+ ): Promise<Record<string, any[]>>;
79
+
80
+ /**
81
+ * 多 sheet 导出 Excel 表头配置
82
+ */
83
+ export interface ExportExcelMuiltiHeader {
84
+ /** 表头显示文本 */
85
+ header: string;
86
+ /** 数据字段 key */
87
+ key: string;
88
+ /** 列宽度 */
89
+ width?: number;
90
+ /** 列样式 */
91
+ style?: any;
92
+ /** 下拉选项配置 */
93
+ option?: Array<{ label: any; value: any }>;
94
+ /** 是否必填 */
95
+ required?: boolean;
96
+ /** 单元格数字格式:'date' | 'number' | 'string' 或自定义格式 */
97
+ numFmt?: string;
98
+ }
99
+
100
+ /**
101
+ * 多 sheet 导出 Excel 配置
102
+ */
103
+ export interface ExportExcelMuiltiSheet {
104
+ /** 表头配置 */
105
+ tableHeader: ExportExcelMuiltiHeader[];
106
+ /** 表格数据 */
107
+ tableData: any[];
108
+ /** sheet 排序顺序 */
109
+ sort?: number;
110
+ }
111
+
112
+ /**
113
+ * 多 sheet 导出 Excel 文件
114
+ * @param tableName 导出表格名称
115
+ * @param sheets 按 sheet 名称配置的数据对象
116
+ */
117
+ export function exportExcelMuilti(
118
+ tableName: string,
119
+ sheets: Record<string, ExportExcelMuiltiSheet>
120
+ ): Promise<void>;
121
+
122
+ // 单点登录 SDK 类型
123
+ export default class OnePortalCasSDK {
124
+ constructor(...args: any[]);
125
+ [key: string]: any;
126
+ }
127
+
128
+ // ============== 数字格式化工具类型 ==============
129
+
130
+ /**
131
+ * 将数字添加千分位分隔符,并保留指定小数位数
132
+ * @param num 需要格式化的数字
133
+ * @param decimals 保留的小数位数,默认 2 位
134
+ * @param decimalSeparator 小数点分隔符,默认 '.'
135
+ * @param thousandSeparator 千分位分隔符,默认 ','
136
+ * @returns 格式化后的数字字符串
137
+ * @example
138
+ * formatNumber(1234567.89) // '1,234,567.89'
139
+ * formatNumber(1234567.89, 0) // '1,234,568'
140
+ * formatNumber(1234567.8912, 3) // '1,234,567.891'
141
+ */
142
+ export function formatNumber(
143
+ num: number | string,
144
+ decimals?: number,
145
+ decimalSeparator?: string,
146
+ thousandSeparator?: string
147
+ ): string;
148
+
149
+ /**
150
+ * 格式化金额(默认 2 位小数,带千分位)
151
+ * @param amount 金额
152
+ * @param decimals 小数位数,默认 2 位
153
+ * @returns 格式化后的金额字符串
154
+ * @example
155
+ * formatMoney(1234567.89) // '1,234,567.89'
156
+ * formatMoney(-1234567.89) // '-1,234,567.89'
157
+ */
158
+ export function formatMoney(amount: number | string, decimals?: number): string;
159
+
160
+ /**
161
+ * 格式化百分比
162
+ * @param num 数字(如 0.1234 表示 12.34%)
163
+ * @param decimals 小数位数,默认 2 位
164
+ * @returns 格式化后的百分比字符串
165
+ * @example
166
+ * formatPercent(0.1234) // '12.34%'
167
+ * formatPercent(0.1234, 0) // '12%'
168
+ * formatPercent(1.5) // '150.00%'
169
+ */
170
+ export function formatPercent(num: number | string, decimals?: number): string;
171
+
172
+ // ============== 通用工具函数类型 ==============
173
+
174
+ /**
175
+ * 延迟执行(Promise 版本)
176
+ * @param wait 等待时间(毫秒)
177
+ */
178
+ export function sleep(wait: number): Promise<void>;
179
+
180
+ /**
181
+ * 深度克隆对象(通过 JSON 序列化)
182
+ * @param data 要克隆的数据
183
+ */
184
+ export function _toRaw<T>(data: T): T;
185
+
186
+ /**
187
+ * 将扁平数组转换为树形结构
188
+ * @param items 扁平数组,每项需包含 id 和 pid 属性
189
+ */
190
+ export function arrayToTree<T extends { id: any; pid: any }>(items: T[]): T[];
191
+
192
+ /**
193
+ * 将字符串按指定字符分割为数组
194
+ * @param str 要分割的字符串
195
+ * @param split 分隔符,默认为空格
196
+ */
197
+ export function stringToArray(str: string, split?: string): string[];
198
+
199
+ /**
200
+ * StatusMap 类 - 创建一个可遍历、可快速取值的状态映射数据结构
201
+ */
202
+ export class StatusMap {
203
+ list: any[];
204
+ map: Map<any, any>;
205
+
206
+ constructor(arrStatus: any[], keys?: string[]);
207
+
208
+ /**
209
+ * 根据 key 获取名称(支持多语言)
210
+ * @param key 状态值
211
+ * @param locale 语言环境,如 'zh_cn' 或 'en_us'
212
+ */
213
+ getName(key: any, locale?: string): string;
214
+
215
+ /**
216
+ * 根据 key 获取标签类型
217
+ * @param key 状态值
218
+ */
219
+ getTag(key: any): string;
220
+
221
+ /**
222
+ * 根据 key 获取完整数据项
223
+ * @param key 状态值
224
+ */
225
+ getItem(key: any): any | null;
226
+
227
+ /**
228
+ * 根据 key 获取颜色
229
+ * @param key 状态值
230
+ */
231
+ getColor(key: any): string | null;
232
+
233
+ /**
234
+ * 检查是否包含某个 key
235
+ * @param key 状态值
236
+ */
237
+ has(key: any): boolean;
238
+ }
239
+
240
+ /**
241
+ * 将数组转换为 StatusMap 对象
242
+ * @param arr 数组数据
243
+ * @param keys 键名映射数组,至少需要 2 个元素 [label键, value键, ...]
244
+ * @param labelEn 英文标签字段名,默认 'i18nName'
245
+ */
246
+ export function arrToStatusMap(arr: any[], keys: string[], labelEn?: string): StatusMap;
247
+
248
+ /**
249
+ * 去除 HTML 标签
250
+ * @param html 包含 HTML 标签的字符串
251
+ */
252
+ export function stripHtmlTags(html: string): string;
253
+
254
+ /**
255
+ * 将 Unicode 编码转换为普通字符串
256
+ * @param unicodeStr Unicode 字符串
257
+ */
258
+ export function unicode2Str(unicodeStr: string): string;
259
+
260
+ /**
261
+ * 检查文件大小是否超过限制
262
+ * @param file 要检查的文件对象
263
+ * @param size 限制的文件大小(单位:MB),默认 10MB
264
+ * @returns 如果文件大小未超过限制,返回 true;否则返回 false
265
+ */
266
+ export function checkFileSize(file: File, size?: number): boolean;
267
+
268
+ /**
269
+ * 根据页面名称创建 ListPage 的 ID 数组
270
+ * @param name 页面名称
271
+ */
272
+ export function createListPageId(name: string): string[];
273
+
274
+ /**
275
+ * 根据表头生成导入字段映射
276
+ * @param header 表头配置数组
277
+ * @returns 字段映射对象
278
+ */
279
+ export function createImportFields(header: any[]): Record<string, string>;
280
+
281
+ /**
282
+ * 根据链式 key 获取对象的值
283
+ * @param object 目标对象
284
+ * @param chainKey 链式 key,如 'a.b.c'
285
+ */
286
+ export function getValueBykey<T = any>(object: any, chainKey: string): T | undefined;
287
+
288
+ /**
289
+ * 请求选项配置
290
+ */
291
+ export interface UseRequestOptions {
292
+ /** 是否手动执行,默认 false */
293
+ manual?: boolean;
294
+ /** 是否打印日志 */
295
+ log?: boolean;
296
+ /** 首次执行传参 */
297
+ params?: any;
298
+ /** 回调函数 */
299
+ cb?: (res: any) => void;
300
+ /** 对返回的数据按属性名进行过滤 */
301
+ format?: string[] | null;
302
+ }
303
+
304
+ /**
305
+ * 请求简单封装
306
+ * @param apiHandle 请求 Promise
307
+ * @param opt 配置选项
308
+ * @returns [loading, resData, run] 加载状态、响应数据、执行函数
309
+ */
310
+ export function useRequest(
311
+ apiHandle: (params?: any) => Promise<any>,
312
+ opt?: UseRequestOptions
313
+ ): [Ref<boolean>, Ref<any>, (params?: any) => void];
314
+
315
+ /**
316
+ * 范围时间选择器值解构
317
+ * @param date 时间组件绑定的数组
318
+ * @returns [dateSource, start, end] 日期源、开始时间、结束时间
319
+ */
320
+ export function useDatePicker(date: string[]): [Ref<string[]>, Ref<string>, Ref<string>];
321
+
322
+ /**
323
+ * 获取值的类型
324
+ * @param value 要检测类型的值
325
+ * @returns 类型字符串(小写),如 'string', 'number', 'array', 'object' 等
326
+ */
327
+ export function _typeOf(value: any): string;
328
+
329
+ // i18n.js hooks
330
+
331
+ /**
332
+ * 国际化响应式状态
333
+ * @param state 返回值的函数
334
+ * @param otherWatch 其他需要监听的值数组
335
+ * @returns [data] 响应式数据
336
+ */
337
+ export function useI18nReState<T>(state: () => T, otherWatch?: any[]): Ref<T>;
338
+
339
+ /**
340
+ * 根据当前语言环境获取对应字段的值
341
+ *
342
+ * 用于处理后端返回的多语言数据对象,自动根据当前 i18n 语言环境返回对应的字段值
343
+ *
344
+ * @param sourceData - 包含多语言字段的源数据对象
345
+ * @param zh - 中文字段名,指定 sourceData 中哪个字段是中文内容,默认 'zh_cn'
346
+ * @param en - 英文字段名,指定 sourceData 中哪个字段是英文内容,默认 'en_us'
347
+ * @returns 返回当前语言对应的字段值,找不到则返回中文字段值,都没有则返回 '-'
348
+ *
349
+ * @description
350
+ * 该函数会自动检测当前 i18n 的语言环境(zh_cn 或 en_us),并返回 sourceData 中对应的字段值。
351
+ *
352
+ * **工作原理:**
353
+ * 1. 根据 zh 和 en 参数确定字段映射关系
354
+ * 2. 获取当前 i18n 语言环境
355
+ * 3. 返回对应语言的字段值
356
+ * 4. 如果找不到当前语言字段,回退到中文字段
357
+ * 5. 如果中文字段也不存在,返回 '-'
358
+ *
359
+ * **回退机制:**
360
+ * sourceData[当前语言字段] → sourceData[中文字段] → '-'
361
+ *
362
+ * @example
363
+ * ```ts
364
+ * // 示例 1:标准用法(字段名为 zh_cn 和 en_us)
365
+ * const data = { zh_cn: '产品A', en_us: 'Product A' };
366
+ * getLocaleValue(data);
367
+ * // 当前语言为中文时返回 '产品A'
368
+ * // 当前语言为英文时返回 'Product A'
369
+ * ```
370
+ *
371
+ * @example
372
+ * ```ts
373
+ * // 示例 2:自定义字段名
374
+ * const data = { nameCn: '产品B', nameEn: 'Product B' };
375
+ * getLocaleValue(data, 'nameCn', 'nameEn');
376
+ * // 当前语言为中文时返回 '产品B'
377
+ * // 当前语言为英文时返回 'Product B'
378
+ * ```
379
+ *
380
+ * @example
381
+ * ```ts
382
+ * // 示例 3:只有中文字段(回退机制)
383
+ * const data = { nameCn: '产品C' };
384
+ * getLocaleValue(data, 'nameCn', 'nameEn');
385
+ * // 即使当前语言为英文,也会返回 '产品C'(回退到中文)
386
+ * ```
387
+ *
388
+ * @example
389
+ * ```ts
390
+ * // 示例 4:空数据
391
+ * getLocaleValue(null); // 返回 '-'
392
+ * getLocaleValue(undefined); // 返回 '-'
393
+ * ```
394
+ *
395
+ * @example
396
+ * ```ts
397
+ * // 示例 5:在列表渲染中使用
398
+ * const products = [
399
+ * { id: 1, nameCn: '苹果', nameEn: 'Apple' },
400
+ * { id: 2, nameCn: '香蕉', nameEn: 'Banana' }
401
+ * ];
402
+ * products.map(item => getLocaleValue(item, 'nameCn', 'nameEn'));
403
+ * // 当前语言为中文时返回 ['苹果', '香蕉']
404
+ * // 当前语言为英文时返回 ['Apple', 'Banana']
405
+ * ```
406
+ */
407
+ export function getLocaleValue(
408
+ sourceData: Record<string, any> | null | undefined,
409
+ zh?: string,
410
+ en?: string
411
+ ): string;
412
+
413
+ // storeHook.js hooks
414
+
415
+ /**
416
+ * 使用 Vuex State(支持模块化)
417
+ * @param moduleName 模块名称(可选)
418
+ * @param mapper state 映射对象或数组
419
+ * @returns 响应式 state 对象
420
+ */
421
+ export function useState(moduleName: string, mapper: string[] | Record<string, any>): Record<string, Ref<any>>;
422
+ export function useState(mapper: string[] | Record<string, any>): Record<string, Ref<any>>;
423
+
424
+ /**
425
+ * 使用 Vuex Getters(支持模块化)
426
+ * @param moduleName 模块名称(可选)
427
+ * @param mapper getters 映射对象或数组
428
+ * @returns 响应式 getters 对象
429
+ */
430
+ export function useGetters(moduleName: string, mapper: string[] | Record<string, any>): Record<string, Ref<any>>;
431
+ export function useGetters(mapper: string[] | Record<string, any>): Record<string, Ref<any>>;
432
+
433
+ /**
434
+ * 使用 Vuex Actions(支持模块化)
435
+ * @param moduleName 模块名称(可选)
436
+ * @param mapper actions 映射对象或数组
437
+ * @returns actions 对象
438
+ */
439
+ export function useActions(moduleName: string, mapper: string[] | Record<string, any>): Record<string, (...args: any[]) => any>;
440
+ export function useActions(mapper: string[] | Record<string, any>): Record<string, (...args: any[]) => any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joy-admin-components",
3
- "version": "0.2.88",
3
+ "version": "0.2.90",
4
4
  "main": "./dist/joy-admin-components.umd.js",
5
5
  "module": "./dist/joy-admin-components.es.js",
6
6
  "types": "./dist/index.d.ts",
@@ -5,7 +5,7 @@ import { SelectProps } from 'element-plus';
5
5
  * 字典选择器组件 - 基于 Element Plus Select 封装
6
6
  * 支持 API 请求数据、全选、多语言等功能
7
7
  */
8
- export interface CmpDictionaryProps extends /* @vue-ignore */ Partial<SelectProps> {
8
+ export interface CmpDictionaryProps extends Partial<SelectProps> {
9
9
  /** 获取下拉数据的 API 函数 */
10
10
  api?: () => Promise<{ data: any[] }>;
11
11
  /** 是否显示全选复选框(仅多选模式),默认 true */
@@ -39,5 +39,5 @@ export interface CmpDictionaryEmits {
39
39
  (e: 'update:modelValue', value: any): void;
40
40
  }
41
41
 
42
- declare const CmpDictionary: DefineComponent<CmpDictionaryProps, {}, any, {}, {}, {}, {}, CmpDictionaryEmits>;
42
+ declare const CmpDictionary: DefineComponent<CmpDictionaryProps>;
43
43
  export default CmpDictionary;
@@ -6,7 +6,7 @@ import { PopconfirmProps } from 'element-plus';
6
6
  * 点击后弹出确认气泡,确认后执行操作(自动防抖 500ms)
7
7
  * 继承 Element Plus ElPopconfirm 所有属性
8
8
  */
9
- export interface ConfrimButtonProps extends /* @vue-ignore */ Partial<PopconfirmProps> {}
9
+ export type ConfrimButtonProps = Partial<PopconfirmProps>;
10
10
 
11
11
  export interface ConfrimButtonEmits {
12
12
  /** 确认操作时触发(已防抖处理) */
@@ -15,5 +15,5 @@ export interface ConfrimButtonEmits {
15
15
  (e: 'no'): void;
16
16
  }
17
17
 
18
- declare const ConfrimButton: DefineComponent<ConfrimButtonProps, {}, any, {}, {}, {}, {}, ConfrimButtonEmits>;
18
+ declare const ConfrimButton: DefineComponent<ConfrimButtonProps>;
19
19
  export default ConfrimButton;
@@ -16,5 +16,5 @@ export interface ImportButtonEmits {
16
16
  (e: 'fileChange', file: File): void;
17
17
  }
18
18
 
19
- declare const ImportButton: DefineComponent<ImportButtonProps, {}, any, {}, {}, {}, {}, ImportButtonEmits>;
19
+ declare const ImportButton: DefineComponent<ImportButtonProps>;
20
20
  export default ImportButton;
@@ -6,7 +6,7 @@ import { FormProps } from 'element-plus';
6
6
  * 继承 Element Plus ElForm 所有属性
7
7
  * 自动为表单项添加栅格布局,支持多列表单
8
8
  */
9
- export interface LayOutFormProps extends /* @vue-ignore */ FormProps {
9
+ export interface LayOutFormProps extends FormProps {
10
10
  /** 栅格间隔,默认 20 */
11
11
  gutter?: number;
12
12
  }
@@ -16,5 +16,5 @@ export interface LayOutFormEmits {
16
16
  (e: 'ref', formRef: any): void;
17
17
  }
18
18
 
19
- declare const LayOutForm: DefineComponent<LayOutFormProps, {}, any, {}, {}, {}, {}, LayOutFormEmits>;
19
+ declare const LayOutForm: DefineComponent<LayOutFormProps>;
20
20
  export default LayOutForm;
@@ -31,5 +31,5 @@ export interface LayerEmits {
31
31
  (e: 'confirm'): void;
32
32
  }
33
33
 
34
- declare const Layer: DefineComponent<LayerProps, {}, any, {}, {}, {}, {}, LayerEmits>;
34
+ declare const Layer: DefineComponent<LayerProps>;
35
35
  export default Layer;
@@ -88,5 +88,5 @@ export interface ListPageExpose {
88
88
  calculateTableHeight: () => void;
89
89
  }
90
90
 
91
- declare const ListPage: DefineComponent<ListPageProps, {}, any>;
91
+ declare const ListPage: DefineComponent<ListPageProps>;
92
92
  export default ListPage;
@@ -47,5 +47,5 @@ export interface SearchBarEmits {
47
47
  (e: 'reset'): void;
48
48
  }
49
49
 
50
- declare const SearchBar: DefineComponent<SearchBarProps, {}, any, {}, {}, {}, {}, SearchBarEmits>;
50
+ declare const SearchBar: DefineComponent<SearchBarProps>;
51
51
  export default SearchBar;