fix(validate): 错误信息不再拼开发用的 [path],回归干净字段名+i18n
校验错只发 {t:i18nKey, params:{field:label}}(不能为空走语言包 key、字段名走 label),
不把 groups.0.title 这种路径塞进可见文案。path 仍递归传递,留给将来 inline 标红结构化携带。
This commit is contained in:
@@ -193,7 +193,9 @@ export class ShrimpTableModule<T, P extends ITableCrudProto<T> = ITableCrudProto
|
||||
/** 递归校验:本节点 validateField,出错即抛(带 path);再下钻复合(tab/object/array)子节点。第一版 fail-fast */
|
||||
private async validateNode(field: IFieldConfig, value: any, path: (string | number)[], rootItem: Record<string, any>): Promise<void> {
|
||||
const err = await this.validateField(field, value, rootItem)
|
||||
if (err) throw new ShrimpError(this.errWithPath(err, path))
|
||||
// 出错只发字段名(label) + i18n key 的 message,不把开发用的 path 拼进可见文案。
|
||||
// path 仍递归往下传(供将来 inline 标红按结构化方式携带,不在这里塞进 message)。
|
||||
if (err) throw new ShrimpError(err)
|
||||
for (const child of this.childrenOf(field, value)) {
|
||||
await this.validateNode(child.field, child.value, [...path, child.key], rootItem)
|
||||
}
|
||||
@@ -215,14 +217,6 @@ export class ShrimpTableModule<T, P extends ITableCrudProto<T> = ITableCrudProto
|
||||
return []
|
||||
}
|
||||
|
||||
/** 嵌套字段出错时把 path 缀进 message(顶层不缀,已有字段名),让用户知道是哪个嵌套位置 */
|
||||
private errWithPath(err: ILabel, path: (string | number)[]): ILabel {
|
||||
if (path.length <= 1 || typeof err !== "object" || err === null) return err
|
||||
const e = err as any
|
||||
const tag = `[${path.join(".")}]`
|
||||
return { ...e, params: { ...e.params, field: e.params?.field != null ? `${e.params.field} ${tag}` : tag } }
|
||||
}
|
||||
|
||||
private async processResItem(item: Record<string, any>): Promise<Record<string, any>> {
|
||||
const result = { ...item }
|
||||
for (const field of this.fields) {
|
||||
|
||||
Reference in New Issue
Block a user