mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 12:08:13 +08:00
优化api的验证方式
This commit is contained in:
parent
0a037a14ae
commit
553a48a311
@ -278,8 +278,7 @@ 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
|
||||
return store
|
||||
.saveRemote(action.api, data, {
|
||||
successMessage: (action.messages && action.messages.success) || (messages && messages.saveSuccess),
|
||||
errorMessage: (action.messages && action.messages.failed) || (messages && messages.saveFailed),
|
||||
@ -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,7 +185,6 @@ 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),
|
||||
|
@ -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,7 +338,6 @@ 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: () => {
|
||||
|
@ -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