diff --git a/packages/core/client/src/block-provider/FormFieldProvider.tsx b/packages/core/client/src/block-provider/FormFieldProvider.tsx index bdb1fec57..989363513 100644 --- a/packages/core/client/src/block-provider/FormFieldProvider.tsx +++ b/packages/core/client/src/block-provider/FormFieldProvider.tsx @@ -1,6 +1,6 @@ -import { createForm, onFieldReact, onFormInputChange, onFormValuesChange } from '@formily/core'; -import { ArrayField, Field, ObjectField } from '@formily/core'; -import { useField, useFieldSchema } from '@formily/react'; +import { createForm, onFormValuesChange } from '@formily/core'; +import { useField } from '@formily/react'; +import { autorun } from '@formily/reactive'; import { Spin } from 'antd'; import React, { createContext, useContext, useEffect, useMemo } from 'react'; import { RecordProvider } from '../record-provider'; @@ -32,6 +32,15 @@ const InternalFormFieldProvider = (props) => { [], ); + // 当使用数据模板时,会 formBlockCtx.form.values 会被整体赋值,这时候需要同步到 form.values + useEffect(() => { + const dispose = autorun(() => { + form.values = formBlockCtx?.form?.values[fieldName] || form.values; + }); + + return dispose; + }, []); + const { resource, service } = useBlockRequestContext(); if (service.loading) { return ; @@ -52,9 +61,8 @@ const InternalFormFieldProvider = (props) => { {props.children} - ); -} +}; export const WithoutFormFieldResource = createContext(null); @@ -65,8 +73,8 @@ export const FormFieldProvider = (props) => { - ) -} + ); +}; export const useFormFieldContext = () => { return useContext(FormFieldContext); @@ -80,5 +88,4 @@ export const useFormFieldProps = () => { return { form: ctx.form, }; - -} +}; diff --git a/packages/core/client/src/schema-component/antd/form-v2/FormField.tsx b/packages/core/client/src/schema-component/antd/form-v2/FormField.tsx index 11f913bb0..547e39881 100644 --- a/packages/core/client/src/schema-component/antd/form-v2/FormField.tsx +++ b/packages/core/client/src/schema-component/antd/form-v2/FormField.tsx @@ -1,4 +1,4 @@ -import { observer, useField, useFieldSchema, useForm } from '@formily/react'; +import { observer, useField, useFieldSchema } from '@formily/react'; import React, { useEffect } from 'react'; import { useFormBlockContext } from '../../../block-provider'; import { useCollection } from '../../../collection-manager'; @@ -21,4 +21,4 @@ export const FormField: any = observer((props) => { } }, []); return
{props.children}
; -}); \ No newline at end of file +});