@yetuzi/vue3-query-components 1.1.38 → 1.2.1
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/CHANGELOG.md +105 -0
- package/README.md +127 -68
- package/dist/index.css +1 -1
- package/dist/index.d.ts +481 -74
- package/dist/index.js +944 -953
- package/dist/index.js.map +1 -1
- package/dist/version-info.json +28 -0
- package/package.json +89 -79
package/dist/index.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ import { VNodeProps } from 'vue';
|
|
|
41
41
|
declare const __VLS_component: DefineComponent<CommonConfigProviderProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<CommonConfigProviderProps> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
42
42
|
|
|
43
43
|
declare const __VLS_component_2: DefineComponent<__VLS_Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
44
|
-
form:
|
|
44
|
+
form: CommonFormItemArray<AnyObject>;
|
|
45
45
|
layouts: Array<CommonQueryTableLayoutsUnite>;
|
|
46
46
|
}, {}, {}, {}, string, ComponentProvideOptions, false, {
|
|
47
47
|
CommonFormRef: ShallowUnwrapRef<CommonFormExpose<AnyObject>> | null;
|
|
@@ -284,12 +284,6 @@ export declare const CommonCheckbox: DefineComponent<__VLS_PublicProps_6, {}, {}
|
|
|
284
284
|
"onUpdate:modelValue"?: ((value: CheckboxGroupValueType) => any) | undefined;
|
|
285
285
|
}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
286
286
|
|
|
287
|
-
/**
|
|
288
|
-
* 多选框
|
|
289
|
-
*/
|
|
290
|
-
declare interface CommonCheckboxItem<T extends AnyObject> extends CommonFormSupplement<'check-box', CommonCheckboxProps, T> {
|
|
291
|
-
}
|
|
292
|
-
|
|
293
287
|
export declare interface CommonCheckboxProps extends ExtractPublicPropTypes<CheckboxGroupProps> {
|
|
294
288
|
}
|
|
295
289
|
|
|
@@ -303,12 +297,6 @@ export declare const CommonConfigProvider: __VLS_WithTemplateSlots<typeof __VLS_
|
|
|
303
297
|
export declare interface CommonConfigProviderProps extends /* @vue-ignore */ DeepPartial<Config> {
|
|
304
298
|
}
|
|
305
299
|
|
|
306
|
-
/**
|
|
307
|
-
* 自定义组件
|
|
308
|
-
*/
|
|
309
|
-
declare interface CommonCustomComponentsItem<T extends AnyObject, C extends Component = Component, P = ComponentProps<C>> extends CommonFormSupplement<C, P, T> {
|
|
310
|
-
}
|
|
311
|
-
|
|
312
300
|
export declare const CommonDatePicker: DefineComponent<__VLS_PublicProps_4, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
|
|
313
301
|
"update:modelValue": (value: ModelValueType) => any;
|
|
314
302
|
}, string, PublicProps, Readonly<__VLS_PublicProps_4> & Readonly<{
|
|
@@ -323,12 +311,6 @@ readonly startPlaceholder: string;
|
|
|
323
311
|
readonly endPlaceholder: string;
|
|
324
312
|
}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
325
313
|
|
|
326
|
-
/**
|
|
327
|
-
* 日期选择器
|
|
328
|
-
*/
|
|
329
|
-
declare interface CommonDatePickerItem<T extends AnyObject> extends CommonFormSupplement<'date-picker', CommonDatePickerProps, T> {
|
|
330
|
-
}
|
|
331
|
-
|
|
332
314
|
/** CommonDatePicker组件属性类型,继承自Element Plus DatePicker组件 */
|
|
333
315
|
export declare interface CommonDatePickerProps extends Partial<DatePickerProps> {
|
|
334
316
|
}
|
|
@@ -354,52 +336,282 @@ export declare const CommonForm: <T extends AnyObject>(__VLS_props: NonNullable<
|
|
|
354
336
|
};
|
|
355
337
|
|
|
356
338
|
/**
|
|
357
|
-
*
|
|
339
|
+
* 多选框组件表单项
|
|
340
|
+
*
|
|
341
|
+
* @typeParam T - 表单数据对象类型
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```ts
|
|
345
|
+
* const checkboxItem: CommonFormCheckboxItem<UserData> = {
|
|
346
|
+
* is: 'check-box',
|
|
347
|
+
* prop: 'hobbies',
|
|
348
|
+
* label: '爱好',
|
|
349
|
+
* props: {
|
|
350
|
+
* options: [
|
|
351
|
+
* { label: '阅读', value: 'reading' },
|
|
352
|
+
* { label: '运动', value: 'sports' }
|
|
353
|
+
* ]
|
|
354
|
+
* }
|
|
355
|
+
* }
|
|
356
|
+
* ```
|
|
358
357
|
*/
|
|
359
|
-
export declare
|
|
360
|
-
|
|
361
|
-
};
|
|
358
|
+
export declare interface CommonFormCheckboxItem<T extends AnyObject> extends CommonFormItemBase<'check-box', CommonCheckboxProps, T> {
|
|
359
|
+
}
|
|
362
360
|
|
|
363
361
|
/**
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
362
|
+
* 自定义组件表单项
|
|
363
|
+
* 允许使用任意 Vue 组件作为表单项
|
|
364
|
+
*
|
|
365
|
+
* @typeParam T - 表单数据对象类型
|
|
366
|
+
* @typeParam C - 自定义组件类型,默认为 Component
|
|
367
|
+
* @typeParam P - 组件 Props 类型,默认从组件推导
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```ts
|
|
371
|
+
* import MyCustomComponent from './MyCustomComponent.vue'
|
|
372
|
+
*
|
|
373
|
+
* const customItem: CommonFormCustomItem<UserData> = {
|
|
374
|
+
* is: MyCustomComponent,
|
|
375
|
+
* prop: 'custom',
|
|
376
|
+
* label: '自定义字段',
|
|
377
|
+
* props: {
|
|
378
|
+
* // 传递给自定义组件的属性
|
|
379
|
+
* customProp: 'value'
|
|
380
|
+
* }
|
|
381
|
+
* }
|
|
382
|
+
* ```
|
|
367
383
|
*/
|
|
368
|
-
export declare interface
|
|
369
|
-
/** 表单数据对象 */
|
|
370
|
-
formData: Reactive<CommonFormData<T>>;
|
|
384
|
+
export declare interface CommonFormCustomItem<T extends AnyObject, C extends Component = Component, P = ComponentProps<C>> extends CommonFormItemBase<C, P, T> {
|
|
371
385
|
}
|
|
372
386
|
|
|
373
387
|
/**
|
|
374
|
-
*
|
|
388
|
+
* 表单数据类型
|
|
389
|
+
* 支持通过 prop 访问表单字段值,并允许额外的字符串索引
|
|
390
|
+
*
|
|
391
|
+
* @typeParam T - 表单数据对象类型
|
|
375
392
|
*/
|
|
376
|
-
declare
|
|
377
|
-
}
|
|
393
|
+
export declare type CommonFormData<T extends AnyObject> = T & Record<string, any>;
|
|
378
394
|
|
|
379
|
-
|
|
395
|
+
/**
|
|
396
|
+
* 日期选择器组件表单项
|
|
397
|
+
*
|
|
398
|
+
* @typeParam T - 表单数据对象类型
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* ```ts
|
|
402
|
+
* const dateItem: CommonFormDatePickerItem<UserData> = {
|
|
403
|
+
* is: 'date-picker',
|
|
404
|
+
* prop: 'birthday',
|
|
405
|
+
* label: '生日',
|
|
406
|
+
* props: {
|
|
407
|
+
* type: 'date',
|
|
408
|
+
* placeholder: '请选择日期'
|
|
409
|
+
* }
|
|
410
|
+
* }
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
export declare interface CommonFormDatePickerItem<T extends AnyObject> extends CommonFormItemBase<'date-picker', CommonDatePickerProps, T> {
|
|
414
|
+
}
|
|
380
415
|
|
|
381
416
|
/**
|
|
382
|
-
*
|
|
417
|
+
* CommonForm 组件实例暴露类型
|
|
418
|
+
* 继承 Element Plus FormInstance 的所有方法,并提供表单数据访问
|
|
419
|
+
*
|
|
420
|
+
* @typeParam T - 表单数据对象类型,默认为 AnyObject
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* ```vue
|
|
424
|
+
* <script setup lang="ts">
|
|
425
|
+
* import { ref } from 'vue'
|
|
426
|
+
*
|
|
427
|
+
* const formRef = ref<CommonFormExpose<UserData>>()
|
|
428
|
+
*
|
|
429
|
+
* const handleSubmit = async () => {
|
|
430
|
+
* // 调用 FormInstance 方法
|
|
431
|
+
* await formRef.value?.validate()
|
|
432
|
+
*
|
|
433
|
+
* // 访问表单数据
|
|
434
|
+
* console.log(formRef.value?.formData)
|
|
435
|
+
* }
|
|
436
|
+
* </script>
|
|
437
|
+
* ```
|
|
383
438
|
*/
|
|
384
|
-
export declare interface
|
|
385
|
-
|
|
439
|
+
export declare interface CommonFormExpose<T extends AnyObject = AnyObject> extends FormInstance {
|
|
440
|
+
/**
|
|
441
|
+
* 表单数据响应式对象
|
|
442
|
+
* 包含所有表单字段的当前值
|
|
443
|
+
*/
|
|
444
|
+
formData: Reactive<CommonFormData<T>>;
|
|
386
445
|
}
|
|
387
446
|
|
|
388
447
|
/**
|
|
389
|
-
*
|
|
448
|
+
* 输入框组件表单项
|
|
449
|
+
*
|
|
450
|
+
* @typeParam T - 表单数据对象类型
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* ```ts
|
|
454
|
+
* const inputItem: CommonFormInputItem<UserData> = {
|
|
455
|
+
* is: 'input',
|
|
456
|
+
* prop: 'name',
|
|
457
|
+
* label: '姓名',
|
|
458
|
+
* props: {
|
|
459
|
+
* placeholder: '请输入姓名',
|
|
460
|
+
* clearable: true
|
|
461
|
+
* }
|
|
462
|
+
* }
|
|
463
|
+
* ```
|
|
390
464
|
*/
|
|
391
|
-
declare interface
|
|
465
|
+
export declare interface CommonFormInputItem<T extends AnyObject> extends CommonFormItemBase<'input', CommonInputProps, T> {
|
|
392
466
|
}
|
|
393
467
|
|
|
394
|
-
|
|
395
|
-
|
|
468
|
+
/**
|
|
469
|
+
* 表单项类型数组
|
|
470
|
+
* 用于 CommonForm 的 form 属性,也可用于类型标注
|
|
471
|
+
*
|
|
472
|
+
* @typeParam T - 表单数据对象类型
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
* ```ts
|
|
476
|
+
* import type { CommonFormItemArray } from '@yetuzi/vue3-query-components'
|
|
477
|
+
*
|
|
478
|
+
* const form: CommonFormItemArray<MyDataType> = [
|
|
479
|
+
* { is: 'input', prop: 'name', label: '用户名' },
|
|
480
|
+
* { is: 'select', prop: 'status', label: '状态' }
|
|
481
|
+
* ]
|
|
482
|
+
* ```
|
|
483
|
+
*/
|
|
484
|
+
export declare type CommonFormItemArray<T extends AnyObject> = Array<CommonFormSelectItem<T> | CommonFormInputItem<T> | CommonFormDatePickerItem<T> | CommonFormRadioItem<T> | CommonFormCustomItem<T> | CommonFormCheckboxItem<T> | CommonFormSwitchItem<T>>;
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* 表单项基础接口
|
|
488
|
+
* 所有表单项类型的公共属性定义
|
|
489
|
+
*
|
|
490
|
+
* @typeParam T - 组件类型,可以是内置组件类型字符串或自定义组件
|
|
491
|
+
* @typeParam P - 组件的 Props 类型
|
|
492
|
+
* @typeParam D - 表单数据对象类型
|
|
493
|
+
* @typeParam V - 初始值的类型,默认为 any
|
|
494
|
+
*
|
|
495
|
+
* @example 内置组件
|
|
496
|
+
* ```ts
|
|
497
|
+
* const inputItem: CommonFormInputItem<UserData> = {
|
|
498
|
+
* is: 'input',
|
|
499
|
+
* prop: 'name',
|
|
500
|
+
* label: '姓名'
|
|
501
|
+
* }
|
|
502
|
+
* ```
|
|
503
|
+
*
|
|
504
|
+
* @example 自定义组件
|
|
505
|
+
* ```ts
|
|
506
|
+
* import MyComponent from './MyComponent.vue'
|
|
507
|
+
*
|
|
508
|
+
* const customItem: CommonFormCustomItem<UserData> = {
|
|
509
|
+
* is: MyComponent,
|
|
510
|
+
* prop: 'custom',
|
|
511
|
+
* label: '自定义字段'
|
|
512
|
+
* }
|
|
513
|
+
* ```
|
|
514
|
+
*/
|
|
515
|
+
declare interface CommonFormItemBase<T, P, D extends AnyObject, V = any> {
|
|
516
|
+
/**
|
|
517
|
+
* 组件类型标识
|
|
518
|
+
* - 内置组件:'input' | 'select' | 'date-picker' | 'radio' | 'check-box' | 'switch'
|
|
519
|
+
* - 自定义组件:直接传入组件对象
|
|
520
|
+
*/
|
|
521
|
+
is: T | (string & {});
|
|
522
|
+
/** 表单项标签 */
|
|
396
523
|
label?: string;
|
|
524
|
+
/** 表单字段名,支持表单数据类型的 key 或任意字符串 */
|
|
397
525
|
prop: keyof D | (string & {});
|
|
526
|
+
/** 传递给组件的额外属性 */
|
|
398
527
|
props?: Partial<P>;
|
|
528
|
+
/** 字段初始值 */
|
|
399
529
|
initialValue?: V;
|
|
530
|
+
/** ElFormItem 的额外属性配置(不包含 prop 和 label) */
|
|
400
531
|
formItem?: Partial<Omit<FormItemProps, 'prop' | 'label'>>;
|
|
401
532
|
}
|
|
402
533
|
|
|
534
|
+
/**
|
|
535
|
+
* CommonForm 组件 Props
|
|
536
|
+
*
|
|
537
|
+
* @typeParam T - 表单数据对象类型
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```vue
|
|
541
|
+
* <template>
|
|
542
|
+
* <CommonForm :form="formConfig" v-model="formData" />
|
|
543
|
+
* </template>
|
|
544
|
+
* ```
|
|
545
|
+
*/
|
|
546
|
+
export declare interface CommonFormProps<T extends AnyObject> extends ExtractPropTypes<FormProps> {
|
|
547
|
+
/** 表单项配置数组 */
|
|
548
|
+
form?: CommonFormItemArray<T>;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* 单选框组件表单项
|
|
553
|
+
*
|
|
554
|
+
* @typeParam T - 表单数据对象类型
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* ```ts
|
|
558
|
+
* const radioItem: CommonFormRadioItem<UserData> = {
|
|
559
|
+
* is: 'radio',
|
|
560
|
+
* prop: 'gender',
|
|
561
|
+
* label: '性别',
|
|
562
|
+
* props: {
|
|
563
|
+
* options: [
|
|
564
|
+
* { label: '男', value: 'male' },
|
|
565
|
+
* { label: '女', value: 'female' }
|
|
566
|
+
* ]
|
|
567
|
+
* }
|
|
568
|
+
* }
|
|
569
|
+
* ```
|
|
570
|
+
*/
|
|
571
|
+
export declare interface CommonFormRadioItem<T extends AnyObject> extends CommonFormItemBase<'radio', CommonRadioProps, T> {
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* 选择器组件表单项
|
|
576
|
+
*
|
|
577
|
+
* @typeParam T - 表单数据对象类型
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* ```ts
|
|
581
|
+
* const selectItem: CommonFormSelectItem<UserData> = {
|
|
582
|
+
* is: 'select',
|
|
583
|
+
* prop: 'city',
|
|
584
|
+
* label: '城市',
|
|
585
|
+
* props: {
|
|
586
|
+
* options: [
|
|
587
|
+
* { label: '北京', value: 'beijing' },
|
|
588
|
+
* { label: '上海', value: 'shanghai' }
|
|
589
|
+
* ]
|
|
590
|
+
* }
|
|
591
|
+
* }
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
export declare interface CommonFormSelectItem<T extends AnyObject> extends CommonFormItemBase<'select', CommonSelectProps, T> {
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* 开关组件表单项
|
|
599
|
+
*
|
|
600
|
+
* @typeParam T - 表单数据对象类型
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* ```ts
|
|
604
|
+
* const switchItem: CommonFormSwitchItem<UserData> = {
|
|
605
|
+
* is: 'switch',
|
|
606
|
+
* prop: 'enabled',
|
|
607
|
+
* label: '是否启用',
|
|
608
|
+
* initialValue: true
|
|
609
|
+
* }
|
|
610
|
+
* ```
|
|
611
|
+
*/
|
|
612
|
+
export declare interface CommonFormSwitchItem<T extends AnyObject> extends CommonFormItemBase<'switch', CommonSwitchProps, T> {
|
|
613
|
+
}
|
|
614
|
+
|
|
403
615
|
export declare const CommonInput: __VLS_WithTemplateSlots_5<typeof __VLS_component_5, __VLS_TemplateResult_5["slots"]>;
|
|
404
616
|
|
|
405
617
|
/** CommonInput组件属性类型,忽略复杂类型检查 */
|
|
@@ -435,7 +647,7 @@ export declare interface CommonQueryTableProps<T extends AnyObject = AnyObject>
|
|
|
435
647
|
* 表单配置数组
|
|
436
648
|
* 定义查询表单的字段和属性
|
|
437
649
|
*/
|
|
438
|
-
form?:
|
|
650
|
+
form?: CommonFormItemArray<T>;
|
|
439
651
|
/**
|
|
440
652
|
* 表格列配置
|
|
441
653
|
* 定义表格的列结构和展示方式
|
|
@@ -455,12 +667,6 @@ export declare const CommonRadio: DefineComponent<__VLS_PublicProps_5, {}, {}, {
|
|
|
455
667
|
"onUpdate:modelValue"?: ((value: EpPropMergeType<readonly [StringConstructor, NumberConstructor, BooleanConstructor], unknown, unknown> | undefined) => any) | undefined;
|
|
456
668
|
}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
457
669
|
|
|
458
|
-
/**
|
|
459
|
-
* 单选框
|
|
460
|
-
*/
|
|
461
|
-
declare interface CommonRadioItem<T extends AnyObject> extends CommonFormSupplement<'radio', CommonRadioProps, T> {
|
|
462
|
-
}
|
|
463
|
-
|
|
464
670
|
/** CommonRadio组件属性类型,提取自Element Plus RadioGroup组件的公共属性 */
|
|
465
671
|
export declare interface CommonRadioProps extends ExtractPublicPropTypes<RadioGroupProps> {
|
|
466
672
|
}
|
|
@@ -485,12 +691,6 @@ export declare const CommonSwitch: DefineComponent<__VLS_PublicProps_7, {}, {},
|
|
|
485
691
|
"onUpdate:modelValue"?: ((value: EpPropMergeType<readonly [BooleanConstructor, StringConstructor, NumberConstructor], unknown, unknown>) => any) | undefined;
|
|
486
692
|
}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
487
693
|
|
|
488
|
-
/**
|
|
489
|
-
* 开关
|
|
490
|
-
*/
|
|
491
|
-
declare interface CommonSwitchItem<T extends AnyObject> extends CommonFormSupplement<'switch', CommonSwitchProps, T> {
|
|
492
|
-
}
|
|
493
|
-
|
|
494
694
|
/**
|
|
495
695
|
* CommonSwitch组件属性类型
|
|
496
696
|
* 继承自Element Plus Switch组件的公共属性,并扩展自定义颜色配置
|
|
@@ -527,34 +727,157 @@ export declare const CommonTable: <T extends AnyObject>(__VLS_props: NonNullable
|
|
|
527
727
|
__ctx?: Awaited<typeof __VLS_setup>;
|
|
528
728
|
};
|
|
529
729
|
|
|
530
|
-
/**
|
|
730
|
+
/**
|
|
731
|
+
* 表格列类型数组
|
|
732
|
+
* 用于 CommonTable 的 columns 属性,也可用于类型标注
|
|
733
|
+
*
|
|
734
|
+
* @typeParam T - 表格数据行类型
|
|
735
|
+
*
|
|
736
|
+
* @example
|
|
737
|
+
* ```ts
|
|
738
|
+
* import type { CommonTableArrayColumns } from '@yetuzi/vue3-query-components'
|
|
739
|
+
*
|
|
740
|
+
* const columns: CommonTableArrayColumns<MyDataType> = [
|
|
741
|
+
* { prop: 'id', label: 'ID', type: 'index' },
|
|
742
|
+
* { prop: 'name', label: '用户名' },
|
|
743
|
+
* { prop: 'createTime', label: '创建时间', type: 'dateTime' }
|
|
744
|
+
* ]
|
|
745
|
+
* ```
|
|
746
|
+
*/
|
|
531
747
|
export declare type CommonTableArrayColumns<T extends AnyObject> = Array<CommonTableColumnRoot<T>>;
|
|
532
748
|
|
|
749
|
+
/**
|
|
750
|
+
* 表格列配置类型
|
|
751
|
+
* 支持数组形式和对象形式的列配置
|
|
752
|
+
*
|
|
753
|
+
* @typeParam T - 表格数据行类型
|
|
754
|
+
*
|
|
755
|
+
* @example 数组形式
|
|
756
|
+
* ```ts
|
|
757
|
+
* const columns: CommonTableArrayColumns<UserData> = [
|
|
758
|
+
* { prop: 'name', label: '姓名' },
|
|
759
|
+
* { prop: 'age', label: '年龄' }
|
|
760
|
+
* ]
|
|
761
|
+
* ```
|
|
762
|
+
*
|
|
763
|
+
* @example 对象形式
|
|
764
|
+
* ```ts
|
|
765
|
+
* const columns: CommonTableObjectColumns<UserData> = {
|
|
766
|
+
* name: { prop: 'name', label: '姓名' },
|
|
767
|
+
* age: { prop: 'age', label: '年龄' }
|
|
768
|
+
* }
|
|
769
|
+
* ```
|
|
770
|
+
*/
|
|
533
771
|
export declare type CommonTableColumn<T extends AnyObject> = CommonTableArrayColumns<T> | CommonTableObjectColumns<T>;
|
|
534
772
|
|
|
535
773
|
/**
|
|
536
|
-
*
|
|
774
|
+
* 表格列定义根类型
|
|
775
|
+
* 包含所有列类型的联合类型
|
|
776
|
+
*
|
|
777
|
+
* @typeParam T - 表格数据行类型
|
|
537
778
|
*/
|
|
538
|
-
export declare type CommonTableColumnRoot<T extends AnyObject> =
|
|
779
|
+
export declare type CommonTableColumnRoot<T extends AnyObject> = TableColumnBase<T> | TableColumnTypeIndex<T> | TableColumnTypeSelection<T> | TableColumnTypeExpand<T> | TableColumnTypeDate<T> | TableColumnTypeDateTime<T>;
|
|
539
780
|
|
|
540
|
-
/**
|
|
781
|
+
/**
|
|
782
|
+
* CommonTable 暴露给父组件的实例类型
|
|
783
|
+
* 包含 ElTable 的所有方法和属性
|
|
784
|
+
*
|
|
785
|
+
* @example
|
|
786
|
+
* ```vue
|
|
787
|
+
* <script setup lang="ts">
|
|
788
|
+
* import { ref } from 'vue'
|
|
789
|
+
*
|
|
790
|
+
* const tableRef = ref<CommonTableExpose>()
|
|
791
|
+
*
|
|
792
|
+
* const clearSelection = () => {
|
|
793
|
+
* tableRef.value?.clearSelection()
|
|
794
|
+
* }
|
|
795
|
+
*
|
|
796
|
+
* const toggleRowSelection = (row: UserData) => {
|
|
797
|
+
* tableRef.value?.toggleRowSelection(row, true)
|
|
798
|
+
* }
|
|
799
|
+
* </script>
|
|
800
|
+
* ```
|
|
801
|
+
*/
|
|
541
802
|
export declare interface CommonTableExpose extends TableInstance {
|
|
542
803
|
}
|
|
543
804
|
|
|
544
805
|
/**
|
|
545
806
|
* CommonTable 组件实例暴露类型
|
|
807
|
+
* 提供 Element Plus Table 实例访问
|
|
808
|
+
*
|
|
809
|
+
* @example
|
|
810
|
+
* ```vue
|
|
811
|
+
* <script setup lang="ts">
|
|
812
|
+
* import { ref } from 'vue'
|
|
813
|
+
*
|
|
814
|
+
* const tableRef = ref<CommonTableInstance>()
|
|
815
|
+
*
|
|
816
|
+
* const scrollToBottom = () => {
|
|
817
|
+
* tableRef.value?.elTableRef.value?.scrollTo({
|
|
818
|
+
* top: 10000,
|
|
819
|
+
* behavior: 'smooth'
|
|
820
|
+
* })
|
|
821
|
+
* }
|
|
822
|
+
* </script>
|
|
823
|
+
* ```
|
|
546
824
|
*/
|
|
547
825
|
export declare interface CommonTableInstance {
|
|
548
826
|
/** ElTable 组件实例引用 */
|
|
549
827
|
elTableRef: Ref<TableInstance | undefined>;
|
|
550
828
|
}
|
|
551
829
|
|
|
552
|
-
/**
|
|
830
|
+
/**
|
|
831
|
+
* 表格列对象形式类型
|
|
832
|
+
* 以键值对的方式配置列
|
|
833
|
+
*
|
|
834
|
+
* @typeParam T - 表格数据行类型
|
|
835
|
+
*
|
|
836
|
+
* @example
|
|
837
|
+
* ```ts
|
|
838
|
+
* const columns: CommonTableObjectColumns<UserData> = {
|
|
839
|
+
* name: { prop: 'name', label: '姓名' },
|
|
840
|
+
* age: { prop: 'age', label: '年龄' }
|
|
841
|
+
* }
|
|
842
|
+
* ```
|
|
843
|
+
*/
|
|
553
844
|
declare type CommonTableObjectColumns<T extends AnyObject> = Record<keyof T | (string & {}), CommonTableColumnRoot<T>>;
|
|
554
845
|
|
|
846
|
+
/**
|
|
847
|
+
* CommonTable 组件 Props
|
|
848
|
+
* 基于 Element Plus Table 封装,提供开箱即用的表格功能
|
|
849
|
+
*
|
|
850
|
+
* @typeParam T - 表格数据行类型
|
|
851
|
+
*
|
|
852
|
+
* @example
|
|
853
|
+
* ```vue
|
|
854
|
+
* <template>
|
|
855
|
+
* <CommonTable :columns="columns" :data="tableData" />
|
|
856
|
+
* </template>
|
|
857
|
+
*
|
|
858
|
+
* <script setup lang="ts">
|
|
859
|
+
* import type { CommonTableArrayColumns } from '@yetuzi/vue3-query-components'
|
|
860
|
+
*
|
|
861
|
+
* interface UserData {
|
|
862
|
+
* id: number
|
|
863
|
+
* name: string
|
|
864
|
+
* email: string
|
|
865
|
+
* }
|
|
866
|
+
*
|
|
867
|
+
* const columns: CommonTableArrayColumns<UserData> = [
|
|
868
|
+
* { prop: 'id', label: 'ID', type: 'index' },
|
|
869
|
+
* { prop: 'name', label: '姓名' },
|
|
870
|
+
* { prop: 'email', label: '邮箱' }
|
|
871
|
+
* ]
|
|
872
|
+
*
|
|
873
|
+
* const tableData: UserData[] = [...]
|
|
874
|
+
* </script>
|
|
875
|
+
* ```
|
|
876
|
+
*/
|
|
555
877
|
export declare interface CommonTableProps<T extends AnyObject = AnyObject> extends ExtractPropTypes<Omit<TableProps<T>, 'data' | 'headerCellStyle'>> {
|
|
556
|
-
/**
|
|
878
|
+
/** 表格列配置 */
|
|
557
879
|
columns: CommonTableColumn<T>;
|
|
880
|
+
/** 表格数据 */
|
|
558
881
|
data: T[];
|
|
559
882
|
}
|
|
560
883
|
|
|
@@ -696,48 +1019,132 @@ export declare type RequiredSomeFields<T extends object, K extends keyof T> = Om
|
|
|
696
1019
|
[P in K]-?: T[P];
|
|
697
1020
|
};
|
|
698
1021
|
|
|
699
|
-
/**
|
|
700
|
-
|
|
1022
|
+
/**
|
|
1023
|
+
* 表格列基础接口
|
|
1024
|
+
* 所有列类型的公共属性定义
|
|
1025
|
+
*
|
|
1026
|
+
* @typeParam T - 表格数据行类型
|
|
1027
|
+
*/
|
|
1028
|
+
declare interface TableColumnBase<T extends AnyObject> extends Partial<Omit<TableColumnCtx<T>, 'prop' | 'type'>> {
|
|
1029
|
+
/** 列字段名,支持数据类型的 key 或任意字符串 */
|
|
701
1030
|
prop: keyof T | (string & {});
|
|
702
|
-
|
|
1031
|
+
/** 列类型 */
|
|
1032
|
+
type?: TableColumnType | (string & {});
|
|
703
1033
|
}
|
|
704
1034
|
|
|
705
1035
|
/**
|
|
706
|
-
*
|
|
1036
|
+
* 表格列类型标识
|
|
1037
|
+
* 从 CommonTableColumnRoot 中自动提取 type 字段的类型
|
|
1038
|
+
*
|
|
1039
|
+
* @example
|
|
1040
|
+
* ```ts
|
|
1041
|
+
* let columnType: TableColumnType
|
|
1042
|
+
*
|
|
1043
|
+
* columnType = 'index' // ✓ 索引列
|
|
1044
|
+
* columnType = 'selection' // ✓ 选择列
|
|
1045
|
+
* columnType = 'expand' // ✓ 展开列
|
|
1046
|
+
* columnType = 'date' // ✓ 日期列
|
|
1047
|
+
* columnType = 'dateTime' // ✓ 日期时间列
|
|
1048
|
+
* ```
|
|
707
1049
|
*/
|
|
708
|
-
declare
|
|
709
|
-
|
|
1050
|
+
export declare type TableColumnType = Extract<CommonTableColumnRoot<AnyObject>, {
|
|
1051
|
+
type: any;
|
|
1052
|
+
}>['type'];
|
|
1053
|
+
|
|
1054
|
+
/**
|
|
1055
|
+
* 日期列类型
|
|
1056
|
+
* 自动格式化日期显示
|
|
1057
|
+
*
|
|
1058
|
+
* @typeParam T - 表格数据行类型
|
|
1059
|
+
*
|
|
1060
|
+
* @example
|
|
1061
|
+
* ```ts
|
|
1062
|
+
* const dateColumn: TableColumnTypeDate<UserData> = {
|
|
1063
|
+
* type: 'date',
|
|
1064
|
+
* prop: 'createTime',
|
|
1065
|
+
* label: '创建日期'
|
|
1066
|
+
* }
|
|
1067
|
+
* ```
|
|
1068
|
+
*/
|
|
1069
|
+
declare interface TableColumnTypeDate<T extends AnyObject> extends TableColumnBase<T> {
|
|
710
1070
|
type: 'date';
|
|
711
1071
|
}
|
|
712
1072
|
|
|
713
1073
|
/**
|
|
714
|
-
*
|
|
1074
|
+
* 日期时间列类型
|
|
1075
|
+
* 自动格式化日期时间显示
|
|
1076
|
+
*
|
|
1077
|
+
* @typeParam T - 表格数据行类型
|
|
1078
|
+
*
|
|
1079
|
+
* @example
|
|
1080
|
+
* ```ts
|
|
1081
|
+
* const dateTimeColumn: TableColumnTypeDateTime<UserData> = {
|
|
1082
|
+
* type: 'dateTime',
|
|
1083
|
+
* prop: 'updateTime',
|
|
1084
|
+
* label: '更新时间'
|
|
1085
|
+
* }
|
|
1086
|
+
* ```
|
|
715
1087
|
*/
|
|
716
|
-
declare interface TableColumnTypeDateTime<T extends AnyObject> extends
|
|
717
|
-
/** 时间内容 */
|
|
1088
|
+
declare interface TableColumnTypeDateTime<T extends AnyObject> extends TableColumnBase<T> {
|
|
718
1089
|
type: 'dateTime';
|
|
719
1090
|
}
|
|
720
1091
|
|
|
721
1092
|
/**
|
|
722
|
-
*
|
|
1093
|
+
* 展开列类型
|
|
1094
|
+
* 提供行展开功能
|
|
1095
|
+
*
|
|
1096
|
+
* @typeParam T - 表格数据行类型
|
|
1097
|
+
*
|
|
1098
|
+
* @example
|
|
1099
|
+
* ```ts
|
|
1100
|
+
* const expandColumn: TableColumnTypeExpand<UserData> = {
|
|
1101
|
+
* type: 'expand',
|
|
1102
|
+
* label: '详情'
|
|
1103
|
+
* }
|
|
1104
|
+
* ```
|
|
723
1105
|
*/
|
|
724
|
-
declare interface TableColumnTypeExpand<T extends AnyObject> extends OptionalFields<
|
|
1106
|
+
declare interface TableColumnTypeExpand<T extends AnyObject> extends OptionalFields<TableColumnBase<T>, 'prop'> {
|
|
725
1107
|
type: 'expand';
|
|
726
1108
|
}
|
|
727
1109
|
|
|
728
1110
|
/**
|
|
729
|
-
*
|
|
1111
|
+
* 索引列类型
|
|
1112
|
+
* 自动显示行号
|
|
1113
|
+
*
|
|
1114
|
+
* @typeParam T - 表格数据行类型
|
|
1115
|
+
*
|
|
1116
|
+
* @example
|
|
1117
|
+
* ```ts
|
|
1118
|
+
* const indexColumn: TableColumnTypeIndex<UserData> = {
|
|
1119
|
+
* type: 'index',
|
|
1120
|
+
* label: '序号',
|
|
1121
|
+
* width: 60
|
|
1122
|
+
* }
|
|
1123
|
+
* ```
|
|
730
1124
|
*/
|
|
731
|
-
declare interface TableColumnTypeIndex<T extends AnyObject> extends OptionalFields<
|
|
1125
|
+
declare interface TableColumnTypeIndex<T extends AnyObject> extends OptionalFields<TableColumnBase<T>, 'prop'> {
|
|
732
1126
|
type: 'index';
|
|
733
1127
|
}
|
|
734
1128
|
|
|
735
1129
|
/**
|
|
736
|
-
*
|
|
1130
|
+
* 选择列类型
|
|
1131
|
+
* 提供多选功能
|
|
1132
|
+
*
|
|
1133
|
+
* @typeParam T - 表格数据行类型
|
|
1134
|
+
*
|
|
1135
|
+
* @example
|
|
1136
|
+
* ```ts
|
|
1137
|
+
* const selectionColumn: TableColumnTypeSelection<UserData> = {
|
|
1138
|
+
* type: 'selection',
|
|
1139
|
+
* selectable: (row, index) => row.status === 'active'
|
|
1140
|
+
* }
|
|
1141
|
+
* ```
|
|
737
1142
|
*/
|
|
738
|
-
declare interface TableColumnTypeSelection<T extends AnyObject> extends OptionalFields<
|
|
1143
|
+
declare interface TableColumnTypeSelection<T extends AnyObject> extends OptionalFields<TableColumnBase<T>, 'prop'> {
|
|
739
1144
|
type: 'selection';
|
|
1145
|
+
/** 行可选择的条件函数 */
|
|
740
1146
|
selectable?: (row: T, index: number) => boolean;
|
|
1147
|
+
/** 是否保留之前的选择 */
|
|
741
1148
|
'reserve-selection'?: boolean;
|
|
742
1149
|
}
|
|
743
1150
|
|