delegate 时关于是否保存 action 对象逻辑调整

This commit is contained in:
2betop 2020-01-09 10:50:43 +08:00
parent 5a63c6752d
commit c73a7bef99
4 changed files with 23 additions and 5 deletions

View File

@ -314,9 +314,8 @@ export default class CRUD extends React.Component<CRUDProps, any> {
stopAutoRefreshWhenModalIsOpen
} = this.props;
delegate || store.setCurrentAction(action);
if (action.actionType === 'dialog') {
store.setCurrentAction(action);
const idx: number = (ctx as any).index;
const length = store.data.items.length;
stopAutoRefreshWhenModalIsOpen && clearTimeout(this.timer);
@ -328,6 +327,7 @@ export default class CRUD extends React.Component<CRUDProps, any> {
index: idx
});
} else if (action.actionType === 'ajax') {
store.setCurrentAction(action);
const data = ctx;
// 由于 ajax 一段时间后再弹出,肯定被浏览器给阻止掉的,所以提前弹。
@ -364,6 +364,7 @@ export default class CRUD extends React.Component<CRUDProps, any> {
pickerMode &&
(action.actionType === 'confirm' || action.actionType === 'submit')
) {
store.setCurrentAction(action);
return Promise.resolve({
items: store.selectedItems.concat()
});

View File

@ -611,16 +611,18 @@ export class DialogRenderer extends Dialog {
}
const scoped = this.context as IScopedContext;
delegate || store.setCurrentAction(action);
if (action.type === 'reset') {
store.setCurrentAction(action);
store.reset();
} else if (
action.actionType === 'close' ||
action.actionType === 'cancel'
) {
store.setCurrentAction(action);
this.handleSelfClose();
} else if (action.actionType === 'confirm') {
store.setCurrentAction(action);
this.tryChildrenToHandle(
{
...action,
@ -630,6 +632,7 @@ export class DialogRenderer extends Dialog {
action
) || this.handleSelfClose();
} else if (action.actionType === 'next' || action.actionType === 'prev') {
store.setCurrentAction(action);
if (action.type === 'submit') {
this.tryChildrenToHandle(
{
@ -644,14 +647,18 @@ export class DialogRenderer extends Dialog {
onConfirm([data], action, data, []);
}
} else if (action.actionType === 'dialog') {
store.setCurrentAction(action);
store.openDialog(data);
} else if (action.actionType === 'drawer') {
store.setCurrentAction(action);
store.openDrawer(data);
} else if (action.actionType === 'reload') {
store.setCurrentAction(action);
action.target && scoped.reload(action.target, data);
} else if (this.tryChildrenToHandle(action, data)) {
// do nothing
} else if (action.actionType === 'ajax') {
store.setCurrentAction(action);
store
.saveRemote(action.api as string, data, {
successMessage: action.messages && action.messages.success,

View File

@ -633,21 +633,26 @@ export class DrawerRenderer extends Drawer {
}
const scoped = this.context as IScopedContext;
delegate || store.setCurrentAction(action);
if (action.actionType === 'close') {
store.setCurrentAction(action);
onClose();
} else if (action.actionType === 'confirm') {
store.setCurrentAction(action);
this.tryChildrenToHandle(action, data) || onClose();
} else if (action.actionType === 'drawer') {
store.setCurrentAction(action);
store.openDrawer(data);
} else if (action.actionType === 'dialog') {
store.setCurrentAction(action);
store.openDialog(data);
} else if (action.actionType === 'reload') {
store.setCurrentAction(action);
action.target && scoped.reload(action.target, data);
} else if (this.tryChildrenToHandle(action, data)) {
// do nothing
} else if (action.actionType === 'ajax') {
store.setCurrentAction(action);
store
.saveRemote(action.api as string, data, {
successMessage: action.messages && action.messages.success,

View File

@ -582,12 +582,12 @@ export default class Form extends React.Component<FormProps, object> {
});
}
delegate || store.setCurrentAction(action);
if (
action.type === 'submit' ||
action.actionType === 'submit' ||
action.actionType === 'confirm'
) {
store.setCurrentAction(action);
return this.submit(
(values): any => {
if (onSubmit && onSubmit(values, action) === false) {
@ -669,12 +669,16 @@ export default class Form extends React.Component<FormProps, object> {
}
});
} else if (action.type === 'reset') {
store.setCurrentAction(action);
store.reset(onReset);
} else if (action.actionType === 'dialog') {
store.setCurrentAction(action);
store.openDialog(data);
} else if (action.actionType === 'drawer') {
store.setCurrentAction(action);
store.openDrawer(data);
} else if (action.actionType === 'ajax') {
store.setCurrentAction(action);
if (!isEffectiveApi(action.api)) {
return env.alert(`当 actionType 为 ajax 时,请设置 api 属性`);
}
@ -708,6 +712,7 @@ export default class Form extends React.Component<FormProps, object> {
})
.catch(() => {});
} else if (action.actionType === 'reload') {
store.setCurrentAction(action);
action.target && this.reloadTarget(action.target, data);
} else if (onAction) {
// 不识别的丢给上层去处理。