UNPKG

@aplus-frontend/ui

Version:

337 lines (336 loc) 10.3 kB
import { ButtonProps, ColProps, DrawerProps, FormItemProps, FormProps, ModalProps, RowProps } from '@aplus-frontend/antdv'; import { FormItemExpose } from '@aplus-frontend/antdv/es/form/FormItem'; import { InternalNamePath, NamePath, ValidateOptions } from '@aplus-frontend/antdv/es/form/interface'; import { LiteralUnion, Recordable } from '../type'; import { VNode } from 'vue'; import { BreakPointType } from './search-form/hooks/use-count-per-row'; export type { ApFormChangeInfo, ApFormFinishInfo } from './provider/interface'; export type ApFormColProps = Omit<ColProps, 'prefixCls'>; export type ApFormItemTransformFn = (value: any) => any; export type ApFormItemTransformType = ApFormItemTransformFn | { transformer: ApFormItemTransformFn; /** * 是否进行扁平化处理(只向上扁平化一层) */ flat?: boolean; }; export type ApFormItemProps = FormItemProps & Partial<ApFormColProps> & { /** * 是否展示包含了输入框&label的border */ bordered?: boolean; valuePropName?: string; /** * 表单项的默认值(只生效一次),支持传入异步函数 */ initialValue?: any; /** * 内部使用,请勿传入 */ _signal?: number; /** * 数据转换(提交/或者手动调用时才会) * @param value * @returns */ transform?: ApFormItemTransformType; tooltip?: any; /** * 此表单项的描述,设置此信息后,在查询表单排序时将优先使用此属性值 */ description?: string; /** * 自定义表单是否输入值校验,用于查询表单收起表单项的输入表单数量角标显示 * @param value * @returns */ customFilled?: (value: any) => boolean; /** * 是否禁用,禁用时将会有特殊样式,配合bordered=true使用生效 */ disabled?: boolean; }; export type ApFormItemGroupProps = RowProps & { countPerRow?: number; }; export type ApFormProps = Omit<FormProps, 'model' | 'onValuesChange'> & { initialValues?: Recordable; /** * 字段值更新时触发 * @param changedValues 更改的字段值 * @param allValues 更改后的字段值 * @param fieldName 触发change的表单项 * @returns */ onValuesChange?: (changedValues: Recordable, allValues: Recordable, fieldName: NamePath) => void; /** * 同步表单数据到url中 */ syncToUrl?: boolean | ((values: Recordable, type: 'get' | 'set') => Recordable); /** * syncToUrl和initialValues合并是否优先,默认为false */ syncToUrlPriority?: boolean; }; export type WatchFunc = (values?: Recordable) => void; export type UpdateModelOptimizeFn = (currentModelValue: any, name: string | number) => void; export type ApFormExpose<ModelType = any> = { setFieldsValue: (fields: Partial<ModelType>) => void; setFieldValue: (name: NamePath, value: any, triggerChange?: boolean, optimizeFn?: UpdateModelOptimizeFn) => void; resetFields: () => Promise<void>; clearValidate: (name?: NamePath) => void; validateFields: (nameList?: NamePath[] | string, options?: ValidateOptions) => Promise<Partial<ModelType>> | undefined; getFieldsValue: (nameList?: true | InternalNamePath[]) => Partial<ModelType> | undefined; validate: (nameList?: NamePath[] | string, options?: ValidateOptions) => Promise<Partial<ModelType>> | undefined; scrollToField: (name: NamePath, options?: any) => void; /** * 内部使用,请勿在外部通过Form实例调用 * @param mark 内部使用的标记 * @returns */ getInternalInstance: (mark: string) => ApFormInternalInstance | undefined; /** * 校验表单并返回转换后的数据 * @param nameList * @param options * @returns */ validateFieldsReturnTransformed: (nameList?: NamePath[] | string, options?: ValidateOptions) => Promise<Partial<ModelType>> | undefined; /** * 获取表单数据并转换 * @param nameList * @returns */ getFieldsValueTransformed: (nameList?: true | InternalNamePath[]) => Partial<ModelType> | undefined; registerWatch: (callback: WatchFunc, inner: boolean) => () => void; }; /** * 被注册的表单项 */ export type RegistedFieldType = { name: FormItemProps['name']; initialValue?: any; transform?: ApFormItemTransformType; }; export type ApFormInternalInstance = { /** * 注册字段watch * @param callback * @param inner * @returns */ registerWatch: (callback: WatchFunc, inner?: boolean) => () => void; /** * 注册表单项 * @param field * @returns */ registerField: (field: RegistedFieldType) => void; /** * 设置表单值 * @param name * @param value * @param triggerChange * @returns */ setFieldValue: (name: NamePath, value: any, triggerChange?: boolean, optimizeFn?: UpdateModelOptimizeFn) => void; /** * 获取表单的初始值(随着表单项组件的注册,initialValues可能会发生改变) * @returns */ getInitialValues: () => Recordable; }; export type ApFormItemExpose = FormItemExpose & { /** * 是否需要格式化(默认为false) * @param shouldFormat * @returns */ getFieldValue: (shouldFormat?: boolean) => any; }; export type SearchFormResizeConfig = { target?: LiteralUnion<'document' | 'form', string>; breakPoint?: BreakPointType; }; export type ApFormListProps = { name: FormItemProps['name']; /** * 设置FormList的默认值 */ initialValue?: any[]; transform?: ApFormItemTransformType; }; export type ApFormSearchFormProps = ApFormProps & { collapse?: boolean; defaultCollapse?: boolean; 'onUpdate:collapse'?: (collapse?: boolean) => void; searchText?: string; resetText?: string; onSubmit?: (values: any) => void; onReset?: () => void; customReset?: boolean; extraInAction?: boolean; forceExpand?: boolean; countPerRow?: number; submitLoading?: boolean; /** * 最大显示的行(超出后将会收起进入更多筛选) */ maxRows?: number; /** * 是否可排序 */ sortable?: boolean; /** * 尺寸监听目标元素(用于响应式) * @deprecated use `resize` instead. */ resizeTarget?: HTMLElement | null; /** * 尺寸变化配置项 * @since 6.35.3 */ resize?: SearchFormResizeConfig; /** * 查询按钮loading延迟(默认300ms) */ loadingDelay?: number; }; export type SearchFormRenderNodeConfig = { node: VNode; key: string; span: number; }; export type ApFormSearchFormPopoverFilterProps = { config: SearchFormRenderNodeConfig[]; onSubmit: () => void; submitLoading: boolean; }; export type ApFormSearchFormPopoverSorterItem = { name: string; label: string; isHidden?: boolean; }; export type ApFormSearchFormPopoverSorterProps = { /** * 需要排序的节点对象 */ items: ApFormSearchFormPopoverSorterItem[]; /** * 点击确定 * @param sortedChildren * @returns */ onClickConfirm: (sortedChildren: ApFormSearchFormPopoverSorterItem[]) => void; /** * 当前的children是否已经排序过了 */ sorted?: boolean; }; export type ApFormSearchFormExpose = { apForm: ApFormExpose; /** * 获取排序结果 * @returns */ getSorterItems: () => ApFormSearchFormPopoverSorterItem[]; /** * 设置排序结果 * @param sortedItems * @returns */ setSorterItems: (sortedItems: ApFormSearchFormPopoverSorterItem[]) => void; /** * 重设查询表单排序 */ resetSorterItems: () => void; }; export type ApFormSubmitterConfig = { submitText?: string; resetText?: string; onSubmit?: () => void; onReset?: () => void; submitButtonProps?: false | Partial<ButtonProps>; resetButtonProps?: false | Partial<ButtonProps>; }; export type ApFormModalFormProps = Omit<ApFormProps, 'onFinish'> & { open?: boolean; 'onUpdate:open'?: (open: boolean) => void; modalProps?: Omit<ModalProps, 'open' | 'onUpdate:open' | 'visible'>; title?: string; width?: number; onFinish?: (values: any) => Promise<boolean>; submitter?: false | ApFormSubmitterConfig; showCancel?: boolean; /** * 提交超时时间 */ submitTimeout?: number; }; export type CustomizeResizeType = { onResize?: () => void; maxWidth?: DrawerProps['width']; minWidth?: DrawerProps['width']; resizeOnOpen?: boolean; }; export type ApFormDrawerFormProps = Omit<ApFormProps, 'onFinish'> & { open?: boolean; 'onUpdate:open'?: (open: boolean) => void; drawerProps?: Omit<DrawerProps, 'open' | 'onUpdate:open'>; title?: DrawerProps['title']; width?: DrawerProps['width']; onFinish?: (values: any) => Promise<boolean>; submitter?: false | ApFormSubmitterConfig; showCancel?: boolean; /** * 提交超时时间 */ submitTimeout?: number; /** * 可拖动改变drawer的尺寸 */ resize?: CustomizeResizeType | boolean; }; export type ApFormModalFormExpose = Omit<ApFormExpose, 'registerWatch'>; export type ApFormDrawerFormExpose = ApFormModalFormExpose; /** * ApFormItem支持的插槽 */ export type ApFormItemSlots = { help?: any; label?: any; extra?: any; default: () => VNode[]; }; export type ApFormDependencyProps = { nameList: NamePath[]; }; export type ApFormSetProps = { /** * 需要聚合成的字段名 */ name: NamePath; /** * 聚合成(数组/对象) */ as?: 'array' | 'object'; /** * 默认值 */ initialValue?: any; /** * 转换函数(表单提交时触发) * @param value * @returns */ transform?: ApFormItemTransformType; }; export type ApFormControlRenderProps = { value?: any; 'onUpdate:value'?: (value: any, ...args: any[]) => void; bordered?: boolean; onFocus?: () => void; onBlur?: () => void; [key: string]: any; }; export type ApFormItemRenderProps = ApFormItemProps;