优化FormItemsRenderer
parent
15ee185b10
commit
3b006227bd
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* 选项项数据类型
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ function SelectCreate(props) {
|
|||
label = "",
|
||||
maxCount = 1,
|
||||
onDelete,
|
||||
formValues,
|
||||
...restProps
|
||||
} = props;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ function BasicSelectTree(props) {
|
|||
nameKey = "name",
|
||||
idKey = "id",
|
||||
childrenKey = "childrenList",
|
||||
formValues,
|
||||
...restProps
|
||||
} = props;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ const Upload = (props) => {
|
|||
tipContent,
|
||||
uploadButtonText: externalUploadButtonText,
|
||||
fileType: externalFileType,
|
||||
formValues,
|
||||
...restProps
|
||||
} = props;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue