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

This commit is contained in:
zhangshujun 2023-07-21 20:23:04 +08:00 committed by GitHub
parent b30270a3fb
commit 3b0b8d0baa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) {