优化FormItemsRenderer

master
LiuJiaNan 2025-11-05 14:24:35 +08:00
parent 15ee185b10
commit 3b006227bd
5 changed files with 2 additions and 27 deletions

View File

@ -4,26 +4,12 @@ import type { NamePath } from "rc-field-form/lib/interface";
import type { FC, ReactNode } from "react";
import type { FORM_ITEM_RENDER_ENUM } from "../../enum/formItemRender";
/**
*
*/
export interface CustomRenderProps {
/** 表单当前值 */
formValues: FormValues;
/** 字段值 */
value?: any;
/** 值变化回调 */
onChange?: (value: any) => void;
/** 其他属性 */
[key: string]: any;
}
/**
*
*/
export type FormItemRenderType
= | (typeof FORM_ITEM_RENDER_ENUM)[keyof typeof FORM_ITEM_RENDER_ENUM]
| ((props: CustomRenderProps) => ReactNode);
| ReactNode;
/**
*

View File

@ -245,15 +245,7 @@ const FormItemsRenderer = ({
return null;
default:
// 支持传入自定义组件
if (typeof render === "function" || typeof render === "object") {
const CustomComponent = render;
if (typeof render === "function")
return <CustomComponent {...componentProps} formValues={getFormValues()} />;
if (typeof render === "object")
return <CustomComponent {...componentProps} />;
}
return <Input placeholder={placeholder} {...componentProps} />;
return render;
}
};

View File

@ -11,7 +11,6 @@ function SelectCreate(props) {
label = "",
maxCount = 1,
onDelete,
formValues,
...restProps
} = props;

View File

@ -11,7 +11,6 @@ function BasicSelectTree(props) {
nameKey = "name",
idKey = "id",
childrenKey = "childrenList",
formValues,
...restProps
} = props;

View File

@ -20,7 +20,6 @@ const Upload = (props) => {
tipContent,
uploadButtonText: externalUploadButtonText,
fileType: externalFileType,
formValues,
...restProps
} = props;