import { Injectable } from '@angular/core' ; import { NzModalService , NzModalSubject } from 'ng-zorro-antd' ; import { Observable } from 'rxjs/Observable' ; import { filter , tap } from 'rxjs/operators' ; /**
 * 对话框辅助类
 */ @ Injectable ( ) export class ModalHelper { private queues : NzModalSubject [ ] = [ ] ; private zIndex = 500 ; constructor ( private modalSrv ) { } /**
     * 移除当前所有对话框
     */ removeAll ( ) { this . queues . forEach ( ( item ) => { item . destroy ( ) ; } ) ; } param { * } comp param { * } params param { ( 'sm' | 'lg' | '' | number ) } size param { * } options open ( comp , params ? , size = 'lg' , options ? ) { let cls = '' , width = '' ; if ( size ) { if ( typeof size === 'number' ) { width = `${ size }px` ; } else { cls = `modal-${ size }` ; } } const subject = this . modalSrv . open ( Object . assign ( { wrapClassName : cls , content : comp , width : width ? width : undefined , footer : false , componentParams : params , zIndex : ++ this . zIndex , maskClosable : false , } , options || { } ) ) ; this . queues . push ( subject ) ; return subject . pipe ( filter ( ( res ) => { let findIdx = - 1 ; if ( typeof res === 'string' ) { const resStr = res as string ; findIdx = [ 'onShow' , 'onShown' , 'onHide' , 'onHidden' , 'onCancel' , 'onDestroy' ] . findIndex ( w => resStr . startsWith ( w ) ) ; } return findIdx === - 1 ; } ) , tap ( ( ) => { this . queues . pop ( ) ; } ) ) ; } /**
     * 静态框，点击蒙层不允许关闭
     */ static ( comp , params ? , size = 'lg' , options ? ) { return this . open ( comp , params , size , Object . assign ( { maskClosable : false } , options ) ) ; } }