import type { CSSProperties } from 'vue'; import type { Rule } from 'ant-design-vue/es/form'; import type { AutoCompleteProps, ButtonProps, CascaderProps, CheckboxProps, DatePickerProps, DividerProps, InputNumberProps, InputProps, RadioProps, SelectProps, SwitchProps, TextAreaProps, TimePickerProps, TimeRangePickerProps, TreeSelectProps, UploadProps } from 'ant-design-vue'; export type { UploadFile } from 'ant-design-vue'; export type EventName = 'submit' | 'reset'; export type AntTag = 'input' | 'inputNumber' | 'inputPassword' | 'inputSearch' | 'select' | 'upload' | 'button' | 'textarea' | 'datePicker' | 'rangePicker' | 'cascader' | 'treeSelect' | 'timePicker' | 'switch' | 'divider' | 'radio' | 'checkbox' | 'autoComplete'; export interface ButtonConfig extends ButtonProps { } export interface AutoCompleteConfig extends AutoCompleteProps { filterOption?: (input: string, option: { value: string; }) => boolean; } export interface InputConfig extends InputProps { } export interface SelectConfig extends SelectProps { btnStyle?: CSSProperties; } export interface UploadConfig extends UploadProps { url?: string; compress?: boolean | { type?: 'image/png' | 'image/jpeg' | 'image/jpg'; quality?: number; }; tips?: string; tipsStyle?: CSSProperties; limit?: number; btnText?: string; btnProps?: ButtonProps; btnStyle?: CSSProperties; } export type DatePickerConfig = DatePickerProps; export interface SwitchConfig extends SwitchProps { checkedValue?: boolean | string | number; unCheckedValue?: boolean | string | number; checkedChildren?: string; unCheckedChildren?: string; } export interface RadioConfig extends RadioProps { } export interface CheckboxConfig extends CheckboxProps { } export interface InputNumberConfig extends InputNumberProps { } export interface CascaderConfig extends CascaderProps { } export interface TextareaConfig extends TextAreaProps { } export interface DividerConfig extends DividerProps { } export interface TreeSelectConfig extends TreeSelectProps { } export interface TimePickerConfig extends TimePickerProps { } export interface RangePickerConfig extends TimeRangePickerProps { } export interface FormConfig> { tag?: AntTag; label?: string; labelCol?: { span?: number; offset?: number; style?: CSSProperties; }; previewText?: (value: any) => string; labelAlign?: 'left' | 'right'; className?: string; width?: string | number; tagWidth?: string | number; isHidden?: boolean; rules?: Rule[]; field?: keyof T; defaultValue?: unknown; step?: number; slotName?: string; previewSlot?: string; previewClassName?: string; eventName?: EventName; component?: FormComponent; children?: { id: string | number; formConfig: FormConfig[]; }[]; } export type FormComponent = ComponentEvents & T extends 'input' ? InputConfig : T extends 'select' ? SelectConfig : T extends 'upload' ? UploadConfig : T extends 'timePicker' ? TimePickerConfig : T extends 'button' ? ButtonConfig : T extends 'autoComplete' ? AutoCompleteConfig : T extends 'datePicker' ? DatePickerConfig : T extends 'rangePicker' ? RangePickerConfig : T extends 'cascader' ? CascaderConfig : T extends 'divider' ? DividerConfig : T extends 'inputNumber' ? InputNumberConfig : T extends 'checkbox' ? CheckboxConfig : T extends 'textarea' ? TextareaConfig : T extends 'switch' ? SwitchConfig : T extends 'radio' ? RadioConfig : T extends 'treeSelect' ? TreeSelectConfig : Record; interface ComponentEvents { onKeydown?: (e: T) => void; onBlur?: (e: T) => void; onClick?: (e: T) => void; } export interface FieldChange { event: any; field: string; value: V; tag: AntTag; /** * 更新表单的某个 config * @param field 要更新的 config 的 field 属性值 * @param keys 要更新的字段名称。 如 'component.options' * @param value 要更新的字段的值 * @example - 比如:updateConfig('sex', 'component.options', ['man', 'woman']) 表示更新 field 为 sex 的 config 的 component.options 为 ['man', 'woman'] */ updateConfig: (field: string, keys: string, value: unknown) => void; fields: T; } export interface FieldBlur extends FieldChange { } export interface FieldClick { validate: (FieldNames?: string[]) => Promise; resetFields: (FieldNames?: string[]) => void; data?: T; eventName: string; event?: Event; }