优化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 { FC, ReactNode } from "react";
|
||||||
import type { FORM_ITEM_RENDER_ENUM } from "../../enum/formItemRender";
|
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
|
export type FormItemRenderType
|
||||||
= | (typeof FORM_ITEM_RENDER_ENUM)[keyof typeof FORM_ITEM_RENDER_ENUM]
|
= | (typeof FORM_ITEM_RENDER_ENUM)[keyof typeof FORM_ITEM_RENDER_ENUM]
|
||||||
| ((props: CustomRenderProps) => ReactNode);
|
| ReactNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 选项项数据类型
|
* 选项项数据类型
|
||||||
|
|
|
||||||
|
|
@ -245,15 +245,7 @@ const FormItemsRenderer = ({
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// 支持传入自定义组件
|
return render;
|
||||||
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} />;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ function SelectCreate(props) {
|
||||||
label = "",
|
label = "",
|
||||||
maxCount = 1,
|
maxCount = 1,
|
||||||
onDelete,
|
onDelete,
|
||||||
formValues,
|
|
||||||
...restProps
|
...restProps
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ function BasicSelectTree(props) {
|
||||||
nameKey = "name",
|
nameKey = "name",
|
||||||
idKey = "id",
|
idKey = "id",
|
||||||
childrenKey = "childrenList",
|
childrenKey = "childrenList",
|
||||||
formValues,
|
|
||||||
...restProps
|
...restProps
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ const Upload = (props) => {
|
||||||
tipContent,
|
tipContent,
|
||||||
uploadButtonText: externalUploadButtonText,
|
uploadButtonText: externalUploadButtonText,
|
||||||
fileType: externalFileType,
|
fileType: externalFileType,
|
||||||
formValues,
|
|
||||||
...restProps
|
...restProps
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue