import { Injectable , TemplateRef , Type } from '@angular/core' ; import { Observable , Observer } from 'rxjs' ; import { deepMerge } from '@delon/util/other' ; import type { NzSafeAny } from 'ng-zorro-antd/core/types' ; import { ModalOptions , NzModalService } from 'ng-zorro-antd/modal' ; export interface ModalHelperOptions { /** 大小；例如：lg、600，默认：`lg` */ size ? : 'sm' | 'md' | 'lg' | 'xl' | '' | number ; /** 对话框 [ModalOptions](https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/components/modal/modal-types.ts) 参数 */ modalOptions ? : ModalOptions ; /** 是否精准（默认：`true`），若返回值非空值（`null`或`undefined`）视为成功，否则视为错误 */ exact ? : boolean ; /** 是否包裹标签页，修复模态包含标签间距问题 */ includeTabs ? : boolean ; } /**
 * 对话框辅助类
 */ @ Injectable ( { providedIn : 'root' } ) export class ModalHelper { constructor ( private srv ) { } param comp param params param options example create ( comp , params ? , options ? ) { options = deepMerge ( { size : 'lg' , exact : true , includeTabs : false } , options ) ; return new Observable ( ( observer ) => { const { size , includeTabs , modalOptions } = options as ModalHelperOptions ; let cls = '' ; let width = '' ; if ( size ) { if ( typeof size === 'number' ) { width = `${ size }px` ; } else { cls = `modal-${ size }` ; } } if ( includeTabs ) { cls += ' modal-include-tabs' ; } if ( modalOptions && modalOptions . nzWrapClassName ) { cls += ` ${ modalOptions . nzWrapClassName }` ; delete modalOptions . nzWrapClassName ; } const defaultOptions = { nzWrapClassName : cls , nzContent : comp , nzWidth : width ? width : undefined , nzFooter : null , nzComponentParams : params } ; const subject = this . srv . create ( { ... defaultOptions , ... modalOptions } ) ; const afterClose$ = subject . afterClose . subscribe ( ( res ) => { if ( options ! . exact === true ) { if ( res != null ) { observer . next ( res ) ; } } else { observer . next ( res ) ; } observer . complete ( ) ; afterClose$ . unsubscribe ( ) ; } ) ; } ) ; } param comp param params param options example createStatic ( comp , params ? , options ? ) { const modalOptions = { nzMaskClosable : false , ... ( options && options . modalOptions ) } ; return this . create ( comp , params , { ... options , modalOptions } ) ; } }