import { Injectable } from '@angular/core'; import { NzNotificationService } from 'ng-zorro-antd/notification'; import { NzMessageService } from 'ng-zorro-antd/message'; @Injectable({ providedIn: 'root' }) export class GlobalService { constructor( private nzNotificationService: NzNotificationService, private nzMessageService: NzMessageService, ) { } /** * 创建全局提示框 * @param type 消息提示类型 'success' | 'error' | 'info' | 'warning' | 'loading' * @param title 消息提示标题 */ message(type: 'success' | 'error' | 'info' | 'warning' | 'loading', title) { this.nzMessageService[type](title, { nzDuration: 2000 }); } /** * 创建通知提醒框 * @param type 类型 'success' | 'info' | 'warning' | 'error' * @param title 标题 * @param content 内容 */ notice(type: 'success' | 'info' | 'warning' | 'error', title, content?) { this.nzNotificationService[type]( title, content, { nzDuration: 2000 } ); } }