UNPKG

@delon/abc

Version:

Common business components of ng-alain.

126 lines (121 loc) 8.15 kB
import { Directionality } from '@angular/cdk/bidi'; import { CdkObserveContent, ObserversModule } from '@angular/cdk/observers'; import * as i0 from '@angular/core'; import { inject, ChangeDetectorRef, DestroyRef, Component, ChangeDetectionStrategy, ViewEncapsulation, ViewChild, Input, NgModule } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { DomSanitizer } from '@angular/platform-browser'; import { RouterLink, RouterModule } from '@angular/router'; import { DelonLocaleService, DelonLocaleModule } from '@delon/theme'; import { isEmpty } from '@delon/util/browser'; import { NzButtonComponent, NzButtonModule } from 'ng-zorro-antd/button'; import * as i1 from '@delon/util/config'; import { CommonModule } from '@angular/common'; class ExceptionComponent { set type(value) { const item = this.typeDict[value]; if (!item) return; this.fixImg(item.img); this._type = value; this._title = item.title; this._desc = ''; } fixImg(src) { this._img = this.dom.bypassSecurityTrustStyle(`url('${src}')`); } set img(value) { this.fixImg(value); } set title(value) { this._title = this.dom.bypassSecurityTrustHtml(value); } set desc(value) { this._desc = this.dom.bypassSecurityTrustHtml(value); } checkContent() { this.hasCon = !isEmpty(this.conTpl.nativeElement); this.cdr.detectChanges(); } constructor(configSrv) { this.i18n = inject(DelonLocaleService); this.dom = inject(DomSanitizer); this.directionality = inject(Directionality); this.cdr = inject(ChangeDetectorRef); this.destroy$ = inject(DestroyRef); this.locale = {}; this.hasCon = false; this.dir = 'ltr'; this._img = ''; this._title = ''; this._desc = ''; this.backRouterLink = '/'; configSrv.attach(this, 'exception', { typeDict: { 403: { img: 'https://gw.alipayobjects.com/zos/rmsportal/wZcnGqRDyhPOEYFcZDnb.svg', title: '403' }, 404: { img: 'https://gw.alipayobjects.com/zos/rmsportal/KpnpchXsobRgLElEozzI.svg', title: '404' }, 500: { img: 'https://gw.alipayobjects.com/zos/rmsportal/RVRUAYdCGeYNBWoKiIwB.svg', title: '500' } } }); } ngOnInit() { this.dir = this.directionality.value; this.directionality.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { this.dir = direction; this.cdr.detectChanges(); }); this.i18n.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(() => { this.locale = this.i18n.getData('exception'); this.cdr.detectChanges(); }); this.checkContent(); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.5", ngImport: i0, type: ExceptionComponent, deps: [{ token: i1.AlainConfigService }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.0.5", type: ExceptionComponent, isStandalone: true, selector: "exception", inputs: { type: "type", img: "img", title: "title", desc: "desc", backRouterLink: "backRouterLink" }, host: { properties: { "class.exception": "true", "class.exception-rtl": "dir === 'rtl'" } }, viewQueries: [{ propertyName: "conTpl", first: true, predicate: ["conTpl"], descendants: true, static: true }], exportAs: ["exception"], ngImport: i0, template: "<div class=\"exception__img-block\">\n <div class=\"exception__img\" [style.backgroundImage]=\"_img\"></div>\n</div>\n<div class=\"exception__cont\">\n <h1 class=\"exception__cont-title\" [innerHTML]=\"_title\"></h1>\n <div class=\"exception__cont-desc\" [innerHTML]=\"_desc || locale[_type]\"></div>\n <div class=\"exception__cont-actions\">\n <div (cdkObserveContent)=\"checkContent()\" #conTpl>\n <ng-content />\n </div>\n @if (!hasCon) {\n <button nz-button [routerLink]=\"backRouterLink\" [nzType]=\"'primary'\">\n {{ locale.backToHome }}\n </button>\n }\n </div>\n</div>\n", dependencies: [{ kind: "directive", type: CdkObserveContent, selector: "[cdkObserveContent]", inputs: ["cdkObserveContentDisabled", "debounce"], outputs: ["cdkObserveContent"], exportAs: ["cdkObserveContent"] }, { kind: "component", type: NzButtonComponent, selector: "button[nz-button], a[nz-button]", inputs: ["nzBlock", "nzGhost", "nzSearch", "nzLoading", "nzDanger", "disabled", "tabIndex", "nzType", "nzShape", "nzSize"], exportAs: ["nzButton"] }, { kind: "directive", type: RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.5", ngImport: i0, type: ExceptionComponent, decorators: [{ type: Component, args: [{ selector: 'exception', exportAs: 'exception', host: { '[class.exception]': 'true', '[class.exception-rtl]': `dir === 'rtl'` }, preserveWhitespaces: false, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, standalone: true, imports: [CdkObserveContent, NzButtonComponent, RouterLink], template: "<div class=\"exception__img-block\">\n <div class=\"exception__img\" [style.backgroundImage]=\"_img\"></div>\n</div>\n<div class=\"exception__cont\">\n <h1 class=\"exception__cont-title\" [innerHTML]=\"_title\"></h1>\n <div class=\"exception__cont-desc\" [innerHTML]=\"_desc || locale[_type]\"></div>\n <div class=\"exception__cont-actions\">\n <div (cdkObserveContent)=\"checkContent()\" #conTpl>\n <ng-content />\n </div>\n @if (!hasCon) {\n <button nz-button [routerLink]=\"backRouterLink\" [nzType]=\"'primary'\">\n {{ locale.backToHome }}\n </button>\n }\n </div>\n</div>\n" }] }], ctorParameters: () => [{ type: i1.AlainConfigService }], propDecorators: { conTpl: [{ type: ViewChild, args: ['conTpl', { static: true }] }], type: [{ type: Input }], img: [{ type: Input }], title: [{ type: Input }], desc: [{ type: Input }], backRouterLink: [{ type: Input }] } }); const COMPONENTS = [ExceptionComponent]; class ExceptionModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.5", ngImport: i0, type: ExceptionModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.0.5", ngImport: i0, type: ExceptionModule, imports: [CommonModule, ObserversModule, RouterModule, DelonLocaleModule, NzButtonModule, ExceptionComponent], exports: [ExceptionComponent] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.0.5", ngImport: i0, type: ExceptionModule, imports: [CommonModule, ObserversModule, RouterModule, DelonLocaleModule, NzButtonModule, COMPONENTS] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.5", ngImport: i0, type: ExceptionModule, decorators: [{ type: NgModule, args: [{ imports: [CommonModule, ObserversModule, RouterModule, DelonLocaleModule, NzButtonModule, ...COMPONENTS], exports: COMPONENTS }] }] }); /** * Generated bundle index. Do not edit. */ export { ExceptionComponent, ExceptionModule }; //# sourceMappingURL=exception.mjs.map