mirror of
https://github.com/imdap/ruoyi-plus-vben5.git
synced 2026-04-23 00:38:34 +08:00
100 lines
2.6 KiB
TypeScript
100 lines
2.6 KiB
TypeScript
import type {
|
||
AutoCompleteProps,
|
||
ButtonProps,
|
||
CheckboxGroupProps,
|
||
CheckboxProps,
|
||
DatePickerProps,
|
||
DateRangePickerProps,
|
||
DividerProps,
|
||
InputNumberProps,
|
||
InputProps,
|
||
RadioGroupProps,
|
||
RadioProps,
|
||
SelectProps,
|
||
SpaceProps,
|
||
SwitchProps,
|
||
TextareaProps,
|
||
TimePickerProps,
|
||
TreeSelectProps,
|
||
} from 'tdesign-vue-next';
|
||
import type { TdRateProps } from 'tdesign-vue-next/es/rate/type';
|
||
import type { UploadProps } from 'tdesign-vue-next/es/upload/types';
|
||
|
||
import type { Component } from 'vue';
|
||
|
||
import type {
|
||
ApiComponentSharedProps,
|
||
VbenFormSchema as CoreFormSchema,
|
||
IconPickerProps,
|
||
} from '@vben/common-ui';
|
||
|
||
import type { ComponentType } from './component';
|
||
|
||
type ComponentPropsFnArgs = Parameters<
|
||
Extract<
|
||
NonNullable<CoreFormSchema<ComponentType>['componentProps']>,
|
||
(...args: any) => any
|
||
>
|
||
>;
|
||
|
||
/**
|
||
* 使用适配器里为各 `component` 声明的 Props 类型 `P`;
|
||
* 与 `Record<string, any>` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。
|
||
*/
|
||
type ComponentProps<P> =
|
||
| ((
|
||
value: ComponentPropsFnArgs[0],
|
||
actions: ComponentPropsFnArgs[1],
|
||
) => P & Record<string, any>)
|
||
| (P & Record<string, any>);
|
||
|
||
/**
|
||
* 与 {@link ComponentType} 中注册的组件名一一对应,便于 Schema 上 `component` + `componentProps` 联动提示
|
||
*/
|
||
interface ComponentPropsMap {
|
||
ApiSelect: ApiComponentSharedProps & SelectProps;
|
||
ApiTreeSelect: ApiComponentSharedProps & TreeSelectProps;
|
||
AutoComplete: AutoCompleteProps;
|
||
Checkbox: CheckboxProps;
|
||
CheckboxGroup: CheckboxGroupProps;
|
||
DatePicker: DatePickerProps;
|
||
DefaultButton: ButtonProps;
|
||
Divider: DividerProps;
|
||
IconPicker: IconPickerProps;
|
||
Input: InputProps;
|
||
InputNumber: InputNumberProps;
|
||
PrimaryButton: ButtonProps;
|
||
Radio: RadioProps;
|
||
RadioGroup: RadioGroupProps;
|
||
RangePicker: DateRangePickerProps;
|
||
Rate: TdRateProps;
|
||
Select: SelectProps;
|
||
Space: SpaceProps;
|
||
Switch: SwitchProps;
|
||
Textarea: TextareaProps;
|
||
TimePicker: TimePickerProps;
|
||
TreeSelect: TreeSelectProps;
|
||
Upload: UploadProps;
|
||
}
|
||
|
||
type BaseSchema = Omit<
|
||
CoreFormSchema<ComponentType>,
|
||
'component' | 'componentProps'
|
||
>;
|
||
|
||
type RegisteredName = keyof ComponentPropsMap;
|
||
|
||
type DiscriminatedFormSchema = {
|
||
[K in RegisteredName]: BaseSchema & {
|
||
component: K;
|
||
componentProps?: ComponentProps<ComponentPropsMap[K]>;
|
||
};
|
||
}[RegisteredName];
|
||
|
||
type FallbackFormSchema = BaseSchema & {
|
||
component: Component | Exclude<ComponentType, RegisteredName>;
|
||
componentProps?: CoreFormSchema<ComponentType>['componentProps'];
|
||
};
|
||
|
||
export type VbenFormSchema = DiscriminatedFormSchema | FallbackFormSchema;
|