Skip to content

Commit 90b7e12

Browse files
alchexievthinkxie
authored andcommitted
feat(module:modal): show confirm loading status of modal opened by nzModalService (#340)
close #365
1 parent 60e3da9 commit 90b7e12

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

src/components/modal/nz-modal.service.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface ConfigInterface {
2929
maskClosable?: boolean;
3030
wrapClassName?: string;
3131
footer?: TemplateRef<any> | boolean;
32+
showConfirmLoading?: boolean;
3233
onOk?: Function;
3334
onCancel?: Function;
3435
componentParams?: Object;
@@ -81,16 +82,20 @@ export class NzModalService {
8182
}
8283
});
8384

84-
props[ 'onOk' ] = this._getConfirmCb(props[ 'nzOnOk' ]);
85+
const isShowConfirmLoading = !!config[ 'showConfirmLoading' ];
86+
props[ 'onOk' ] = this._getConfirmCb(props[ 'nzOnOk' ], isShowConfirmLoading);
8587
props[ 'onCancel' ] = this._getConfirmCb(props[ 'nzOnCancel' ]);
8688
// 在service模式下,不需要nzOnOk,防止触发this.nzOnOk.emit(e);
8789
delete props[ 'nzOnOk' ];
8890
delete props[ 'nzOnCancel' ];
8991
return props;
9092
}
9193

92-
_getConfirmCb(fn?: Function): Function {
93-
return (_close) => {
94+
_getConfirmCb(fn?: Function, isShowConfirmLoading: boolean = false): Function {
95+
return (_close, _instance) => {
96+
if (isShowConfirmLoading) {
97+
_instance.nzConfirmLoading = true;
98+
}
9499
if (fn) {
95100
const ret = fn();
96101
if (!ret) {
@@ -132,7 +137,7 @@ export class NzModalService {
132137
setTimeout(() => {
133138
compRef.destroy();
134139
}, 200);
135-
});
140+
}, instance);
136141
}
137142
});
138143
});

src/showcase/nz-demo-modal/nz-demo-confirm-async.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class NzDemoConfirmAsyncComponent {
1616
this.confirmServ.confirm({
1717
title : '您是否确认要删除这项内容',
1818
content: '点确认 1 秒后关闭',
19+
showConfirmLoading: true,
1920
onOk() {
2021
return new Promise((resolve) => {
2122
setTimeout(resolve, 1000);

src/showcase/nz-demo-modal/nz-demo-modal-service.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class NzDemoModalServiceComponent {
4949
title : '对话框标题',
5050
content : '纯文本内容,点确认 1 秒后关闭',
5151
closable: false,
52+
showConfirmLoading: true,
5253
onOk() {
5354
return new Promise((resolve) => {
5455
setTimeout(resolve, 1000);

src/showcase/nz-demo-modal/nz-demo-modal.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<article>
1+
<article>
22
<section class="markdown"><h1>Modal 对话框</h1>
33
<section class="markdown"><p>模态对话框。</p>
44
<h2 id="何时使用"><span>何时使用</span>
@@ -355,6 +355,13 @@ <h2 id="NzModalService_xxx"><span>NzModalService.xxx()</span>
355355
<td>open</td>
356356
<td></td>
357357
</tr>
358+
<tr>
359+
<td>showConfirmLoading</td>
360+
<td>如果footer没有指定(即展示默认footer)时,确定按钮在执行确定回调时是否显示 loading 状态</td>
361+
<td>Boolean</td>
362+
<td>All</td>
363+
<td>false</td>
364+
</tr>
358365
</tbody>
359366
</table>
360367
<h2 id="NzModalSubject"><span>NzModalSubject对象</span>

0 commit comments

Comments
 (0)