diff --git a/packages/core/client/src/block-provider/hooks/index.ts b/packages/core/client/src/block-provider/hooks/index.ts index d34a8d540e..d048cd96c6 100644 --- a/packages/core/client/src/block-provider/hooks/index.ts +++ b/packages/core/client/src/block-provider/hooks/index.ts @@ -97,6 +97,30 @@ const filterValue = (value) => { return obj; }; +function getFilteredFormValues(form) { + const values = _.cloneDeep(form.values); + const allFields = []; + form.query('*').forEach((field) => { + if (field) { + allFields.push(field); + } + }); + const readonlyPaths = allFields + .filter((field) => field?.componentProps?.readOnlySubmit) + .map((field) => { + const segments = field.path?.segments || []; + if (segments.length <= 1) { + return segments.join('.'); + } + return segments.slice(0, -1).join('.'); + }); + for (const path of readonlyPaths) { + _.unset(values, path); + } + + return values; +} + export function getFormValues({ filterByTk, field, @@ -124,7 +148,7 @@ export function getFormValues({ } } - return form.values; + return getFilteredFormValues(form); } export function useCollectValuesToSubmit() { diff --git a/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx b/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx index ed9969a523..03c67938c8 100644 --- a/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx @@ -34,7 +34,7 @@ import useServiceOptions, { useAssociationFieldContext } from './hooks'; const removeIfKeyEmpty = (obj, filterTargetKey) => { if (!obj || typeof obj !== 'object' || !filterTargetKey || Array.isArray(obj)) return obj; - return !obj[filterTargetKey] ? null : obj; + return !obj[filterTargetKey] ? undefined : obj; }; export const AssociationFieldAddNewer = (props) => { @@ -106,8 +106,13 @@ const InternalAssociationSelect = observer( useEffect(() => { const initValue = isVariable(field.value) ? undefined : field.value; const value = Array.isArray(initValue) ? initValue.filter(Boolean) : initValue; - setInnerValue(value); - }, [field.value]); + const result = removeIfKeyEmpty(value, filterTargetKey); + setInnerValue(result); + if (!isEqual(field.value, result)) { + field.value = result; + } + }, [field.value, filterTargetKey]); + useEffect(() => { const id = uid(); form.addEffects(id, () => { diff --git a/packages/core/client/src/schema-component/antd/form-item/hooks/useLazyLoadDisplayAssociationFieldsOfForm.ts b/packages/core/client/src/schema-component/antd/form-item/hooks/useLazyLoadDisplayAssociationFieldsOfForm.ts index bd2f7e4357..4c9bba47bd 100644 --- a/packages/core/client/src/schema-component/antd/form-item/hooks/useLazyLoadDisplayAssociationFieldsOfForm.ts +++ b/packages/core/client/src/schema-component/antd/form-item/hooks/useLazyLoadDisplayAssociationFieldsOfForm.ts @@ -101,6 +101,10 @@ const useLazyLoadDisplayAssociationFieldsOfForm = () => { field.value = null; } else { field.value = result; + field.componentProps = { + ...field.componentProps, + readOnlySubmit: true, + }; // 让它不参与提交 } }); })