onAction 的代理模式整理 & url\link\jump 类型时依然处理 reload 逻辑

This commit is contained in:
2betop 2020-01-07 10:41:58 +08:00
parent 2cedd55790
commit 27ff80788c
6 changed files with 30 additions and 16 deletions

View File

@ -301,7 +301,8 @@ export default class CRUD extends React.Component<CRUDProps, any> {
e: React.UIEvent<any> | undefined,
action: Action,
ctx: object,
delegate?: boolean
throwErrors: boolean = false,
delegate?: IScopedContext
): any {
const {
onAction,
@ -367,7 +368,7 @@ export default class CRUD extends React.Component<CRUDProps, any> {
items: store.selectedItems.concat()
});
} else {
onAction(e, action, ctx);
onAction(e, action, ctx, throwErrors, delegate || this.context);
}
}
@ -441,7 +442,7 @@ export default class CRUD extends React.Component<CRUDProps, any> {
})
.catch(() => null);
} else if (onAction) {
onAction(e, action, ctx);
onAction(e, action, ctx, false, this.context);
}
}

View File

@ -599,12 +599,14 @@ export class DialogRenderer extends Dialog {
action: Action,
data: object,
throwErrors: boolean = false,
delegate?: boolean
delegate?: IScopedContext
) {
const {onAction, store, onConfirm, env} = this.props;
if (action.from === this.$$id) {
return onAction ? onAction(e, action, data, throwErrors, true) : false;
return onAction
? onAction(e, action, data, throwErrors, this.context)
: false;
}
const scoped = this.context as IScopedContext;
@ -666,7 +668,7 @@ export class DialogRenderer extends Dialog {
})
.catch(() => {});
} else if (onAction) {
let ret = onAction(e, action, data, throwErrors, true);
let ret = onAction(e, action, data, throwErrors, this.context);
action.close &&
(ret && ret.then
? ret.then(this.handleSelfClose)

View File

@ -622,12 +622,14 @@ export class DrawerRenderer extends Drawer {
action: Action,
data: object,
throwErrors: boolean = false,
delegate?: boolean
delegate?: IScopedContext
) {
const {onClose, onAction, store, env} = this.props;
if (action.from === this.$$id) {
return onAction ? onAction(e, action, data, throwErrors, true) : false;
return onAction
? onAction(e, action, data, throwErrors, this.context)
: false;
}
const scoped = this.context as IScopedContext;
@ -663,7 +665,7 @@ export class DrawerRenderer extends Drawer {
})
.catch(() => {});
} else if (onAction) {
let ret = onAction(e, action, data, throwErrors, true);
let ret = onAction(e, action, data, throwErrors, this.context);
action.close &&
(ret && ret.then
? ret.then(this.handleSelfClose)

View File

@ -529,7 +529,7 @@ export default class Form extends React.Component<FormProps, object> {
action: Action,
data: object,
throwErrors: boolean = false,
delegate?: boolean
delegate?: IScopedContext
): any {
const {
store,
@ -711,7 +711,7 @@ export default class Form extends React.Component<FormProps, object> {
action.target && this.reloadTarget(action.target, data);
} else if (onAction) {
// 不识别的丢给上层去处理。
return onAction(e, action, data, throwErrors);
return onAction(e, action, data, throwErrors, this.context);
}
}
@ -1158,7 +1158,7 @@ export class FormRenderer extends Form {
action: Action,
ctx: object,
throwErrors: boolean = false,
delegate?: boolean
delegate?: IScopedContext
) {
if (action.target && action.actionType !== 'reload') {
const scoped = this.context as IScopedContext;

View File

@ -181,7 +181,8 @@ export default class Page extends React.Component<PageProps> {
e: React.UIEvent<any> | void,
action: Action,
ctx: object,
delegate?: boolean
throwErrors: boolean = false,
delegate?: IScopedContext
) {
const {env, store, messages} = this.props;
@ -543,7 +544,7 @@ export class PageRenderer extends Page {
action: Action,
ctx: object,
throwErrors: boolean = false,
delegate?: boolean
delegate?: IScopedContext
) {
const scoped = this.context as IScopedContext;
@ -563,7 +564,15 @@ export class PageRenderer extends Page {
);
});
} else {
super.handleAction(e, action, ctx, delegate);
super.handleAction(e, action, ctx, throwErrors, delegate);
if (
action.reload &&
~['url', 'link', 'jump'].indexOf(action.actionType!)
) {
const scoped = delegate || (this.context as IScopedContext);
scoped.reload(action.reload, ctx);
}
}
}

View File

@ -401,7 +401,7 @@ export default class Wizard extends React.Component<WizardProps, WizardState> {
} else if (action.actionType === 'reload') {
action.target && this.reloadTarget(action.target, data);
} else if (onAction) {
onAction(e, action, data);
onAction(e, action, data, false, this.context);
}
}