mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 11:07:52 +08:00
优化api的验证方式
This commit is contained in:
parent
0a037a14ae
commit
553a48a311
@ -278,24 +278,23 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
||||
// 由于 ajax 一段时间后再弹出,肯定被浏览器给阻止掉的,所以提前弹。
|
||||
action.redirect && action.blank && env.jumpTo(filter(action.redirect, data), action);
|
||||
|
||||
return isEffectiveApi(action.api, data) &&
|
||||
store
|
||||
.saveRemote(action.api, data, {
|
||||
successMessage: (action.messages && action.messages.success) || (messages && messages.saveSuccess),
|
||||
errorMessage: (action.messages && action.messages.failed) || (messages && messages.saveFailed),
|
||||
})
|
||||
.then(async (payload: object) => {
|
||||
const data = createObject(ctx, payload);
|
||||
return store
|
||||
.saveRemote(action.api, data, {
|
||||
successMessage: (action.messages && action.messages.success) || (messages && messages.saveSuccess),
|
||||
errorMessage: (action.messages && action.messages.failed) || (messages && messages.saveFailed),
|
||||
})
|
||||
.then(async (payload: object) => {
|
||||
const data = createObject(ctx, payload);
|
||||
|
||||
if (action.feedback && isVisible(action.feedback, data)) {
|
||||
await this.openFeedback(action.feedback, data);
|
||||
stopAutoRefreshWhenModalIsOpen && clearTimeout(this.timer);
|
||||
}
|
||||
if (action.feedback && isVisible(action.feedback, data)) {
|
||||
await this.openFeedback(action.feedback, data);
|
||||
stopAutoRefreshWhenModalIsOpen && clearTimeout(this.timer);
|
||||
}
|
||||
|
||||
action.redirect && !action.blank && env.jumpTo(filter(action.redirect, data), action);
|
||||
action.reload ? this.reloadTarget(action.reload, data) : this.search(undefined, undefined, true);
|
||||
})
|
||||
.catch(() => {});
|
||||
action.redirect && !action.blank && env.jumpTo(filter(action.redirect, data), action);
|
||||
action.reload ? this.reloadTarget(action.reload, data) : this.search(undefined, undefined, true);
|
||||
})
|
||||
.catch(() => {});
|
||||
} else if (pickerMode && (action.actionType === 'confirm' || action.actionType === 'submit')) {
|
||||
return Promise.resolve({
|
||||
items: store.selectedItems.concat(),
|
||||
@ -677,9 +676,10 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
||||
modified: diff,
|
||||
});
|
||||
|
||||
isEffectiveApi(quickSaveItemApi, createObject(data, rows)) &&
|
||||
const sendData = createObject(data, rows);
|
||||
isEffectiveApi(quickSaveItemApi, sendData) &&
|
||||
store
|
||||
.saveRemote(quickSaveItemApi, createObject(data, rows))
|
||||
.saveRemote(quickSaveItemApi, sendData)
|
||||
.then(() => {
|
||||
if ((quickSaveItemApi as ApiObject).reload) {
|
||||
this.reloadTarget((quickSaveItemApi as ApiObject).reload as string, data);
|
||||
|
@ -523,8 +523,7 @@ export default class Form extends React.Component<FormProps, object> {
|
||||
[finishedField || 'finished']: false
|
||||
});
|
||||
|
||||
return isEffectiveApi(action.api || api as Api, store.data) &&
|
||||
store
|
||||
return store
|
||||
.saveRemote(action.api || api as Api, values, {
|
||||
successMessage: saveSuccess,
|
||||
errorMessage: saveFailed,
|
||||
@ -587,8 +586,7 @@ export default class Form extends React.Component<FormProps, object> {
|
||||
return env.alert(`当 actionType 为 ajax 时,请设置 api 属性`);
|
||||
}
|
||||
|
||||
return isEffectiveApi(action.api, data) &&
|
||||
store
|
||||
return store
|
||||
.saveRemote(action.api as Api, data, {
|
||||
successMessage: action.messages && action.messages.success || saveSuccess,
|
||||
errorMessage: action.messages && action.messages.failed || saveFailed
|
||||
|
@ -185,21 +185,20 @@ export default class Page extends React.Component<PageProps> {
|
||||
} else if (action.actionType === 'drawer') {
|
||||
store.openDrawer(ctx);
|
||||
} else if (action.actionType === 'ajax') {
|
||||
isEffectiveApi(action.api, ctx) &&
|
||||
store
|
||||
.saveRemote(action.api as string, ctx, {
|
||||
successMessage: (action.messages && action.messages.success) || (messages && messages.saveSuccess),
|
||||
errorMessage: (action.messages && action.messages.failed) || (messages && messages.saveSuccess),
|
||||
})
|
||||
.then(async () => {
|
||||
if (action.feedback && isVisible(action.feedback, store.data)) {
|
||||
await this.openFeedback(action.feedback, store.data);
|
||||
}
|
||||
store
|
||||
.saveRemote(action.api as string, ctx, {
|
||||
successMessage: (action.messages && action.messages.success) || (messages && messages.saveSuccess),
|
||||
errorMessage: (action.messages && action.messages.failed) || (messages && messages.saveSuccess),
|
||||
})
|
||||
.then(async () => {
|
||||
if (action.feedback && isVisible(action.feedback, store.data)) {
|
||||
await this.openFeedback(action.feedback, store.data);
|
||||
}
|
||||
|
||||
action.redirect && env.jumpTo(filter(action.redirect, store.data), action);
|
||||
action.reload && this.reloadTarget(action.reload, store.data);
|
||||
})
|
||||
.catch(() => {});
|
||||
action.redirect && env.jumpTo(filter(action.redirect, store.data), action);
|
||||
action.reload && this.reloadTarget(action.reload, store.data);
|
||||
})
|
||||
.catch(() => {});
|
||||
} else if (action.actionType === 'copy' && (action.content || action.copy)) {
|
||||
env.copy && env.copy(filter(action.content || action.copy, ctx));
|
||||
}
|
||||
|
@ -301,7 +301,7 @@ export default class Wizard extends React.Component<WizardProps, WizardState> {
|
||||
[finishedField || 'finished']: false,
|
||||
});
|
||||
|
||||
if (isEffectiveApi(step.api || action.api, store.data)) {
|
||||
if (isEffectiveApi(action.api || step.api, store.data)) {
|
||||
store
|
||||
.saveRemote(action.api || step.api, store.data, {
|
||||
onSuccess: () => {
|
||||
@ -338,44 +338,43 @@ export default class Wizard extends React.Component<WizardProps, WizardState> {
|
||||
const formStore = this.form ? (this.form.props.store as IFormStore) : store;
|
||||
store.markSaving(true);
|
||||
|
||||
isEffectiveApi(action.api || step.api || api, store.data) &&
|
||||
formStore
|
||||
.saveRemote(action.api || step.api || api, store.data, {
|
||||
onSuccess: () => {
|
||||
if (!isEffectiveApi(finnalAsyncApi, store.data) || store.data[finishedField || 'finished']) {
|
||||
return;
|
||||
}
|
||||
|
||||
return until(
|
||||
() => store.checkRemote(finnalAsyncApi as Api, store.data),
|
||||
(ret: any) => ret && ret[finishedField || 'finished'],
|
||||
cancel => (this.asyncCancel = cancel)
|
||||
);
|
||||
},
|
||||
})
|
||||
.then(value => {
|
||||
store.updateData({
|
||||
...store.data,
|
||||
...value
|
||||
});
|
||||
store.markSaving(false);
|
||||
if (onFinished && onFinished(value, action) === false) {
|
||||
// 如果是 false 后面的操作就不执行
|
||||
return value;
|
||||
formStore
|
||||
.saveRemote(action.api || step.api || api, store.data, {
|
||||
onSuccess: () => {
|
||||
if (!isEffectiveApi(finnalAsyncApi, store.data) || store.data[finishedField || 'finished']) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (redirect) {
|
||||
env.updateLocation(filter(redirect, store.data));
|
||||
} else if (reload) {
|
||||
this.reloadTarget(reload, store.data);
|
||||
}
|
||||
|
||||
return value;
|
||||
})
|
||||
.catch(e => {
|
||||
store.markSaving(false);
|
||||
console.error(e);
|
||||
return until(
|
||||
() => store.checkRemote(finnalAsyncApi as Api, store.data),
|
||||
(ret: any) => ret && ret[finishedField || 'finished'],
|
||||
cancel => (this.asyncCancel = cancel)
|
||||
);
|
||||
},
|
||||
})
|
||||
.then(value => {
|
||||
store.updateData({
|
||||
...store.data,
|
||||
...value
|
||||
});
|
||||
store.markSaving(false);
|
||||
if (onFinished && onFinished(value, action) === false) {
|
||||
// 如果是 false 后面的操作就不执行
|
||||
return value;
|
||||
}
|
||||
|
||||
if (redirect) {
|
||||
env.updateLocation(filter(redirect, store.data));
|
||||
} else if (reload) {
|
||||
this.reloadTarget(reload, store.data);
|
||||
}
|
||||
|
||||
return value;
|
||||
})
|
||||
.catch(e => {
|
||||
store.markSaving(false);
|
||||
console.error(e);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,9 +167,9 @@ export function isEffectiveApi(api?: Api, data?: any, initFetch?: boolean, initF
|
||||
if (initFetchOn && data && !evalExpression(initFetchOn, data)) {
|
||||
return false;
|
||||
}
|
||||
if (typeof api === 'string' && isValidApi(api)) {
|
||||
if (typeof api === 'string' && api.length) {
|
||||
return true;
|
||||
} else if (isObject(api) && isValidApi((api as ApiObject).url)) {
|
||||
} else if (isObject(api) && (api as ApiObject).url) {
|
||||
if ((api as ApiObject).sendOn && data && !evalExpression((api as ApiObject).sendOn as string, data)) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user