scoped中来关闭子弹框
This commit is contained in:
parent
52c30c75b7
commit
8ce313bfde
|
@ -26,13 +26,14 @@ export interface ScopedComponentType extends React.Component<RendererProps> {
|
|||
query?: RendererData | null,
|
||||
ctx?: RendererData
|
||||
) => void;
|
||||
context: any;
|
||||
}
|
||||
|
||||
export interface IScopedContext {
|
||||
parent?: AlisIScopedContext;
|
||||
registerComponent: (component: ScopedComponentType) => void;
|
||||
unRegisterComponent: (component: ScopedComponentType) => void;
|
||||
getComponentByName: (name: string) => ScopedComponentType | void;
|
||||
getComponentByName: (name: string) => ScopedComponentType;
|
||||
getComponents: () => Array<ScopedComponentType>;
|
||||
reload: (target: string, ctx: RendererData) => void;
|
||||
send: (target: string, ctx: RendererData) => void;
|
||||
|
@ -172,14 +173,28 @@ function createScopedTools(
|
|||
let targets =
|
||||
typeof target === 'string' ? target.split(/\s*,\s*/) : target;
|
||||
|
||||
targets.forEach(name => {
|
||||
const component = scoped.getComponentByName(name);
|
||||
component && component.props.onClose && component.props.onClose();
|
||||
});
|
||||
// 过滤已经关掉的,当用户 close 配置多个弹框 name 时会出现这种情况
|
||||
targets
|
||||
.map(name => scoped.getComponentByName(name))
|
||||
.filter(component => component && component.props.show)
|
||||
.forEach(closeDialog);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function closeDialog(component: ScopedComponentType) {
|
||||
(component.context as IScopedContext)
|
||||
.getComponents()
|
||||
.filter(
|
||||
item =>
|
||||
item &&
|
||||
(item.props.type === 'dialog' || item.props.type === 'drawer') &&
|
||||
item.props.show
|
||||
)
|
||||
.forEach(closeDialog);
|
||||
component.props.onClose && component.props.onClose();
|
||||
}
|
||||
|
||||
export function HocScoped<
|
||||
T extends {
|
||||
$path?: string;
|
||||
|
|
|
@ -364,10 +364,7 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
|||
action.reload
|
||||
? this.reloadTarget(action.reload, data)
|
||||
: this.search(undefined, undefined, true, true);
|
||||
if (action.close) {
|
||||
onClose();
|
||||
this.closeTarget(action.close);
|
||||
}
|
||||
action.close && this.closeTarget(action.close);
|
||||
})
|
||||
.catch(() => {});
|
||||
} else if (
|
||||
|
|
|
@ -305,7 +305,6 @@ export default class Dialog extends React.Component<DialogProps, DialogState> {
|
|||
key,
|
||||
disabled: (body && (body as any).disabled) || store.loading,
|
||||
onAction: this.handleAction,
|
||||
onClose: this.handleSelfClose,
|
||||
onFinished: this.handleChildFinished,
|
||||
affixOffsetTop: 0,
|
||||
onChange: this.handleFormChange,
|
||||
|
|
|
@ -275,7 +275,6 @@ export default class Drawer extends React.Component<DrawerProps, object> {
|
|||
key,
|
||||
disabled: store.loading,
|
||||
onAction: this.handleAction,
|
||||
onClose: this.handleSelfClose,
|
||||
onFinished: this.handleChildFinished,
|
||||
popOverContainer: this.getPopOverContainer,
|
||||
onChange: this.handleFormChange,
|
||||
|
|
|
@ -748,10 +748,7 @@ export default class Form extends React.Component<FormProps, object> {
|
|||
redirect && env.jumpTo(redirect, action);
|
||||
|
||||
action.reload && this.reloadTarget(action.reload, store.data);
|
||||
if (action.close) {
|
||||
onClose();
|
||||
this.closeTarget(action.close);
|
||||
}
|
||||
action.close && this.closeTarget(action.close);
|
||||
})
|
||||
.catch(() => {});
|
||||
} else if (action.actionType === 'reload') {
|
||||
|
|
Loading…
Reference in New Issue