diff --git a/web/src/app/home/components/dynamic-form/DynamicFormComponent.tsx b/web/src/app/home/components/dynamic-form/DynamicFormComponent.tsx index f46d42b5..7570a084 100644 --- a/web/src/app/home/components/dynamic-form/DynamicFormComponent.tsx +++ b/web/src/app/home/components/dynamic-form/DynamicFormComponent.tsx @@ -143,8 +143,20 @@ export default function DynamicFormComponent({ // 监听表单值变化 useEffect(() => { + // Emit initial form values immediately so the parent always has a valid snapshot, + // even if the user saves without modifying any field. + // form.watch(callback) only fires on subsequent changes, not on mount. + const formValues = form.getValues(); + const initialFinalValues = itemConfigList.reduce( + (acc, item) => { + acc[item.name] = formValues[item.name] ?? item.default; + return acc; + }, + {} as Record, + ); + onSubmit?.(initialFinalValues); + const subscription = form.watch(() => { - // 获取完整的表单值,确保包含所有默认值 const formValues = form.getValues(); const finalValues = itemConfigList.reduce( (acc, item) => {