2 Star 0 Fork 0

Jim/react-new-umi-antd-2024

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index.tsx 2.63 KB
一键复制 编辑 原始数据 按行查看 历史
zhufei 提交于 2024-05-31 17:35 +08:00 . 类型检查
import {Col, Form, Row} from "antd";
import React, {Key} from "react";
import UploadDom from "../UploadDom";
import style from "./style.less";
import {FormItem, IProps} from "./types";
const DynamicForms = React.memo((props: IProps) => {
const {form, responsiveLayout, formItemLayout, formItems, buttonDom, buttonSpan} = props;
/**
* 渲染表单项
*
* @param item 表单项信息
* @param index 表单项索引
* @returns 表单项的JSX元素
*/
const renderFormItem = (item: FormItem, index: Key | null | undefined) => {
return (
<Col {...responsiveLayout} key={index}>
<Form.Item label={item.label} name={item.name} rules={item.rules} initialValue={item.initialValue}>
{item.type === "Select" ? (
<item.component
allowClear
placeholder={item.placeholder}
style={{width: "100%", textAlign: "left"}}
{...item.events}
maxCount={item?.maxCount}
mode={item?.mode}
disabled={item?.disabled}
maxTagCount={item?.maxTagCount}
>
{item.options?.map((option, index) => (
<item.component.Option key={index} value={option}>
{option}
</item.component.Option>
))}
</item.component>
) : item.type === "Cascader" ? (
<item.component
disabled={item?.disabled}
allowClear
placeholder={item.placeholder}
style={{width: "100%", textAlign: "left"}}
options={item.options}
{...item.events}
/>
) : item.type === "Upload" ? (
<item.component {...item.events}>{item.children}</item.component>
) : item.type === "UploadImg" ? (
<UploadDom></UploadDom>
) : (
<item.component
allowClear
type={item?.isType}
prefix={item?.prefix}
disabled={item?.disabled}
placeholder={item.placeholder}
style={{width: "100%", textAlign: "left"}}
{...item.events}
/>
)}
</Form.Item>
</Col>
);
};
return (
<Form form={form} onFinish={values => props.onFinish(values)} {...formItemLayout} className={style.formContainer}>
{formItems.map(renderFormItem)}
<Col span={buttonSpan}>
<Row justify='end'>
<Form.Item>{buttonDom()}</Form.Item>
</Row>
</Col>
</Form>
);
});
export default DynamicForms;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/music_poor/react-new-umi-antd-2024.git
[email protected]:music_poor/react-new-umi-antd-2024.git
music_poor
react-new-umi-antd-2024
react-new-umi-antd-2024
role

搜索帮助