Commit 3b0b8d0baa9b03a82fb88fbdb4bb21214793dfe6

Authored by zhangshujun
Committed by GitHub
1 parent b30270a3

feat:不允许可重复添加同一field的表单项 (#2923)

src/components/Form/src/hooks/useFormEvents.ts
@@ -210,7 +210,13 @@ export function useFormEvents({ @@ -210,7 +210,13 @@ export function useFormEvents({
210 first = false, 210 first = false,
211 ) { 211 ) {
212 const schemaList: FormSchema[] = cloneDeep(unref(getSchema)); 212 const schemaList: FormSchema[] = cloneDeep(unref(getSchema));
213 - 213 + const addSchemaIds: string[] = Array.isArray(schema)
  214 + ? schema.map((item) => item.field)
  215 + : [schema.field];
  216 + if (schemaList.find((item) => addSchemaIds.includes(item.field))) {
  217 + error('There are schemas that have already been added');
  218 + return;
  219 + }
214 const index = schemaList.findIndex((schema) => schema.field === prefixField); 220 const index = schemaList.findIndex((schema) => schema.field === prefixField);
215 const _schemaList = isObject(schema) ? [schema as FormSchema] : (schema as FormSchema[]); 221 const _schemaList = isObject(schema) ? [schema as FormSchema] : (schema as FormSchema[]);
216 if (!prefixField || index === -1 || first) { 222 if (!prefixField || index === -1 || first) {