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