diff --git a/apps/vue/src/components/Form/src/hooks/useForm.ts b/apps/vue/src/components/Form/src/hooks/useForm.ts index ab80409ac..40f246da0 100644 --- a/apps/vue/src/components/Form/src/hooks/useForm.ts +++ b/apps/vue/src/components/Form/src/hooks/useForm.ts @@ -94,7 +94,7 @@ export function useForm(props?: Props): UseFormReturnType { }, appendSchemaByField: async ( - schema: FormSchema, + schema: FormSchema | FormSchema[], prefixField: string | undefined, first: boolean, ) => { diff --git a/apps/vue/src/components/Form/src/hooks/useFormEvents.ts b/apps/vue/src/components/Form/src/hooks/useFormEvents.ts index 4b12ff355..c780a828d 100644 --- a/apps/vue/src/components/Form/src/hooks/useFormEvents.ts +++ b/apps/vue/src/components/Form/src/hooks/useFormEvents.ts @@ -60,7 +60,7 @@ export function useFormEvents({ /** * @description: Set form value */ - async function setFieldsValue>(values: T): Promise { + async function setFieldsValue(values: any): Promise { const fields = unref(getSchema) .map((item) => item.field) .filter(Boolean); @@ -154,19 +154,23 @@ export function useFormEvents({ /** * @description: Insert after a certain field, if not insert the last */ - async function appendSchemaByField(schema: FormSchema, prefixField?: string, first = false) { + async function appendSchemaByField( + schema: FormSchema | FormSchema[], + prefixField?: string, + first = false, + ) { const schemaList: FormSchema[] = cloneDeep(unref(getSchema)); const index = schemaList.findIndex((schema) => schema.field === prefixField); - + const _schemaList = isObject(schema) ? [schema as FormSchema] : (schema as FormSchema[]); if (!prefixField || index === -1 || first) { - first ? schemaList.unshift(schema) : schemaList.push(schema); + first ? schemaList.unshift(..._schemaList) : schemaList.push(..._schemaList); schemaRef.value = schemaList; _setDefaultValue(schema); return; } if (index !== -1) { - schemaList.splice(index + 1, 0, schema); + schemaList.splice(index + 1, 0, ..._schemaList); } _setDefaultValue(schema); diff --git a/apps/vue/src/components/Form/src/types/form.ts b/apps/vue/src/components/Form/src/types/form.ts index 968af1ce7..922be8599 100644 --- a/apps/vue/src/components/Form/src/types/form.ts +++ b/apps/vue/src/components/Form/src/types/form.ts @@ -26,7 +26,7 @@ export interface ButtonProps extends AntdButtonProps { export interface FormActionType { submit: () => Promise; - setFieldsValue: (values: T) => Promise; + setFieldsValue: (values: T) => Promise; resetFields: () => Promise; getFieldsValue: () => Recordable; clearValidate: (name?: string | string[]) => Promise; @@ -35,7 +35,7 @@ export interface FormActionType { setProps: (formProps: Partial) => Promise; removeSchemaByField: (field: string | string[]) => Promise; appendSchemaByField: ( - schema: FormSchema, + schema: FormSchema | FormSchema[], prefixField: string | undefined, first?: boolean | undefined, ) => Promise;