import type { FormInstance } from 'antd'; import type { NamePath } from 'antd/es/form/interface'; /** * 单元格规则装配 + 全量数据真实校验(脱离 DOM)。 * * 背景:antd6 虚拟表格滚动时视口外的行会被卸载,其 Form.Item 字段未注册, * form.validateFields 无法覆盖;本模块用 form store 里的全量数据 + 真实规则 * 逐行逐列离屏校验,解决「统一校验」缺口,并产出可常驻的真实报错文案。 */ interface BuildCellRulesParams { column: any; rowData: any; index: number; form: FormInstance; name: (string | number)[]; config: any; } interface BuiltCellRule { /** 单元格 Form.Item 的 namePath(用于定位/messageVariables) */ namePath: (string | number)[]; /** 列在行内的稳定标识(与 transformColumns 的 dataIndex/key 一致),用于错误存储归集 */ cellKey: string; /** 待校验值(names 列为组合数组) */ value: any; /** 真实规则集合 */ rules: any[]; /** 字段 label,供 ${label} 文案插值 */ label: string; } /** * 为单行单列装配真实校验规则与取值。 * 当该单元格处于查看/禁用态、或无任何规则时返回 null(跳过校验)。 */ export declare const buildCellRules: ({ column, rowData, index, form, name, config, }: BuildCellRulesParams) => BuiltCellRule | null; interface ValidateAllParams { form: FormInstance; name: NamePath; columns: any[]; config: any; } export interface ValidateAllResult { hasError: boolean; /** rowKey -> { cellKey -> 错误文案数组 } */ errorMap: Record>; /** 首个错误单元格的 namePath(用于滚动定位),无错误为 null */ firstErrorPath: (string | number)[] | null; /** 首个错误行的 rowKey(用于横向滚动时定位错误行 DOM),无错误为 null */ firstErrorRowKey: string | null; /** 首个错误列的 cellKey(names 列为 splitNames,普通列为列名),用于横向滚动定位列,无错误为 null */ firstErrorColumnKey: string | null; } /** * 对 form store 中 name 路径下的全量数组数据,逐行逐列用真实规则校验(脱离 DOM)。 */ export declare const validateAllRows: ({ form, name, columns, config, }: ValidateAllParams) => Promise; /** * 外部错误存储:以 rowKey + cellKey 为键持久化真实报错文案。 * 它是「报错常驻」的真实来源——脱离 antd Field 实体生命周期, * 行卸载后仍保留,重新挂载时回填显示。 */ export interface ErrorStore { /** 读取某单元格错误文案 */ get(rowKey: string | number, cellKey: string): string[] | undefined; /** 读取整行错误 */ getRow(rowKey: string | number): Record | undefined; /** 全量替换(来自一次完整校验) */ setAll(errorMap: Record>): void; /** 清理某单元格(用户修正后调用),整行清空时移除该行 */ clearCell(rowKey: string | number, cellKey: string): void; /** 清空所有 */ clearAll(): void; /** 是否为空 */ isEmpty(): boolean; } export declare const createErrorStore: () => ErrorStore; interface RunUnifiedParams extends ValidateAllParams { errorStore: ErrorStore; } /** * 统一校验入口:对全量数据跑真实规则,写入 errorStore,返回是否有错与首个错误行索引。 * 供隐藏聚合校验字段在 form.validateFields() 时调用,从而覆盖视口外未挂载的行。 */ export declare const runUnifiedValidation: ({ form, name, columns, config, errorStore, }: RunUnifiedParams) => Promise<{ hasError: boolean; firstErrorIndex: number | null; firstErrorRowKey: string | null; firstErrorColumnKey: string | null; }>; export {};