mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
提交事件支持禁用默认提示
This commit is contained in:
parent
3594fc8a81
commit
49e2d5b7dd
@ -767,7 +767,7 @@ export default class Form extends React.Component<FormProps, object> {
|
||||
if (result) {
|
||||
dispatchEvent('validateSucc', data);
|
||||
} else {
|
||||
dispatchEvent('validateFail', data);
|
||||
dispatchEvent('validateError', data);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
@ -794,9 +794,7 @@ export default class Form extends React.Component<FormProps, object> {
|
||||
submit(fn?: (values: object) => Promise<any>): Promise<any> {
|
||||
const {store, messages, translate: __, dispatchEvent, data} = this.props;
|
||||
this.flush();
|
||||
const validateErrCb = () => {
|
||||
dispatchEvent('validateFail', data);
|
||||
};
|
||||
const validateErrCb = () => dispatchEvent('validateError', data);
|
||||
return store.submit(
|
||||
fn,
|
||||
this.hooks['validate'] || [],
|
||||
@ -982,8 +980,10 @@ export default class Form extends React.Component<FormProps, object> {
|
||||
if (Array.isArray(action.required) && action.required.length) {
|
||||
return store.validateFields(action.required).then(result => {
|
||||
if (!result) {
|
||||
dispatchEvent('validateError', this.props.data);
|
||||
env.notify('error', __('Form.validateFailed'));
|
||||
const dispatcher = dispatchEvent('validateError', this.props.data);
|
||||
if (!dispatcher?.prevented) {
|
||||
env.notify('error', __('Form.validateFailed'));
|
||||
}
|
||||
} else {
|
||||
dispatchEvent('validateSucc', this.props.data);
|
||||
this.handleAction(
|
||||
@ -1041,7 +1041,7 @@ export default class Form extends React.Component<FormProps, object> {
|
||||
errorMessage: saveFailed,
|
||||
onSuccess: (result: Payload) => {
|
||||
// result为提交接口返回的内容
|
||||
dispatchEvent(
|
||||
const dispatcher = dispatchEvent(
|
||||
'submitSucc',
|
||||
createObject(this.props.data, {result})
|
||||
);
|
||||
@ -1051,18 +1051,25 @@ export default class Form extends React.Component<FormProps, object> {
|
||||
) {
|
||||
return;
|
||||
}
|
||||
return until(
|
||||
const cbResult = until(
|
||||
() => store.checkRemote(finnalAsyncApi as Api, store.data),
|
||||
(ret: any) => ret && ret[finishedField || 'finished'],
|
||||
cancel => (this.asyncCancel = cancel),
|
||||
checkInterval
|
||||
);
|
||||
)
|
||||
return {
|
||||
cbResult,
|
||||
dispatcher
|
||||
};
|
||||
},
|
||||
onFailed: (result: Payload) => {
|
||||
dispatchEvent(
|
||||
const dispatcher = dispatchEvent(
|
||||
'submitFail',
|
||||
createObject(this.props.data, {error: result})
|
||||
);
|
||||
return {
|
||||
dispatcher
|
||||
};
|
||||
}
|
||||
})
|
||||
.then(async response => {
|
||||
|
@ -326,10 +326,7 @@ export const FormStore = ServiceStore.named('FormStore')
|
||||
}
|
||||
|
||||
if (!json.ok) {
|
||||
// 验证错误
|
||||
if (options && options.onFailed) {
|
||||
options.onFailed(json);
|
||||
}
|
||||
|
||||
if (json.status === 422 && json.errors) {
|
||||
setFormItemErrors(json.errors);
|
||||
|
||||
@ -349,18 +346,16 @@ export const FormStore = ServiceStore.named('FormStore')
|
||||
throw new ServerError(self.msg, json);
|
||||
} else {
|
||||
updateSavedData();
|
||||
if (options && options.onSuccess) {
|
||||
const ret = options.onSuccess(json);
|
||||
|
||||
if (ret && ret.then) {
|
||||
yield ret;
|
||||
}
|
||||
const ret = options && options.onSuccess && options.onSuccess(json);
|
||||
if (ret?.cbResult?.then) {
|
||||
yield ret.cbResult;
|
||||
}
|
||||
self.markSaving(false);
|
||||
self.updateMessage(
|
||||
json.msg ?? self.__(options && options.successMessage)
|
||||
);
|
||||
self.msg &&
|
||||
if (!ret?.dispatcher?.prevented) {
|
||||
self.msg &&
|
||||
getEnv(self).notify(
|
||||
'success',
|
||||
self.msg,
|
||||
@ -371,31 +366,33 @@ export const FormStore = ServiceStore.named('FormStore')
|
||||
}
|
||||
: undefined
|
||||
);
|
||||
}
|
||||
return json.data;
|
||||
}
|
||||
} catch (e) {
|
||||
self.markSaving(false);
|
||||
const ret = options && options.onFailed && options.onFailed(e.response || {});
|
||||
|
||||
if (!isAlive(self) || self.disposed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.type === 'ServerError') {
|
||||
const result = (e as ServerError).response;
|
||||
getEnv(self).notify(
|
||||
'error',
|
||||
e.message,
|
||||
result.msgTimeout !== undefined
|
||||
? {
|
||||
closeButton: true,
|
||||
timeout: result.msgTimeout
|
||||
}
|
||||
: undefined
|
||||
);
|
||||
} else {
|
||||
getEnv(self).notify('error', e.message);
|
||||
if (!ret?.dispatcher?.prevented) {
|
||||
if (e.type === 'ServerError') {
|
||||
const result = (e as ServerError).response;
|
||||
getEnv(self).notify(
|
||||
'error',
|
||||
e.message,
|
||||
result.msgTimeout !== undefined
|
||||
? {
|
||||
closeButton: true,
|
||||
timeout: result.msgTimeout
|
||||
}
|
||||
: undefined
|
||||
);
|
||||
} else {
|
||||
getEnv(self).notify('error', e.message);
|
||||
}
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
@ -479,9 +476,10 @@ export const FormStore = ServiceStore.named('FormStore')
|
||||
) {
|
||||
let msg = failedMessage ?? self.__('Form.validateFailed');
|
||||
const env = getEnv(self);
|
||||
|
||||
msg && env.notify('error', msg);
|
||||
validateErrCb && validateErrCb();
|
||||
const dispatcher: any = validateErrCb && validateErrCb();
|
||||
if (dispatcher?.prevented){
|
||||
msg && env.notify('error', msg);
|
||||
}
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user