Selaa lähdekoodia

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

zhangshujun 1 vuosi sitten
vanhempi
commit
3b0b8d0baa
1 muutettua tiedostoa jossa 7 lisäystä ja 1 poistoa
  1. 7 1
      src/components/Form/src/hooks/useFormEvents.ts

+ 7 - 1
src/components/Form/src/hooks/useFormEvents.ts

@@ -210,7 +210,13 @@ export function useFormEvents({
     first = false,
   ) {
     const schemaList: FormSchema[] = cloneDeep(unref(getSchema));
-
+    const addSchemaIds: string[] = Array.isArray(schema)
+      ? schema.map((item) => item.field)
+      : [schema.field];
+    if (schemaList.find((item) => addSchemaIds.includes(item.field))) {
+      error('There are schemas that have already been added');
+      return;
+    }
     const index = schemaList.findIndex((schema) => schema.field === prefixField);
     const _schemaList = isObject(schema) ? [schema as FormSchema] : (schema as FormSchema[]);
     if (!prefixField || index === -1 || first) {