From f8df71ce8e3ec945ee241c19a8a0e561cc495f71 Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Fri, 12 Apr 2024 14:53:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96schemaForm=20onChange?= =?UTF-8?q?=20=E8=A7=A3=E5=86=B3=E5=BC=B9=E7=AA=97=E4=B8=AD=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E7=BC=96=E8=BE=91=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#10011)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/component/base/SchemaForm.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/amis-editor-core/src/component/base/SchemaForm.tsx b/packages/amis-editor-core/src/component/base/SchemaForm.tsx index 3da40e6a9..fb1d4e5d8 100644 --- a/packages/amis-editor-core/src/component/base/SchemaForm.tsx +++ b/packages/amis-editor-core/src/component/base/SchemaForm.tsx @@ -101,8 +101,6 @@ export function SchemaFrom({ return schema; }, [body, controls, submitOnChange]); - value = value || {}; - const finalValue = pipeIn ? pipeIn(value) : value; const themeConfig = React.useMemo(() => getThemeConfig(), []); const submitSubscribers = React.useRef>([]); const subscribeSubmit = React.useCallback( @@ -131,19 +129,31 @@ export function SchemaFrom({ [] ); + const data = React.useMemo(() => { + value = value || {}; + const finalValue = pipeIn ? pipeIn(value) : value; + + return createObjectFromChain([ctx, themeConfig, finalValue]); + }, [value, themeConfig, ctx]); + return render( schema, { onFinished: async (newValue: any) => { newValue = pipeOut ? await pipeOut(newValue, value) : newValue; const diffValue = diff(value, newValue); + // 没有变化时不触发onChange + if (!diffValue) { + return; + } + onChange(newValue, diffValue, (schema, value, id, diff) => { return submitSubscribers.current.reduce((schema, fn) => { return fn(schema, value, id, diff); }, schema); }); }, - data: createObjectFromChain([ctx, themeConfig, finalValue]), + data: data, node: node, manager: manager, popOverContainer,