import { RenderFunction, SetupContext, Ref, ComputedRef } from 'vue' import { DefineVxeComponentApp, DefineVxeComponentOptions, DefineVxeComponentInstance, VxeComponentBaseOptions, VxeComponentEventParams, VxeComponentSizeType, ValueOf, VxeComponentSlotType, VxeComponentAlignType } from '@vxe-ui/core' import { VxeFormItemPropTypes, VxeFormItemProps } from './form-item' import { VxeGridConstructor } from './grid' /* eslint-disable no-use-before-define,@typescript-eslint/ban-types */ export declare const VxeForm: DefineVxeComponentApp export type VxeFormComponent = DefineVxeComponentOptions, VxeFormEventProps> export type VxeFormInstance = DefineVxeComponentInstance, VxeFormConstructor> export interface VxeFormConstructor extends VxeComponentBaseOptions, VxeFormMethods { props: VxeFormProps context: SetupContext reactData: FormReactData internalData: FormInternalData getRefMaps(): FormPrivateRef getComputeMaps(): FormPrivateComputed renderVN: RenderFunction xeGrid: VxeGridConstructor | null } export interface FormPrivateRef { refElem: Ref } export interface VxeFormPrivateRef extends FormPrivateRef {} export namespace VxeFormPropTypes { export type Size = VxeComponentSizeType export type CollapseStatus = boolean export type Loading = boolean export type Data = any export type Span = string | number export type Align = VxeComponentAlignType export type VerticalAlign = 'center' | '' | null export type Border = boolean export type TitleBackground = boolean export type TitleBold = boolean export type TitleAlign = VxeComponentAlignType export type TitleWidth = string | number export type TitleColon = boolean export type TitleAsterisk = boolean export type TitleOverflow = boolean | 'ellipsis' | 'title' | 'tooltip' | '' | null export type Vertical = boolean export type Padding = boolean interface ClassNameParams { $form: VxeFormConstructor data: any items: VxeFormDefines.ItemInfo[] } export type ClassName = string | ((params: ClassNameParams) => string) export type Items = VxeFormItemProps[] export type Readonly = boolean export type Disabled = boolean /** * 校验规则配置项 */ export interface Rules { [field: string]: VxeFormDefines.FormRule[] } export type PreventSubmit = boolean export type ValidConfig = { autoPos?: boolean /** * 当校验不通过时在对应项显示错误提示 */ showErrorMessage?: boolean /** * 是否显示错误项背景色 */ showErrorBackground?: boolean /** * 当校验不通过时在对应项显示错误图标 */ showErrorIcon?: boolean /** * 自定义错误图标 */ errorIcon?: boolean /** * 提示消息主题样式 */ theme?: 'normal' | 'beautify' | '' /** * 已废弃,被 showErrorMessage 替换 * @deprecated */ showMessage?: boolean } /** * 提示信息配置项 */ export interface TooltipConfig { theme?: 'dark' | 'light' enterable?: boolean leaveDelay?: number leaveMethod?: (params: { $event: Event }) => boolean } export interface CollapseConfig { foldIcon?: string unfoldIcon?: string foldButtonText?: string unfoldButtonText?: string } export type CustomLayout = boolean /** * 额外的参数 */ export type Params = any } export interface VxeFormProps { size?: VxeFormPropTypes.Size collapseStatus?: VxeFormPropTypes.CollapseStatus loading?: VxeFormPropTypes.Loading data?: D span?: VxeFormPropTypes.Span align?: VxeFormPropTypes.Align verticalAlign?: VxeFormPropTypes.VerticalAlign border?: VxeFormPropTypes.Border titleBackground?: VxeFormPropTypes.TitleBackground titleBold?: VxeFormPropTypes.TitleBold titleAlign?: VxeFormPropTypes.TitleAlign /** * 所有标题默认宽度,支持 px,auto */ titleWidth?: VxeFormPropTypes.TitleWidth titleColon?: VxeFormPropTypes.TitleColon titleAsterisk?: VxeFormPropTypes.TitleAsterisk titleOverflow?: VxeFormPropTypes.TitleOverflow vertical?: VxeFormPropTypes.Vertical padding?: VxeFormPropTypes.Padding className?: VxeFormPropTypes.ClassName readonly?: VxeFormPropTypes.Readonly disabled?: VxeFormPropTypes.Disabled items?: VxeFormPropTypes.Items rules?: VxeFormPropTypes.Rules preventSubmit?: VxeFormPropTypes.PreventSubmit validConfig?: VxeFormPropTypes.ValidConfig tooltipConfig?: VxeFormPropTypes.TooltipConfig collapseConfig?: VxeFormPropTypes.CollapseConfig customLayout?: VxeFormPropTypes.CustomLayout /** * 额外的参数 */ params?: VxeFormPropTypes.Params } export interface FormPrivateComputed { computeSize: ComputedRef computeValidOpts: ComputedRef computeTooltipOpts: ComputedRef computeCollapseOpts: ComputedRef computeAutoItemWidthList: ComputedRef } export interface VxeFormPrivateComputed extends FormPrivateComputed {} export interface FormReactData { collapseAll: boolean staticItems: any[] formItems: VxeFormDefines.ItemInfo[] itemWidth: number } export interface FormInternalData { meTimeout: undefined | number stTimeout: undefined | number tooltipStore: { item: VxeFormDefines.ItemInfo | null visible: boolean } itemFormatCache: Record< string, { field: string formatData?: { value?: any label?: any } } > fullItemList: VxeFormDefines.ItemInfo[] fullItemIdData: Record fullItemFieldData: Record } export interface FormMethods { dispatchEvent(type: ValueOf, params: Record, evnt: Event | null): void /** * 重置表单 */ reset(): Promise /** * 对表单进行校验,参数为一个回调函数。该回调函数会在校验结束后被调用 callback(errMap)。若不传入回调函数,则会返回一个 promise * @param callback 回调函数 */ validate(callback?: (errMap?: VxeFormDefines.ValidateErrorMapParams) => void): Promise /** * 对表单指定项进行校验,参数为一个回调函数。该回调函数会在校验结束后被调用 callback(errMap)。若不传入回调函数,则会返回一个 promise * @param field 字段名 * @param callback 回调函数 */ validateField(field: VxeFormItemPropTypes.Field | VxeFormItemPropTypes.Field[] | VxeFormDefines.ItemInfo | VxeFormDefines.ItemInfo[] | null, callback?: (errMap?: VxeFormDefines.ValidateErrorMapParams) => void): Promise /** * 手动清除校验状态,如果指定 field 则清除指定的项,否则清除整个表单 * @param field 字段名 */ clearValidate(field?: VxeFormItemPropTypes.Field | VxeFormItemPropTypes.Field[] | VxeFormDefines.ItemInfo | VxeFormDefines.ItemInfo[] | null): Promise /** * 更新项状态 * 当使用自定义渲染时可能会用到 */ updateStatus( params: { field: VxeFormItemPropTypes.Field }, itemValue?: any ): void /** * 已废弃,被 getFlatItems 替换 * @deprecated */ getItems(): VxeFormDefines.ItemInfo[] /** * 获取扁平化的项列表 */ getFlatItems(): VxeFormDefines.ItemInfo[] /** * 获取配置项,与 items 一致 */ getNestedItems(): VxeFormDefines.ItemInfo[] /** * 加载表单项 */ loadItems(items: VxeFormPropTypes.Items | VxeFormDefines.ItemInfo[]): Promise /** * 隐藏指定项 */ hideItem(fieldOrItems?: VxeFormItemPropTypes.Field | VxeFormItemPropTypes.Field[] | VxeFormDefines.ItemInfo | VxeFormDefines.ItemInfo[] | null): Promise /** * 显示指定项 */ showItem(fieldOrItems?: VxeFormItemPropTypes.Field | VxeFormItemPropTypes.Field[] | VxeFormDefines.ItemInfo | VxeFormDefines.ItemInfo[] | null): Promise /** * 根据项的字段名获取表单项 */ getItemByField(field: VxeFormItemPropTypes.Field): VxeFormDefines.ItemInfo | null /** * 手动关闭 tooltip 提示 */ closeTooltip(): Promise /** * 手动切换折叠状态 */ toggleCollapse(): Promise /** * 重新计算表单 */ recalculate(): Promise } export interface VxeFormMethods extends FormMethods {} export interface FormPrivateMethods { /** * @private */ callSlot(slotFunc: ((params: T) => VxeComponentSlotType | VxeComponentSlotType[]) | string | null, params: T): VxeComponentSlotType[] /** * @private */ triggerItemEvent(evnt: Event | { type: string }, field: string, itemValue?: any): Promise /** * @private */ toggleCollapseEvent(evnt: Event): void /** * @private */ triggerTitleTipEvent( evnt: MouseEvent, params: { item: VxeFormDefines.ItemInfo } ): void handleSubmitEvent(evnt: Event): void /** * @private */ handleTitleTipLeaveEvent(): void /** * @private */ handleValidIconEvent( evnt: Event, params: { item: VxeFormDefines.ItemInfo } ): void } export interface VxeFormPrivateMethods extends FormPrivateMethods {} export type VxeFormEmits = ['update:collapseStatus', 'collapse', 'toggle-collapse', 'submit', 'submit-invalid', 'reset'] export namespace VxeFormDefines { export interface ItemCacheItem { item: ItemInfo index: number items: ItemInfo[] } export class ItemInfo { id: string title: VxeFormItemPropTypes.Title field: VxeFormItemPropTypes.Field span: VxeFormItemPropTypes.Span align: VxeFormItemPropTypes.Align verticalAlign: VxeFormItemPropTypes.VerticalAlign titleBackground: VxeFormItemPropTypes.TitleBold titleBold: VxeFormItemPropTypes.TitleBold titleAlign: VxeFormItemPropTypes.TitleAlign titleWidth: VxeFormItemPropTypes.TitleWidth titleColon: VxeFormItemPropTypes.TitleColon titleAsterisk: VxeFormItemPropTypes.TitleAsterisk titlePrefix: VxeFormItemPropTypes.TitlePrefix titleSuffix: VxeFormItemPropTypes.TitleSuffix titleOverflow: VxeFormItemPropTypes.TitleOverflow showTitle: VxeFormItemPropTypes.ShowTitle vertical: VxeFormItemPropTypes.Vertical padding: VxeFormItemPropTypes.Padding resetValue: VxeFormItemPropTypes.ResetValue visibleMethod: VxeFormItemPropTypes.VisibleMethod visible: VxeFormItemPropTypes.Visible showContent: VxeFormItemPropTypes.ShowContent folding: VxeFormItemPropTypes.Folding collapseNode: VxeFormItemPropTypes.CollapseNode className: VxeFormItemPropTypes.ClassName contentClassName: VxeFormItemPropTypes.ContentClassName contentStyle: VxeFormItemPropTypes.ContentStyle titleClassName: VxeFormItemPropTypes.TitleClassName titleStyle: VxeFormItemPropTypes.TitleStyle readonly: VxeFormItemPropTypes.Readonly itemRender: VxeFormItemPropTypes.ItemRender rules: VxeFormItemPropTypes.Rules formatter: VxeFormItemPropTypes.Formatter params: any // 渲染属性 showError: boolean showIconMsg: boolean errRule: any slots: VxeFormItemPropTypes.Slots children: ItemInfo[] } export interface FormRule { /** * 是否必填 */ required?: boolean /** * 最小长度/值 */ min?: number /** * 最大长度/值 */ max?: number /** * 指定字段 */ field?: string /** * 数据类型 */ type?: 'number' | 'string' | 'array' | '' | null /** * 使用正则表达式校验 */ pattern?: string | RegExp /** * 使用自定义校验函数,接收一个 Promise * @param params 参数 */ validator?: string | ((params: RuleValidatorParams) => void | Error | Promise) /** * 提示消息 */ content?: string trigger?: 'change' | '' | null maxWidth?: number /** * @deprecated 已废弃,请使用 content */ message?: string } export interface RuleValidatorParams { $form: VxeFormConstructor itemValue: any rule: VxeFormDefines.FormRule rules: VxeFormDefines.FormRule[] data: D field: string } export interface ValidateErrorParams { $form: VxeFormConstructor rule: VxeFormDefines.FormRule data: any field: string /** * @deprecated */ property: string } export interface ProvideItemInfo { itemConfig: ItemInfo } export interface ValidateErrorMapParams { [field: string]: ValidateErrorParams[] } interface FormEventParams extends VxeComponentEventParams { $form: VxeFormConstructor } interface FormBaseParams { data: D } export interface CollapseParams extends FormBaseParams {} export interface CollapseEventParams extends FormEventParams, CollapseParams {} export interface SubmitParams extends FormBaseParams {} export interface SubmitEventParams extends FormEventParams, SubmitParams {} export interface SubmitInvalidParams extends FormBaseParams {} export interface SubmitInvalidEventParams extends FormEventParams, SubmitInvalidParams {} export interface ResetParams extends FormBaseParams {} export interface ResetEventParams extends FormEventParams, ResetParams {} } export type VxeFormEventProps = { onCollapse?: VxeFormEvents.Collapse onSubmit?: VxeFormEvents.Submit onSubmitInvalid?: VxeFormEvents.SubmitInvalid onReset?: VxeFormEvents.Reset } export interface VxeFormListeners { collapse?: VxeFormEvents.Collapse submit?: VxeFormEvents.Submit submitInvalid?: VxeFormEvents.SubmitInvalid reset?: VxeFormEvents.Reset } export namespace VxeFormEvents { export type Collapse = (params: VxeFormDefines.CollapseEventParams) => void export type Submit = (params: VxeFormDefines.SubmitEventParams) => void export type SubmitInvalid = (params: VxeFormDefines.SubmitInvalidEventParams) => void export type Reset = (params: VxeFormDefines.ResetEventParams) => void } export namespace VxeFormSlotTypes { export interface DefaultSlotParams {} } export interface VxeFormSlots { /** * 自定义插槽模板 */ [key: string]: | ((params: { $form: VxeFormConstructor [key: string]: any }) => any) | undefined default: (params: VxeFormSlotTypes.DefaultSlotParams) => any } export const Form: typeof VxeForm export default VxeForm