@c-standard/angular-devui-extension
Version:
an extensional components lib for devui
1 lines • 6.56 kB
Source Map (JSON)
{"version":3,"file":"c-standard-angular-devui-extension-notify.mjs","sources":["../../../projects/components/notify/notify.component.ts","../../../projects/components/notify/notify.service.ts","../../../projects/components/notify/notify.module.ts","../../../projects/components/notify/c-standard-angular-devui-extension-notify.ts"],"sourcesContent":["import { Component, Input } from '@angular/core';\r\nimport { NotifyOptions } from './notify';\r\n\r\n@Component({\r\n selector: 'd-notify',\r\n template: `\r\n <d-alert\r\n [type]=\"data?.type || 'info'\"\r\n [closeable]=\"false\"\r\n >\r\n {{ data?.message }}\r\n </d-alert>\r\n `,\r\n styleUrls: ['./notify.component.less'],\r\n})\r\nexport class NotifyComponent {\r\n @Input() data?: NotifyOptions;\r\n}\r\n","import {\r\n ApplicationRef,\r\n ComponentFactoryResolver,\r\n EmbeddedViewRef,\r\n Injectable,\r\n Injector,\r\n} from '@angular/core';\r\nimport { NotifyOptions } from './notify';\r\nimport { NotifyComponent } from './notify.component';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class NotifyService {\r\n constructor(\r\n // todo 修改\r\n private componentFactoryResolver: ComponentFactoryResolver,\r\n private appRef: ApplicationRef,\r\n private injector: Injector\r\n ) {}\r\n\r\n notify(options?: NotifyOptions) {\r\n const data: any = {\r\n message: options?.message,\r\n type: options?.type,\r\n };\r\n // 1. Create a component reference from the component\r\n const componentRef = this.componentFactoryResolver\r\n .resolveComponentFactory(NotifyComponent)\r\n .create(this.injector);\r\n\r\n componentRef.instance.data = data;\r\n // 2. Attach component to the appRef so that it's inside the ng component tree\r\n this.appRef.attachView(componentRef.hostView);\r\n\r\n // 3. Get DOM element from component\r\n const domElem = (componentRef.hostView as EmbeddedViewRef<any>).rootNodes[0] as HTMLElement;\r\n\r\n // 4. Append DOM element to the body\r\n document.body.appendChild(domElem);\r\n\r\n // 6. Wait some time and remove it from the component tree and from the DOM\r\n setTimeout(() => {\r\n if (componentRef) {\r\n this.appRef.detachView(componentRef.hostView);\r\n componentRef.destroy();\r\n }\r\n }, options?.delay || 1000);\r\n }\r\n\r\n warring(message?: string) {\r\n this.notify({ type: 'warning', message: message });\r\n }\r\n\r\n success(message?: string) {\r\n this.notify({ type: 'success', message: message });\r\n }\r\n\r\n error(message?: string) {\r\n this.notify({ type: 'danger', message: message });\r\n }\r\n}\r\n","import { NgModule } from '@angular/core';\r\nimport { NotifyComponent } from './notify.component';\r\nimport { AlertModule } from 'ng-devui';\r\nimport { CommonModule } from '@angular/common';\r\n\r\n@NgModule({\r\n declarations: [NotifyComponent],\r\n imports: [AlertModule, CommonModule],\r\n})\r\nexport class NotifyModule {}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;MAea,eAAe,CAAA;;4GAAf,eAAe,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA,CAAA;AAAf,eAAA,CAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,IAAA,EAAA,eAAe,EAVd,QAAA,EAAA,UAAA,EAAA,MAAA,EAAA,EAAA,IAAA,EAAA,MAAA,EAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,EAAA,CAAA;;;;;;;AAOT,IAAA,CAAA,EAAA,QAAA,EAAA,IAAA,EAAA,MAAA,EAAA,CAAA,kQAAA,CAAA,EAAA,UAAA,EAAA,CAAA,EAAA,IAAA,EAAA,EAAA,CAAA,cAAA,EAAA,QAAA,EAAA,SAAA,EAAA,MAAA,EAAA,CAAA,MAAA,EAAA,UAAA,EAAA,WAAA,EAAA,SAAA,EAAA,UAAA,EAAA,aAAA,CAAA,EAAA,OAAA,EAAA,CAAA,YAAA,CAAA,EAAA,CAAA,EAAA,CAAA,CAAA;2FAGQ,eAAe,EAAA,UAAA,EAAA,CAAA;kBAZ3B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