@c-standard/angular-devui-extension
Version:
an extensional components lib for devui
102 lines (96 loc) • 5.43 kB
JavaScript
import * as i0 from '@angular/core';
import { Component, Input, Injectable, NgModule } from '@angular/core';
import * as i1 from 'ng-devui';
import { AlertModule } from 'ng-devui';
import { CommonModule } from '@angular/common';
class NotifyComponent {
}
NotifyComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: NotifyComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
NotifyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.7", type: NotifyComponent, selector: "d-notify", inputs: { data: "data" }, ngImport: i0, template: `
<d-alert
[type]="data?.type || 'info'"
[closeable]="false"
>
{{ data?.message }}
</d-alert>
`, isInline: true, styles: ["d-alert{position:absolute;top:20px;left:50%;transform:translate(-50%);width:25vw;min-width:300px;z-index:var(--devui-z-index-full-page-overlay, 1080);box-shadow:var(--devui-shadow-length-base, 0 1px 4px 0) var(--devui-light-shadow, rgba(37, 43, 58, .1))}\n"], components: [{ type: i1.AlertComponent, selector: "d-alert", inputs: ["type", "cssClass", "closeable", "content", "showIcon", "dismissTime"], outputs: ["closeEvent"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: NotifyComponent, decorators: [{
type: Component,
args: [{ selector: 'd-notify', template: `
<d-alert
[type]="data?.type || 'info'"
[closeable]="false"
>
{{ data?.message }}
</d-alert>
`, styles: ["d-alert{position:absolute;top:20px;left:50%;transform:translate(-50%);width:25vw;min-width:300px;z-index:var(--devui-z-index-full-page-overlay, 1080);box-shadow:var(--devui-shadow-length-base, 0 1px 4px 0) var(--devui-light-shadow, rgba(37, 43, 58, .1))}\n"] }]
}], propDecorators: { data: [{
type: Input
}] } });
class NotifyService {
constructor(
// todo 修改
componentFactoryResolver, appRef, injector) {
this.componentFactoryResolver = componentFactoryResolver;
this.appRef = appRef;
this.injector = injector;
}
notify(options) {
const data = {
message: options?.message,
type: options?.type,
};
// 1. Create a component reference from the component
const componentRef = this.componentFactoryResolver
.resolveComponentFactory(NotifyComponent)
.create(this.injector);
componentRef.instance.data = data;
// 2. Attach component to the appRef so that it's inside the ng component tree
this.appRef.attachView(componentRef.hostView);
// 3. Get DOM element from component
const domElem = componentRef.hostView.rootNodes[0];
// 4. Append DOM element to the body
document.body.appendChild(domElem);
// 6. Wait some time and remove it from the component tree and from the DOM
setTimeout(() => {
if (componentRef) {
this.appRef.detachView(componentRef.hostView);
componentRef.destroy();
}
}, options?.delay || 1000);
}
warring(message) {
this.notify({ type: 'warning', message: message });
}
success(message) {
this.notify({ type: 'success', message: message });
}
error(message) {
this.notify({ type: 'danger', message: message });
}
}
NotifyService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: NotifyService, deps: [{ token: i0.ComponentFactoryResolver }, { token: i0.ApplicationRef }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
NotifyService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: NotifyService, providedIn: 'root' });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: NotifyService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root',
}]
}], ctorParameters: function () { return [{ type: i0.ComponentFactoryResolver }, { type: i0.ApplicationRef }, { type: i0.Injector }]; } });
class NotifyModule {
}
NotifyModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: NotifyModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
NotifyModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: NotifyModule, declarations: [NotifyComponent], imports: [AlertModule, CommonModule] });
NotifyModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: NotifyModule, imports: [[AlertModule, CommonModule]] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: NotifyModule, decorators: [{
type: NgModule,
args: [{
declarations: [NotifyComponent],
imports: [AlertModule, CommonModule],
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { NotifyModule, NotifyService };
//# sourceMappingURL=c-standard-angular-devui-extension-notify.mjs.map