Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module:modal): loading state (confirmLoading) of default footer in modal opened by nzModalService #340

Merged
merged 1 commit into from
Sep 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/components/modal/nz-modal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface ConfigInterface {
maskClosable?: boolean;
wrapClassName?: string;
footer?: TemplateRef<any> | boolean;
showConfirmLoading?: boolean;
onOk?: Function;
onCancel?: Function;
componentParams?: Object;
Expand Down Expand Up @@ -81,16 +82,20 @@ export class NzModalService {
}
});

props[ 'onOk' ] = this._getConfirmCb(props[ 'nzOnOk' ]);
const isShowConfirmLoading = !!config[ 'showConfirmLoading' ];
props[ 'onOk' ] = this._getConfirmCb(props[ 'nzOnOk' ], isShowConfirmLoading);
props[ 'onCancel' ] = this._getConfirmCb(props[ 'nzOnCancel' ]);
// 在service模式下,不需要nzOnOk,防止触发this.nzOnOk.emit(e);
delete props[ 'nzOnOk' ];
delete props[ 'nzOnCancel' ];
return props;
}

_getConfirmCb(fn?: Function): Function {
return (_close) => {
_getConfirmCb(fn?: Function, isShowConfirmLoading: boolean = false): Function {
return (_close, _instance) => {
if (isShowConfirmLoading) {
_instance.nzConfirmLoading = true;
}
if (fn) {
const ret = fn();
if (!ret) {
Expand Down Expand Up @@ -132,7 +137,7 @@ export class NzModalService {
setTimeout(() => {
compRef.destroy();
}, 200);
});
}, instance);
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class NzDemoConfirmAsyncComponent {
this.confirmServ.confirm({
title : '您是否确认要删除这项内容',
content: '点确认 1 秒后关闭',
showConfirmLoading: true,
onOk() {
return new Promise((resolve) => {
setTimeout(resolve, 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class NzDemoModalServiceComponent {
title : '对话框标题',
content : '纯文本内容,点确认 1 秒后关闭',
closable: false,
showConfirmLoading: true,
onOk() {
return new Promise((resolve) => {
setTimeout(resolve, 1000);
Expand Down
9 changes: 8 additions & 1 deletion src/showcase/nz-demo-modal/nz-demo-modal.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<article>
<article>
<section class="markdown"><h1>Modal 对话框</h1>
<section class="markdown"><p>模态对话框。</p>
<h2 id="何时使用"><span>何时使用</span>
Expand Down Expand Up @@ -355,6 +355,13 @@ <h2 id="NzModalService_xxx"><span>NzModalService.xxx()</span>
<td>open</td>
<td>无</td>
</tr>
<tr>
<td>showConfirmLoading</td>
<td>如果footer没有指定(即展示默认footer)时,确定按钮在执行确定回调时是否显示 loading 状态</td>
<td>Boolean</td>
<td>All</td>
<td>false</td>
</tr>
</tbody>
</table>
<h2 id="NzModalSubject"><span>NzModalSubject对象</span>
Expand Down