ohayolibs
Version:
Ohayo is a set of essential modules for ohayojp.
91 lines (74 loc) • 2.39 kB
text/typescript
import { ChangeDetectionStrategy, Component, ElementRef, Input, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import { DomSanitizer, SafeHtml, SafeUrl } from '@angular/platform-browser';
import { OhayoLocaleService, LocaleData } from '@ohayo/theme';
import { isEmpty } from '@ohayo/util';
import { Subscription } from 'rxjs';
export type ExceptionType = 403 | 404 | 500;
export class ExceptionComponent implements OnInit, OnDestroy {
static ngAcceptInputType_type: ExceptionType | string;
private i18n$: Subscription;
private conTpl: ElementRef;
_type: ExceptionType;
locale: LocaleData = {};
hasCon = false;
_img: SafeUrl = '';
_title: SafeHtml = '';
_desc: SafeHtml = '';
set type(value: ExceptionType) {
const item = {
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',
},
}[value];
if (!item) return;
this.fixImg(item.img);
this._type = value;
this._title = item.title;
this._desc = '';
}
private fixImg(src: string): void {
this._img = this.dom.bypassSecurityTrustStyle(`url('${src}')`);
}
set img(value: string) {
this.fixImg(value);
}
set title(value: string) {
this._title = this.dom.bypassSecurityTrustHtml(value);
}
set desc(value: string) {
this._desc = this.dom.bypassSecurityTrustHtml(value);
}
checkContent(): void {
this.hasCon = !isEmpty(this.conTpl.nativeElement);
}
constructor(private i18n: OhayoLocaleService, private dom: DomSanitizer) { }
ngOnInit(): void {
this.i18n$ = this.i18n.change.subscribe(() => (this.locale = this.i18n.getData('exception')));
this.checkContent();
}
ngOnDestroy(): void {
this.i18n$.unsubscribe();
}
}