import { Get, PartialDeep } from 'type-fest'; import { ComputedRef, Ref } from 'vue'; import { StringKeyof } from '../utils/types'; import { InternalPath } from './path'; import { FieldStore } from './store/fieldStore'; import { ValueStore } from './store/valueStore'; import { ValueMergeStrategy } from './utils/value'; export interface FormOptions { /** * 取 fieldsValue 值时是否清空 null 和 undefined 的数据 * @default true */ omitNil?: boolean; /** * 取 fieldsValue 值时是否清空空字符串的值 * @default true */ omitEmptyString?: boolean; /** * 表单初始值 */ initialValues?: Values; /** * 字段值发生变化后的回调(手动交互才会触发) * @param value 变化后的值 * @param path 字段路径 */ onValueChange?: (opt: { value: any; path: string; }) => void; } export interface BaseForm { /** * 内部使用 */ _: { valueStore: ValueStore; fieldStore: FieldStore; }; /** * 唯一标识 */ id: string; /** * 表单是否挂载完成 */ mounted: Ref; /** * 表单值和用户设置的(包括隐藏的) */ values: Ref; /** * 表单值 */ fieldsValue: ComputedRef; /** * 重置指定路径字段的值 */ resetFieldValue: >(path: T) => void; /** * 重置所有字段的值 */ resetFieldsValue: () => void; /** * 设置指定路径字段的初始值 */ setInitialValue: >(path: T, value: Get) => void; /** * 设置一组初始值 */ setInitialValues: (values: PartialDeep, strategy?: ValueMergeStrategy) => void; }