Skip to content

Commit a561b9f

Browse files
committed
feat: FormList update (#15)
* feat: FormItem update * feat: FormList update * feat: update * feat: update
1 parent 2850171 commit a561b9f

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

src/components/FormList/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { Button, Form, FormInstance, FormProps } from "antd";
33

44
import { getFormElement } from "../tools";
55

6-
export interface FormListProps extends Pick<FormProps, "form" | "colon" | "className" | "style" | "layout" | "labelAlign" | "onValuesChange" | "disabled"> {
6+
export interface FormListProps extends Omit<FormProps, "labelCol" | "wrapperCol"> {
77
labelCol?: number;
88
wrapperCol?: number;
99

1010
// 搜索
1111
searchBtn?: null | ReactElement;
12+
1213
// 提交
1314
submitBtn?: boolean;
1415
submitNode?: ReactElement;
@@ -98,22 +99,24 @@ const FormList = (props: FormListProps) => {
9899
return (
99100
<Form form={realForm} labelCol={labelCol ? { span: labelCol } : undefined} wrapperCol={wrapperCol ? { span: wrapperCol } : undefined} onFinish={onOk} {...restProps}>
100101
{itemInfo.map((e, idx) => {
102+
const key = e.name instanceof Array ? e.name.join("_") : e.name || idx;
103+
101104
if (e.hide) {
102105
return null;
103106
}
104107

105108
if (e.type === "blockNode") {
106-
return <span key={typeof e.name === "string" ? e.name || idx : e.name.join("_")}>{e.label}</span>;
109+
return <span key={key}>{e.label}</span>;
107110
}
108111

109112
return (
110113
<Form.Item
114+
key={key}
115+
name={e.name}
111116
label={e.label}
112117
extra={e.extra}
113118
rules={[e.rule]}
114119
hidden={!(e.visible ?? true)}
115-
name={e.name ? e.name : undefined}
116-
key={typeof e.name === "string" ? e.name || idx : e.name.join("_")}
117120
valuePropName={e.valuePropName ? e.valuePropName : e.type === "switch" ? "checked" : "value"}
118121
initialValue={e.type === "radio" ? e.options?.[0].value : e.type === "switch" ? true : undefined}
119122
{...e.formItemProps}

src/components/FormModal/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface FormModalProps
1010
}
1111

1212
const FormModal = (props: FormModalProps) => {
13-
const { open, title, noFooter, okButtonProps, className, classNames, maskClosable = true, onCancel, wrapperCol = 12, labelCol = 5, onForm, ...resetProps } = props;
13+
const { open, title, noFooter, okButtonProps, className, classNames, maskClosable = true, onCancel, wrapperCol = 21, labelCol = 3, onForm, ...resetProps } = props;
1414

1515
const formInstance = useRef<FormInstance<any> | null>(null);
1616

@@ -25,7 +25,7 @@ const FormModal = (props: FormModalProps) => {
2525
open={open}
2626
okText="确定"
2727
title={title}
28-
destroyOnClose
28+
destroyOnHidden
2929
cancelText="取消"
3030
className={className}
3131
maskClosable={maskClosable}
@@ -41,7 +41,9 @@ const FormModal = (props: FormModalProps) => {
4141
formInstance.current && formInstance.current.submit();
4242
}}
4343
>
44-
<FormList submitBtn={false} labelCol={labelCol} wrapperCol={wrapperCol} onForm={getForm} {...resetProps} />
44+
<div className="overflow-hidden">
45+
<FormList submitBtn={false} labelCol={labelCol} wrapperCol={wrapperCol} onForm={getForm} {...resetProps} />
46+
</div>
4547
</Modal>
4648
);
4749
};

src/components/tools.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ export const getFormElement = (type: FormItem["type"], info: FormItem) => {
4141
options={info.options as { value: string }[]}
4242
className="min-w-[150px]"
4343
filterOption={(input, option: any) => {
44-
return (option.label as string).includes(input);
44+
if (typeof option.label === "string") {
45+
return option.label.includes(input);
46+
}
47+
return false;
4548
}}
4649
{...info.otherOptions}
4750
/>

src/formIten.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
declare interface FormItem {
2-
name: string | (number | string)[];
2+
name?: string | (number | string)[];
33
label?: string | React.ReactNode;
44
placeholder?: string;
55
initialValue?: unknown;
6-
rule?: any;
6+
rule?: import("antd").FormItemProps["rules"][number];
77
hide?: boolean;
88
visible?: boolean;
99
disable?: boolean;
1010
extra?: string | React.ReactNode;
1111
type: "input" | "numberInput" | "select" | "treeSelect" | "datePick" | "rangePick" | "radio" | "checkbox" | "textArea" | "switch" | "blockNode" | "node";
12-
valuePropName?: string;
12+
valuePropName?: import("antd").FormItemProps["valuePropName"];
1313
formItemProps?: import("antd").FormItemProps;
1414
// 特有属性
1515
rightNode?: React.ReactNode; // node

0 commit comments

Comments
 (0)