Merge pull request #4167 from pianruijie/feat/form-event-action

feat: 未配置target及api时,派发事件
This commit is contained in:
hsm-lv 2022-04-28 11:18:12 +08:00 committed by GitHub
commit 71c2e440cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 13 deletions

View File

@ -1213,7 +1213,7 @@ Form 支持轮询初始化接口,步骤如下:
| formItemValidateError | 表单数据 | 表单项校验失败 |
| validateSucc | 表单数据 | 表单校验成功 |
| validateError | 表单数据 | 表单校验成功 |
| submitSucc | `result: object` 接口返回内容 | 提交成功 |
| submitSucc | 配置api时 `result: object` 接口返回内容; 否则为表单数据 | 提交成功 |
| submitFail | `error: object` 接口返回内容 | 提交失败 |
## 动作表

View File

@ -121,7 +121,7 @@ export default {
{
actionType: 'toast',
args: {
msg: '${event.data|json}'
msg: '表单值变化:${event.data|json}'
}
}
]
@ -131,7 +131,7 @@ export default {
{
actionType: 'toast',
args: {
msg: '${event.data|json}'
msg: '表单初始化完成:${event.data|json}'
}
}
]
@ -141,7 +141,7 @@ export default {
{
actionType: 'toast',
args: {
msg: '${event.data|json}'
msg: '表单项校验成功:${event.data|json}'
}
}
]
@ -151,7 +151,7 @@ export default {
{
actionType: 'toast',
args: {
msg: '${event.data|json}'
msg: '表单项校验失败:${event.data|json}'
}
}
]
@ -161,7 +161,7 @@ export default {
{
actionType: 'toast',
args: {
msg: '${event.data|json}'
msg: '表单校验成功:${event.data|json}'
}
}
]
@ -171,7 +171,7 @@ export default {
{
actionType: 'toast',
args: {
msg: '${event.data|json}'
msg: '表单校验成功:${event.data|json}'
}
}
]
@ -179,9 +179,21 @@ export default {
submitSucc: {
actions: [
{
actionType: 'toast',
actionType: 'dialog',
args: {
msg: '${event.data|json}'
val: '${event.data}'
},
dialog: {
title: `提交成功`,
data: {
val: '${val}'
},
body: [
{
type: 'tpl',
tpl: '${val|json}'
}
]
}
}
]
@ -189,9 +201,21 @@ export default {
submitFail: {
actions: [
{
actionType: 'toast',
actionType: 'dialog',
args: {
msg: '${event.data|json}'
val: '${event.data}'
},
dialog: {
title: `提交失败`,
data: {
val: '${val}'
},
body: [
{
type: 'tpl',
tpl: '${val|json}'
}
]
}
}
]
@ -234,7 +258,7 @@ export default {
{
actionType: 'toast',
args: {
msg: '${event.data|json}'
msg: '表单项校验成功:${event.data|json}'
}
}
]
@ -244,12 +268,48 @@ export default {
{
actionType: 'toast',
args: {
msg: '${event.data|json}'
msg: '表单项校验失败:${event.data|json}'
}
}
]
}
}
},
{
type: 'form',
debug: true,
title: "表单提交表单无target无api只触发提交成功事件",
body: [
{
type: 'input-text',
name: 'name',
label: '姓名',
required: true,
validateOnChange: true
},
{
type: 'input-text',
name: 'email',
label: '邮箱',
required: true,
validateOnChange: true,
validations: {
isEmail: true
}
}
],
onEvent: {
submitSucc: {
actions: [
{
actionType: 'toast',
args: {
msg: '提交成功:${event.data|json}'
}
}
]
},
}
}
]
};

View File

@ -1020,6 +1020,7 @@ export default class Form extends React.Component<FormProps, object> {
if (target) {
this.submitToTarget(target, values);
dispatchEvent('submitSucc', createObject(this.props.data, values));
} else if (action.actionType === 'reload') {
action.target && this.reloadTarget(action.target, values);
} else if (action.actionType === 'dialog') {
@ -1082,6 +1083,9 @@ export default class Form extends React.Component<FormProps, object> {
// return values;
});
} else {
// type为submit但是没有配api以及target时只派发事件
dispatchEvent('submitSucc', createObject(this.props.data, values));
}
return Promise.resolve(null);