diff --git a/packages/utils/src/hooks/useFetchData/index.tsx b/packages/utils/src/hooks/useFetchData/index.tsx index 42f2ed4515ce..bd1c1911afe9 100644 --- a/packages/utils/src/hooks/useFetchData/index.tsx +++ b/packages/utils/src/hooks/useFetchData/index.tsx @@ -33,14 +33,14 @@ function useFetchData = Record>(pr return [proFieldKeyRef.current, JSON.stringify(props.params)]; }, [props.params]); - const { data } = useSWR(key, fetchData, { + const { data, error } = useSWR(key, fetchData, { revalidateOnFocus: false, shouldRetryOnError: false, revalidateOnReconnect: false, }); return [ - data as T, + (data as T) || error, () => { mutate(key); }, diff --git a/packages/utils/src/transformKeySubmitValue/index.ts b/packages/utils/src/transformKeySubmitValue/index.ts index d8f0034a3162..e11c145a43d2 100644 --- a/packages/utils/src/transformKeySubmitValue/index.ts +++ b/packages/utils/src/transformKeySubmitValue/index.ts @@ -38,9 +38,36 @@ const transformKeySubmitValue = ( if (tempValues == null || tempValues === undefined) { return result; } + Object.keys(tempValues).forEach((entityKey) => { const key = parentsKey ? [parentsKey, entityKey].flat(1) : [entityKey].flat(1); const itemValue = tempValues[entityKey]; + const transformFunction = get(dataFormatMap, key); + const transform = () => { + const tempKey = + typeof transformFunction === 'function' + ? transformFunction?.(itemValue, entityKey, tempValues) + : entityKey; + // { [key:string]:any } 数组也能通过编译 + if (Array.isArray(tempKey)) { + result = namePathSet(result, tempKey, itemValue); + return; + } + if (typeof tempKey === 'object') { + finalValues = { + ...finalValues, + ...tempKey, + }; + } else if (tempKey) { + result = namePathSet(result, [tempKey], itemValue); + } + }; + + /** 如果存在转化器提前渲染一下 */ + if (transformFunction && typeof transformFunction === 'function') { + transform(); + } + if ( typeof itemValue === 'object' && !Array.isArray(itemValue) && @@ -54,24 +81,7 @@ const transformKeySubmitValue = ( result = namePathSet(result, [entityKey], genValues); return; } - const transformFunction = get(dataFormatMap, key); - const tempKey = - typeof transformFunction === 'function' - ? transformFunction?.(itemValue, entityKey, tempValues) - : entityKey; - // { [key:string]:any } 数组也能通过编译 - if (Array.isArray(tempKey)) { - result = namePathSet(result, tempKey, itemValue); - return; - } - if (typeof tempKey === 'object') { - finalValues = { - ...finalValues, - ...tempKey, - }; - } else if (tempKey) { - result = namePathSet(result, [tempKey], itemValue); - } + transform(); }); // namePath、transform在omit为false时需正常返回 https://github.com/ant-design/pro-components/issues/2901#issue-908097115 return omit ? result : tempValues;