From 91a55c9e671c05b4af83600d894c6631090eb721 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Wed, 1 Feb 2023 13:59:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96appendSchemaByField=E5=8F=AA?= =?UTF-8?q?=E8=83=BD=E5=8D=95=E4=B8=80=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=E9=A1=B9=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/vue/src/components/Form/src/hooks/useForm.ts | 2 +- .../src/components/Form/src/hooks/useFormEvents.ts | 14 +++++++++----- apps/vue/src/components/Form/src/types/form.ts | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) 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;