Skip to content

Commit ec45828

Browse files
committed
add children onBlur
1 parent 0c278f0 commit ec45828

4 files changed

Lines changed: 40 additions & 23 deletions

File tree

README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,15 @@ interface CardLayout {
9292

9393
```typescript
9494
interface FormViewProps {
95-
header?: React.ReactNode; // 表单头部内容
96-
footer?: React.ReactNode; // 表单底部内容
95+
header?: React.ReactNode; // 表单头部内容(表单外部)
96+
footer?: React.ReactNode; // 表单底部内容(表单外部)
97+
children?:React.ReactNode; // 主表单自定义内容(表单内部)
9798
}
9899
```
99100

100-
- `header`: 渲染在表单内容上方的区域,可用于放置标题、说明文字等
101-
- `footer`: 渲染在表单内容下方的区域,可用于放置提交按钮、操作栏等
101+
- `header`: 渲染在表单外部内容上方的区域,可用于放置标题、说明文字等
102+
- `footer`: 渲染在表单外部内容下方的区域,可用于放置提交按钮、操作栏等
103+
- `children`: 渲染在主表单内部的区域,可用于放置固定的隐藏字段或者其他的界面内容
102104

103105
### 6. 表单提交(onFinish)
104106

@@ -252,18 +254,18 @@ pnpm build
252254

253255
### FormView 组件属性
254256

255-
| 属性 | 类型 | 说明 |
256-
|------|------|------|
257-
| meta | FormMeta | 表单元数据定义 |
258-
| form | FormInstance | 表单实例 |
259-
| onValuesChange | (values: any) => void | 值变化回调 |
260-
| onFinish | (values: any, formCode?: string) => void | 表单提交回调 |
261-
| header | React.ReactNode | 表单头部内容 |
262-
| footer | React.ReactNode | 表单底部内容 |
263-
| review | boolean | 是否预览模式 |
264-
| validators | FormFieldValidator[] | 验证规则数组 |
265-
| events | FormEvent[] | 事件定义数组 |
266-
| layouts | FormLayout[] | 布局定义数组 |
257+
| 属性 | 类型 | 说明 |
258+
|------------|------|----------|
259+
| meta | FormMeta | 表单元数据定义 |
260+
| form | FormInstance | 表单实例 |
261+
| onBlur | (formCode?: string) => void | 表单失去焦点事件 |
262+
| onFinish | (values: any, formCode?: string) => void | 表单提交回调 |
263+
| header | React.ReactNode | 表单头部内容 |
264+
| footer | React.ReactNode | 表单底部内容 |
265+
| review | boolean | 是否预览模式 |
266+
| validators | FormFieldValidator[] | 验证规则数组 |
267+
| events | FormEvent[] | 事件定义数组 |
268+
| layouts | FormLayout[] | 布局定义数组 |
267269

268270
### 数据类型
269271

packages/form-engine/src/form/index.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,33 @@ export const FormViewContent: React.FC<FormViewContentProps> = (props) => {
2828

2929
const review = props.review || false;
3030

31-
const handleOnSubmit = (values:any,formCode:string) => {
31+
const handleOnFinish = (values:any,formCode:string) => {
3232
props.onFinish?.(values,formCode);
3333
}
3434

35+
const handleOnBlur = (formCode:string) => {
36+
props.onBlur?.(formCode);
37+
}
38+
3539
return (
3640
<FormContext.Provider value={context}>
3741
{props.header}
3842
<FormSubView
3943
Form={Form}
4044
formCode={meta.code}
4145
review={review}
42-
onFinish={handleOnSubmit}
46+
onFinish={handleOnFinish}
47+
onBlur={handleOnBlur}
48+
children={props.children}
4349
/>
4450
{subFormList && subFormList.map(item=>{
4551
return (
4652
<FormSubView
4753
Form={Form}
4854
formCode={item.code}
4955
review={review}
50-
onFinish={handleOnSubmit}
56+
onFinish={handleOnFinish}
57+
onBlur={handleOnBlur}
5158
/>
5259
)
5360
})}

packages/form-engine/src/form/sub-view.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ interface FormSubViewProps {
66
Form: React.ComponentType<any>;
77
review: boolean;
88
onFinish: (values:any,formCode:string) => void;
9+
onBlur: (formCode:string) => void;
10+
children?:React.ReactNode;
911
}
1012

1113
export const FormSubView: React.FC<FormSubViewProps> = (props) => {
@@ -51,10 +53,14 @@ export const FormSubView: React.FC<FormSubViewProps> = (props) => {
5153
return (
5254
<Form
5355
form={formTarget}
56+
onBlur={()=>{
57+
props.onBlur(props.formCode);
58+
}}
5459
onFinish={(values:any)=>{
5560
props.onFinish(values,props.formCode);
5661
}}
5762
>
63+
{props.children}
5864
{layoutContext.render(props.formCode, fields, review, context)}
5965
</Form>
6066
)

packages/form-engine/src/types/view.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,16 @@ export interface FormViewProps {
9696
meta: FormMeta;
9797
/** 表单操控对象 */
9898
form?: FormInstance;
99-
/** 表单数据更新事件 */
100-
onValuesChange?: (values: any) => void;
10199
/** 表单提交数据 **/
102100
onFinish?: (values:any,formCode?:string) => void;
103-
/** 表单头内容 **/
101+
/** 表单失去焦点事件 **/
102+
onBlur?: (formCode?:string) => void;
103+
/** 表单头内容(表单外部) **/
104104
header?:React.ReactNode;
105-
/** 表单底部内容 **/
105+
/** 表单底部内容(表单外部) **/
106106
footer?:React.ReactNode;
107+
/** 主表单自定义内容(表单内部) **/
108+
children?:React.ReactNode;
107109
/** 是否预览模式 */
108110
review?: boolean;
109111
/** 字段校验逻辑 */

0 commit comments

Comments
 (0)