feat: for支持pureSubmit事件

This commit is contained in:
pianruijie 2022-09-06 17:04:55 +08:00
parent bdb310d201
commit 7f48846bfe
3 changed files with 52 additions and 2 deletions

View File

@ -1458,6 +1458,7 @@ Form 支持轮询初始化接口,步骤如下:
| formItemValidateError | `event.data: object` 当前表单数据 | 表单项校验失败时触发 |
| validateSucc | `event.data: object` 当前表单数据 | 表单校验成功时触发 |
| validateError | `event.data: object` 当前表单数据 | 表单校验失败时触发 |
| pureSubmit | `event.data: object` 当前表单数据 | 表单提交后触发配置了该事件将不会触发表单提交时默认的校验、提交到api或者target等行为所有行为需要自己配置 |
| submitSucc | `event.data.result: object` api 远程请求成功后返回的结果数据 | 提交成功时触发 |
| submitFail | `event.data.error: object` api 远程请求失败后返回的错误信息 | 提交失败时触发 |

View File

@ -276,6 +276,43 @@ export default {
]
}
}
},
{
type: 'form',
debug: true,
api: '/api/mock2/form/saveForm',
title: "表单配置pureSubmit事件后将不会触发表单提交时默认的校验、提交到api或者target等行为所有行为需要自己配置",
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: {
pureSubmit: {
actions: [
{
actionType: 'toast',
args: {
msg: '提交成功:${event.data|json}'
}
}
]
},
}
}
]
};

View File

@ -1014,7 +1014,8 @@ export default class Form extends React.Component<FormProps, object> {
clearPersistDataAfterSubmit,
trimValues,
dispatchEvent,
translate: __
translate: __,
$schema
} = this.props;
// 做动作之前,先把数据同步一下。
@ -1822,7 +1823,7 @@ export class FormRenderer extends Form {
return this.handleAction(undefined, action, data, throwErrors);
}
handleAction(
async handleAction(
e: React.UIEvent<any> | undefined,
action: ActionObject,
ctx: object,
@ -1833,6 +1834,17 @@ export class FormRenderer extends Form {
// if (this.props.disabled) {
// return;
// }
// 配了pureSubmit事件的表示将提交逻辑全部托管给事件
const {dispatchEvent, $schema} = this.props;
const pureSubmitEvent = $schema?.onEvent?.pureSubmit;
const dispatcher = await dispatchEvent(
'pureSubmit',
this.props.data
);
if (dispatcher?.prevented || pureSubmitEvent) {
return;
}
if (action.target && action.actionType !== 'reload') {
const scoped = this.context as IScopedContext;