UNPKG

@ng-arthur/core

Version:

@ng-arthur/core for Angular 8+ Components

1,273 lines (1,240 loc) 44.6 kB
import { __decorate, __metadata, __extends, __param, __spread } from 'tslib'; import { Input, Directive, Injectable, Pipe, NgModule, ɵɵdefineInjectable, ɵɵinject, EventEmitter, Component, ViewEncapsulation, Output, ChangeDetectionStrategy, Inject, ElementRef, InjectionToken, Injector, APP_INITIALIZER, Optional, SkipSelf, INJECTOR } from '@angular/core'; import { TranslateDirective, TranslatePipe, TranslateModule, TranslateService, TranslateLoader } from '@ngx-translate/core'; import { BehaviorSubject, of, throwError, forkJoin } from 'rxjs'; import { filter, share, switchMap, map, tap, catchError } from 'rxjs/operators'; import { CommonModule, DOCUMENT } from '@angular/common'; import { configure, start, done } from 'nprogress'; import QRCode from 'qrcode'; import { HttpClient } from '@angular/common/http'; import { NaUtils } from '@ng-arthur/common'; import merge from 'deepmerge'; import { Meta, Title } from '@angular/platform-browser'; import { ActivatedRoute } from '@angular/router'; var NaI18NDirective = /** @class */ (function () { function NaI18NDirective(translate) { this.translate = translate; } Object.defineProperty(NaI18NDirective.prototype, "naI18n", { set: function (key) { this.translate.translate = key; }, enumerable: true, configurable: true }); Object.defineProperty(NaI18NDirective.prototype, "naI18nParams", { set: function (params) { this.translate.translateParams = params; }, enumerable: true, configurable: true }); __decorate([ Input(), __metadata("design:type", String), __metadata("design:paramtypes", [String]) ], NaI18NDirective.prototype, "naI18n", null); __decorate([ Input(), __metadata("design:type", Object), __metadata("design:paramtypes", [Object]) ], NaI18NDirective.prototype, "naI18nParams", null); NaI18NDirective = __decorate([ Directive({ selector: '[naI18n]' }), __metadata("design:paramtypes", [TranslateDirective]) ], NaI18NDirective); return NaI18NDirective; }()); var NaI18NPipe = /** @class */ (function () { function NaI18NPipe(translate) { this.translate = translate; } NaI18NPipe.prototype.transform = function (value, args) { return this.translate.transform(value, args); }; NaI18NPipe = __decorate([ Injectable(), Pipe({ name: 'naI18N', pure: false // required to update the value when the promise is resolved }), __metadata("design:paramtypes", [TranslatePipe]) ], NaI18NPipe); return NaI18NPipe; }()); var NaI18NModule = /** @class */ (function () { function NaI18NModule() { } NaI18NModule = __decorate([ NgModule({ imports: [ TranslateModule, ], exports: [ TranslateModule, NaI18NPipe, NaI18NDirective ], declarations: [ NaI18NPipe, NaI18NDirective ], }) ], NaI18NModule); return NaI18NModule; }()); var NaTranslateService = /** @class */ (function () { function NaTranslateService(translate) { this.translate = translate; this.change$ = new BehaviorSubject(new Object()); if (translate.getLangs() == null || translate.getLangs().length <= 0) { // translate.addLangs(['zh', 'en']); translate.addLangs([this.translate.getBrowserLang()]); } // if (this.translate.currentLang == null) { // this.translate.use(this.translate.getBrowserLang()); // } if (this.translate.getDefaultLang() == null) { // this.translate.setDefaultLang(this.translate.getBrowserCultureLang()); // zh_CN this.translate.setDefaultLang(this.translate.getBrowserLang()); // zh } } Object.defineProperty(NaTranslateService.prototype, "change", { get: function () { return this.change$.asObservable().pipe(filter(function (w) { return w != null; })); }, enumerable: true, configurable: true }); Object.defineProperty(NaTranslateService.prototype, "currentLang", { get: function () { return this.translate.currentLang; }, enumerable: true, configurable: true }); /** * Gets the translated value of a key (or an array of keys) */ NaTranslateService.prototype.get = function (key, interpolateParams) { return this.translate.get(key, interpolateParams); }; /** * Returns a stream of translated values of a key (or an array of keys) which updates * whenever the language changes. */ NaTranslateService.prototype.stream = function (key, interpolateParams) { return this.translate.stream(key, interpolateParams); }; /** * Returns a translation instantly from the internal state of loaded translation. * All rules regarding the current language, the preferred language of even fallback languages will be used except any promise handling. */ NaTranslateService.prototype.instant = function (key, interpolateParams) { return this.translate.instant(key, interpolateParams); }; /** * Changes the lang currently used */ NaTranslateService.prototype.use = function (lang) { this.change$.next(lang); return this.translate.use(lang); }; /** * Sets the default language to use as a fallback */ NaTranslateService.prototype.setDefaultLang = function (lang) { this.translate.setDefaultLang(lang); }; /** * Gets the default language used * @returns string */ NaTranslateService.prototype.getDefaultLang = function () { return this.translate.defaultLang; }; /** * Returns an array of currently available langs * @returns any */ NaTranslateService.prototype.getLangs = function () { return this.translate.langs; }; /** * @param langs * Add available langs */ NaTranslateService.prototype.addLangs = function (langs) { this.translate.addLangs(langs); }; /** * Sets the translated value of a key */ NaTranslateService.prototype.set = function (key, value, lang) { if (lang === void 0) { lang = this.translate.currentLang; } this.translate.set(key, value, lang); }; /** * Allows to reload the lang file from the file */ NaTranslateService.prototype.reloadLang = function (lang) { return this.translate.reloadLang(lang); }; /** * Deletes inner translation */ NaTranslateService.prototype.resetLang = function (lang) { this.translate.resetLang(lang); }; /** * Returns the language code name from the browser, e.g. "de" * * @returns string */ NaTranslateService.prototype.getBrowserLang = function () { return this.translate.getBrowserLang(); }; /** * Returns the culture language code name from the browser, e.g. "de-DE" * * @returns string */ NaTranslateService.prototype.getBrowserCultureLang = function () { return this.translate.getBrowserCultureLang(); }; NaTranslateService = __decorate([ Injectable(), __metadata("design:paramtypes", [TranslateService]) ], NaTranslateService); return NaTranslateService; }()); var NaI18NService = /** @class */ (function (_super) { __extends(NaI18NService, _super); function NaI18NService() { return _super !== null && _super.apply(this, arguments) || this; } NaI18NService.ngInjectableDef = ɵɵdefineInjectable({ factory: function NaI18NService_Factory() { return new NaI18NService(ɵɵinject(TranslateService)); }, token: NaI18NService, providedIn: "root" }); NaI18NService = __decorate([ Injectable({ providedIn: 'root' }) ], NaI18NService); return NaI18NService; }(NaTranslateService)); var NaMenuService = /** @class */ (function () { function NaMenuService(i18nSrv) { this.i18nSrv = i18nSrv; this._change$ = new BehaviorSubject([]); this.data = []; } Object.defineProperty(NaMenuService.prototype, "change", { get: function () { return this._change$.pipe(share()); }, enumerable: true, configurable: true }); NaMenuService.prototype.getPathByUrl = function (url) { return null; }; NaMenuService.prototype.ngOnDestroy = function () { if (this._change$) { this._change$.unsubscribe(); } if (this.i18n$) { this.i18n$.unsubscribe(); } }; NaMenuService.ngInjectableDef = ɵɵdefineInjectable({ factory: function NaMenuService_Factory() { return new NaMenuService(ɵɵinject(NaI18NService)); }, token: NaMenuService, providedIn: "root" }); NaMenuService = __decorate([ Injectable({ providedIn: 'root' }), __metadata("design:paramtypes", [NaI18NService]) ], NaMenuService); return NaMenuService; }()); var NaMessageService = /** @class */ (function () { function NaMessageService() { } NaMessageService.prototype.success = function (content, options) { throw new Error("\u8BF7\u5BFC\u5165NaMessageService\u5B9E\u73B0\u7C7B, \u9519\u8BEF\u4FE1\u606F: " + content); }; NaMessageService.prototype.error = function (content, options) { throw new Error("\u8BF7\u5BFC\u5165NaMessageService\u5B9E\u73B0\u7C7B, \u9519\u8BEF\u4FE1\u606F: " + content); }; NaMessageService.prototype.info = function (content, options) { throw new Error("\u8BF7\u5BFC\u5165NaMessageService\u5B9E\u73B0\u7C7B, \u9519\u8BEF\u4FE1\u606F: " + content); }; NaMessageService.prototype.warning = function (content, options) { throw new Error("\u8BF7\u5BFC\u5165NaMessageService\u5B9E\u73B0\u7C7B, \u9519\u8BEF\u4FE1\u606F: " + content); }; NaMessageService.prototype.loading = function (content, options) { throw new Error("\u8BF7\u5BFC\u5165NaMessageService\u5B9E\u73B0\u7C7B, \u9519\u8BEF\u4FE1\u606F: " + content); }; NaMessageService.prototype.hide = function () { }; NaMessageService = __decorate([ Injectable() ], NaMessageService); return NaMessageService; }()); var NaMessageModule = /** @class */ (function () { function NaMessageModule() { } NaMessageModule = __decorate([ NgModule({ imports: [ CommonModule ], providers: [ NaMessageService ] }) ], NaMessageModule); return NaMessageModule; }()); var DeleteEmptyFields = function (target, propertyKey, descriptor, bindingPropertyName) { console.log(target, propertyKey, descriptor, bindingPropertyName); function PropDecorator(_target, _name) { console.log(_target, _name); } return PropDecorator; }; function preloaderFinished() { var body = document.querySelector('body'); var preloader = document.querySelector('.preloader'); body.style.overflow = 'hidden'; function remove() { // preloader value null when running --hmr if (!preloader) { return; } preloader.addEventListener('transitionend', function () { preloader.className = 'preloader-hidden'; }); preloader.className += ' preloader-hidden-add preloader-hidden-add-active'; } window.appBootstrap = function () { setTimeout(function () { remove(); body.style.overflow = ''; }, 100); }; } var ProgressBarService = /** @class */ (function () { function ProgressBarService() { this.progressEmitter = new EventEmitter(); } ProgressBarService.prototype.start = function () { this.progressEmitter.emit(true); }; ProgressBarService.prototype.done = function () { this.progressEmitter.emit(false); }; ProgressBarService = __decorate([ Injectable(), __metadata("design:paramtypes", []) ], ProgressBarService); return ProgressBarService; }()); var ProgressBarComponent = /** @class */ (function () { function ProgressBarComponent(progressBarService) { this.progressBarService = progressBarService; // NProgressConfigureOptions this.options = { parent: '#container', showSpinner: false }; configure(this.options); this.progressEmitter$ = this.progressBarService.progressEmitter.subscribe(function (forceShow) { if (forceShow) { start(); } else { done(); } }); } Object.defineProperty(ProgressBarComponent.prototype, "progress", { set: function (forceShow) { this.progressBarService.progressEmitter.emit(forceShow); }, enumerable: true, configurable: true }); ProgressBarComponent.prototype.ngOnDestroy = function () { if (this.progressEmitter$) { this.progressEmitter$.unsubscribe(); } }; ProgressBarComponent.prototype.ngAfterViewInit = function () { }; ProgressBarComponent.prototype.ngAfterContentInit = function () { // NProgress.start(); }; ProgressBarComponent.prototype.ngOnChanges = function (changes) { // console.log(changes['progress']); }; __decorate([ Input(), __metadata("design:type", Object) ], ProgressBarComponent.prototype, "options", void 0); __decorate([ Input(), __metadata("design:type", Boolean), __metadata("design:paramtypes", [Boolean]) ], ProgressBarComponent.prototype, "progress", null); ProgressBarComponent = __decorate([ Component({ selector: 'na-progress-bar', template: "<div id=\"container\" style=\"height: 100%;\">\n <ng-content></ng-content>\n</div>\n", encapsulation: ViewEncapsulation.None, styles: ["#nprogress{pointer-events:none}#nprogress .bar{background:#29d;position:fixed;z-index:1031;top:0;left:0;width:100%;height:2px}#nprogress .peg{display:block;position:absolute;right:0;width:100px;height:100%;box-shadow:0 0 10px #29d,0 0 5px #29d;opacity:1;-webkit-transform:rotate(3deg) translate(0,-4px);transform:rotate(3deg) translate(0,-4px)}#nprogress .spinner{display:block;position:fixed;z-index:1031;top:15px;right:15px}#nprogress .spinner-icon{width:18px;height:18px;box-sizing:border-box;border:2px solid transparent;border-top-color:#29d;border-left-color:#29d;border-radius:50%;-webkit-animation:.4s linear infinite nprogress-spinner;animation:.4s linear infinite nprogress-spinner}.nprogress-custom-parent{overflow:hidden;position:relative}.nprogress-custom-parent #nprogress .bar,.nprogress-custom-parent #nprogress .spinner{position:absolute}@-webkit-keyframes nprogress-spinner{0%{-webkit-transform:rotate(0)}100%{-webkit-transform:rotate(360deg)}}@keyframes nprogress-spinner{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}"] }), __metadata("design:paramtypes", [ProgressBarService]) ], ProgressBarComponent); return ProgressBarComponent; }()); var ProgressBarModule = /** @class */ (function () { function ProgressBarModule() { } ProgressBarModule = __decorate([ NgModule({ imports: [ CommonModule ], exports: [ ProgressBarComponent ], declarations: [ ProgressBarComponent ], providers: [ ProgressBarService ] }) ], ProgressBarModule); return ProgressBarModule; }()); var NaQRCodeComponent = /** @class */ (function () { function NaQRCodeComponent(el, _doc) { this.el = el; this._doc = _doc; this.urlChange = new EventEmitter(); this.level = 'M'; /** * 定义周边区域应该有多宽。 */ this.margin = 0; this.type = 'image/jpeg'; /** * Height/Width */ this.size = 256; // /** // * 宽度 // */ // @Input() width = 256; // /** // * 高度 // */ // @Input() height: number; /** * 前景色,值必须为十六进制格式(RGBA) */ this.colorDark = '#000000'; /** * 背景色,值必须为十六进制格式(RGBA) */ this.colorLight = '#ffffff'; this.isValidQrCodeText = function (data) { // if (this.allowEmptyString === false) { // return !(typeof data === 'undefined' || data === ''); // } return !(typeof data === 'undefined'); }; } NaQRCodeComponent.prototype.ngOnInit = function () { var _this = this; QRCode.toDataURL(this._doc.getElementById('canvas'), this.data, { version: this.version, errorCorrectionLevel: this.level, margin: this.margin, width: this.size, color: { dark: this.colorDark, light: this.colorLight }, type: this.type, rendererOpts: { quality: 0.3 } }) .then(function (url) { _this.urlChange.emit(url); }) .catch(function (err) { console.error(err); }); }; NaQRCodeComponent.prototype.ngOnChanges = function (changes) { var data = changes['data']; if (data && this.isValidQrCodeText(data.currentValue)) ; }; __decorate([ Input(), __metadata("design:type", Number) ], NaQRCodeComponent.prototype, "version", void 0); __decorate([ Input(), __metadata("design:type", String) ], NaQRCodeComponent.prototype, "data", void 0); __decorate([ Input(), __metadata("design:type", String) ], NaQRCodeComponent.prototype, "url", void 0); __decorate([ Output(), __metadata("design:type", Object) ], NaQRCodeComponent.prototype, "urlChange", void 0); __decorate([ Input(), __metadata("design:type", String) ], NaQRCodeComponent.prototype, "level", void 0); __decorate([ Input(), __metadata("design:type", Object) ], NaQRCodeComponent.prototype, "margin", void 0); __decorate([ Input(), __metadata("design:type", String) ], NaQRCodeComponent.prototype, "type", void 0); __decorate([ Input(), __metadata("design:type", Object) ], NaQRCodeComponent.prototype, "size", void 0); __decorate([ Input(), __metadata("design:type", Object) ], NaQRCodeComponent.prototype, "colorDark", void 0); __decorate([ Input(), __metadata("design:type", Object) ], NaQRCodeComponent.prototype, "colorLight", void 0); NaQRCodeComponent = __decorate([ Component({ selector: 'na-qrcode', template: "<canvas id=\"canvas\"></canvas>\n", changeDetection: ChangeDetectionStrategy.OnPush, styles: [""] }), __param(1, Inject(DOCUMENT)), __metadata("design:paramtypes", [ElementRef, Object]) ], NaQRCodeComponent); return NaQRCodeComponent; }()); var NaQRCodeService = /** @class */ (function () { function NaQRCodeService() { } /** * Creates QR Code symbol and returns a qrcode object. */ // create(text: string | QRCodeSegment[], options: QRCodeOptions): QRCode.QRCode { NaQRCodeService.prototype.create = function (text, options) { return QRCode.create(text, options); }; /** * Draws qr code symbol to canvas. */ NaQRCodeService.prototype.toCanvas = function (text, options, canvas) { if (canvas) { return QRCode.toCanvas(canvas, text, options); } return QRCode.toCanvas(text, options); }; /** * Returns a Data URI containing a representation of the QR Code image. */ NaQRCodeService.prototype.toDataURL = function (text, options, canvasElement) { if (canvasElement) { return QRCode.toDataURL(canvasElement, text, options); } return QRCode.toDataURL(text, options); }; /** * Returns a string representation of the QR Code. * If choosen output format is svg it will returns a string containing xml code. */ NaQRCodeService.prototype.toString = function (text, options) { return QRCode.toString(text, options); }; /** * Saves QR Code to image file. * If options.type is not specified, the format will be guessed from file extension. * Recognized extensions are png, svg, txt. */ NaQRCodeService.prototype.toFile = function (path, text, options) { return QRCode.toFile(path, text, options); }; /** * Writes QR Code image to stream. Only works with png format for now. */ NaQRCodeService.prototype.toFileStream = function (streamW, text, options) { return QRCode.toFileStream(streamW, text, options); }; NaQRCodeService = __decorate([ Injectable(), __metadata("design:paramtypes", []) ], NaQRCodeService); return NaQRCodeService; }()); var NaQRCodeModule = /** @class */ (function () { function NaQRCodeModule() { } NaQRCodeModule = __decorate([ NgModule({ imports: [], exports: [ NaQRCodeComponent ], providers: [ NaQRCodeService ], declarations: [NaQRCodeComponent] }) ], NaQRCodeModule); return NaQRCodeModule; }()); var NaSettingsComponent = /** @class */ (function () { function NaSettingsComponent() { } NaSettingsComponent.prototype.ngOnInit = function () { }; NaSettingsComponent = __decorate([ Component({ selector: 'na-settings', template: "<p>\n settings works!\n</p>\n", styles: [""] }), __metadata("design:paramtypes", []) ], NaSettingsComponent); return NaSettingsComponent; }()); var NaSettingsModule = /** @class */ (function () { function NaSettingsModule() { } NaSettingsModule = __decorate([ NgModule({ imports: [ CommonModule ], declarations: [NaSettingsComponent] }) ], NaSettingsModule); return NaSettingsModule; }()); var NaSettingsService = /** @class */ (function () { function NaSettingsService() { } NaSettingsService.ngInjectableDef = ɵɵdefineInjectable({ factory: function NaSettingsService_Factory() { return new NaSettingsService(); }, token: NaSettingsService, providedIn: "root" }); NaSettingsService = __decorate([ Injectable({ providedIn: 'root' }), __metadata("design:paramtypes", []) ], NaSettingsService); return NaSettingsService; }()); var NA_STARTUP_CONFIG = new InjectionToken('NA_STARTUP_CONFIG'); /** * 用于应用启动时 * * 一般用来获取应用所需要的基础数据等 * * @export */ var NaStartupService = /** @class */ (function () { function NaStartupService(client) { this.client = client; this._startupConfig = {}; this.initialized = false; this.cache = new Map(); } /** * 启动加载 * * TODO ssr注入`HttpClient`在使用client时会有异常 * @param startupConfig 启动配置文件 */ /* load(startupConfig: IStartupConfigResource): Promise<any | void> { return new Promise((resolve, reject) => { const filePath = startupConfig.prefix + startupConfig.suffix; this.client.get(filePath).subscribe( (next: any) => { const rtnData = Object.assign({}, next); const profiles = next.profiles; if (profiles && profiles.active) { const file = startupConfig.prefix + '-' + profiles.active + startupConfig.suffix; const params = {}; // params[NaConstant.HTTP.RTN_ERROR_PROMPT] = false; this.client.get(file, {params: params}).subscribe( data => { NaUtils.mergeJSON(rtnData, data); console.log(data, rtnData); resolve(true); }, err => { console.log(err); reject(err); }, () => { this._startupConfig = rtnData; } ); } }, error => { console.error(`the profiles does not exist or error. please check the profiles active.`, error); reject(error); } ); }); } */ NaStartupService.prototype.load = function (startupConfig) { var _this = this; var filePath = startupConfig.prefix + startupConfig.suffix; return this.client.get(filePath).pipe(switchMap(function (value) { var rtnData = Object.assign({}, value); var profiles = rtnData.profiles; if (profiles && profiles.active) { var file = startupConfig.prefix + '-' + profiles.active + startupConfig.suffix; var params = {}; // params[NaConstant.HTTP.RTN_ERROR_PROMPT] = false; return _this.client.get(file, { params: params }).pipe(map(function (resp) { NaUtils.mergeJSON(rtnData, resp); return rtnData; })); } else { return of(rtnData); } }), tap(function (next) { _this._startupConfig = next; _this.initialized = true; }), catchError(function (err) { console.error("the profiles does not exist or error. please check the profiles active.", err); return throwError(err); })) .toPromise(); }; NaStartupService.prototype.get = function (key) { if (!this.initialized) { throw new Error('未加载完毕!'); } return this.getValue(this._startupConfig, key); }; NaStartupService.prototype.getValue = function (target, key) { if (this.cache.has(key)) { return this.cache.get(key); } var keys = key.split('.'); key = ''; do { key += keys.shift(); if (NaUtils.isDefined(target) && NaUtils.isDefined(target[key]) && (typeof target[key] === 'object' || !keys.length)) { target = target[key]; key = ''; } else if (!keys.length) { target = undefined; } else { key += '.'; } } while (keys.length); this.cache.set(key, target); return target; }; NaStartupService = __decorate([ Injectable(), __metadata("design:paramtypes", [HttpClient]) ], NaStartupService); return NaStartupService; }()); function throwIfAlreadyLoaded(parentModule, moduleName) { if (parentModule) { throw new Error(moduleName + " has already been loaded. Import " + moduleName + " modules in the AppModule only."); } } /** * 其他翻译资源 */ var NA_TRANSLATE_RESOURCES = new InjectionToken('NA_TRANSLATE_RESOURCES'); var MultiTranslateHttpLoader = /** @class */ (function () { function MultiTranslateHttpLoader(http, resources, injector) { this.http = http; this.resources = resources; this.injector = injector; } /** * 获取翻译资源 * * @param lang 语言 */ MultiTranslateHttpLoader.prototype.getTranslation = function (lang) { var _this = this; var obs = []; var translateResources = this.injector.get(NA_TRANSLATE_RESOURCES, []); translateResources.forEach(function (tr) { obs.push(tr.getTranslation(lang).pipe(catchError(function (err) { console.error('获取翻译资源失败!', err); return of({}); }))); }); var requests = this.resources.map(function (resource) { return _this.http.get(resource.prefix + lang + resource.suffix).pipe(catchError(function (err) { console.error('获取翻译资源失败!', err); return of({}); })); }); obs.push.apply(obs, __spread(requests)); // const merge = require('deepmerge').default; return forkJoin(obs).pipe(map(function (response) { var mergeResponse = []; response.forEach(function (item) { if (item) { mergeResponse.push(item); } }); // 如果response数组内存在null,这里会报错 return merge.all(mergeResponse); })); }; return MultiTranslateHttpLoader; }()); var NA_DEFAULT_RESOURCES = new InjectionToken('NA_DEFAULT_RESOURCES'); function createTranslateLoader(http, resources, injector) { return new MultiTranslateHttpLoader(http, resources, injector); } var NaTranslateModule = /** @class */ (function () { function NaTranslateModule() { } NaTranslateModule_1 = NaTranslateModule; NaTranslateModule.forRoot = function (resources) { if (resources === void 0) { resources = []; } return { ngModule: NaTranslateModule_1, providers: __spread([ { provide: NA_DEFAULT_RESOURCES, useValue: resources } ], TranslateModule.forRoot({ loader: { provide: TranslateLoader, useFactory: (createTranslateLoader), deps: [HttpClient, NA_DEFAULT_RESOURCES, Injector] }, // 隔离服务 isolate: true, useDefaultLang: true }).providers) }; }; var NaTranslateModule_1; NaTranslateModule = NaTranslateModule_1 = __decorate([ NgModule({ imports: [ TranslateModule ], exports: [ TranslateModule, ], providers: [ NaTranslateService ] }) ], NaTranslateModule); return NaTranslateModule; }()); var NaStartupModule = /** @class */ (function () { function NaStartupModule(parentModule) { throwIfAlreadyLoaded(parentModule, 'NaStartupModule'); } NaStartupModule_1 = NaStartupModule; NaStartupModule.forRoot = function (startupConfig) { return { ngModule: NaStartupModule_1, providers: [ { provide: NA_STARTUP_CONFIG, useValue: startupConfig }, NaStartupService, { provide: APP_INITIALIZER, useFactory: NaStartupServiceFactory, deps: [NaStartupService, NA_STARTUP_CONFIG], multi: true, } ] }; }; var NaStartupModule_1; NaStartupModule = NaStartupModule_1 = __decorate([ NgModule({ imports: [ NaTranslateModule ] }), __param(0, Optional()), __param(0, SkipSelf()), __metadata("design:paramtypes", [NaStartupModule]) ], NaStartupModule); return NaStartupModule; }()); function NaStartupServiceFactory(startupService, startupConfig) { var initializer = function () { return startupService.load(startupConfig); }; return initializer; } var NaMetaService = /** @class */ (function () { function NaMetaService(meta) { this.meta = meta; } NaMetaService.prototype.addTag = function (tag, forceCreation) { return this.meta.addTag(tag, forceCreation); }; NaMetaService.prototype.addTags = function (tags, forceCreation) { return this.meta.addTags(tags, forceCreation); }; NaMetaService.prototype.getTag = function (attrSelector) { return this.meta.getTag(attrSelector); }; NaMetaService.prototype.getTags = function (attrSelector) { return this.meta.getTags(attrSelector); }; NaMetaService.prototype.updateTag = function (tag, selector) { return this.meta.updateTag(tag, selector); }; NaMetaService.prototype.removeTag = function (attrSelector) { this.meta.removeTag(attrSelector); }; NaMetaService.prototype.removeTagElement = function (meta) { this.meta.removeTagElement(meta); }; NaMetaService.ngInjectableDef = ɵɵdefineInjectable({ factory: function NaMetaService_Factory() { return new NaMetaService(ɵɵinject(Meta)); }, token: NaMetaService, providedIn: "root" }); NaMetaService = __decorate([ Injectable({ providedIn: 'root' }), __metadata("design:paramtypes", [Meta]) ], NaMetaService); return NaMetaService; }()); // import { MenuService } from '../menu/menu.service'; // import { ALAIN_I18N_TOKEN, AlainI18NService } from '../i18n/i18n'; var NaTitleService = /** @class */ (function () { function NaTitleService(injector, title, // private menuSrv: MenuService, // @Optional() // @Inject(ALAIN_I18N_TOKEN) // private i18nSrv: AlainI18NService, doc) { this.injector = injector; this.title = title; this.doc = doc; this._prefix = ''; this._suffix = ''; this._separator = ' - '; this._reverse = false; this._default = 'Not Page Name'; // if (this.i18nSrv) { // this.i18n$ = this.i18nSrv.change.subscribe(() => this.setTitle()); // } } Object.defineProperty(NaTitleService.prototype, "separator", { /** 设置分隔符 */ set: function (value) { this._separator = value; }, enumerable: true, configurable: true }); Object.defineProperty(NaTitleService.prototype, "prefix", { /** 设置前缀 */ set: function (value) { this._prefix = value; }, enumerable: true, configurable: true }); Object.defineProperty(NaTitleService.prototype, "suffix", { /** 设置后缀 */ set: function (value) { this._suffix = value; }, enumerable: true, configurable: true }); Object.defineProperty(NaTitleService.prototype, "reverse", { /** 设置是否反转 */ set: function (value) { this._reverse = value; }, enumerable: true, configurable: true }); Object.defineProperty(NaTitleService.prototype, "default", { /** 设置默认标题名 */ set: function (value) { this._default = value; }, enumerable: true, configurable: true }); NaTitleService.prototype.getByElement = function () { var el = this.doc.querySelector('.content__title h1') || this.doc.querySelector('pro-header h1.title'); if (el) { return el.firstChild.textContent.trim(); } return ''; }; NaTitleService.prototype.getByRoute = function () { var next = this.injector.get(ActivatedRoute); while (next.firstChild) { next = next.firstChild; } var data = (next.snapshot && next.snapshot.data) || {}; // if (data.titleI18n && this.i18nSrv) { // data.title = this.i18nSrv.fanyi(data.titleI18n); // } return data.title; }; NaTitleService.prototype.getByMenu = function () { // const menus = this.menuSrv.getPathByUrl(this.injector.get(Router).url); // if (!menus || menus.length <= 0) { // return ''; // } // const item = menus[menus.length - 1]; // let title; // if (item.i18n && this.i18nSrv) { // title = this.i18nSrv.fanyi(item.i18n); // } // return title || item.text; return null; }; /** * 设置标题,若不指定具体名称,则按以顺序获取: * - 路由配置 `{ data: { title: 'page name' } }` * - 根据当前 URL 解析菜单数据 * - 页面 `content__title` 中获取 `h1` 内容 * - 默认标题名 */ NaTitleService.prototype.setTitle = function (title) { if (!title) { title = this.getByRoute() || this.getByMenu() || this.getByElement() || this._default; } if (title && !Array.isArray(title)) { title = [title]; } var newTitles = []; if (this._prefix) { newTitles.push(this._prefix); } newTitles.push.apply(newTitles, __spread(title)); if (this._suffix) { newTitles.push(this._suffix); } if (this._reverse) { newTitles = newTitles.reverse(); } this.title.setTitle(newTitles.join(this._separator)); }; NaTitleService.prototype.ngOnDestroy = function () { if (this.i18n$) { this.i18n$.unsubscribe(); } }; NaTitleService.ngInjectableDef = ɵɵdefineInjectable({ factory: function NaTitleService_Factory() { return new NaTitleService(ɵɵinject(INJECTOR), ɵɵinject(Title), ɵɵinject(DOCUMENT)); }, token: NaTitleService, providedIn: "root" }); NaTitleService = __decorate([ Injectable({ providedIn: 'root' }), __param(2, Inject(DOCUMENT)), __metadata("design:paramtypes", [Injector, Title, Object]) ], NaTitleService); return NaTitleService; }()); // #docregion // #docregion storage-token var BROWSER_STORAGE = new InjectionToken('Browser Storage', { providedIn: 'root', factory: function () { return localStorage; } }); // #enddocregion storage-token // #docregion inject-storage-token // @Injectable({ // providedIn: 'root' // }) var BrowserStorageService = /** @class */ (function () { function BrowserStorageService() { } /** * 设置缓存值 * * @param {string} key 主键 * @param {any} value 数据 * @param {number} [expires] 过期时间的秒数 * @memberof NaLocalStorageService */ BrowserStorageService.prototype.set = function (key, value, expires) { var obj = new Object(); obj['data'] = value; if (expires != null) { obj['expires'] = (new Date().getTime() + expires * 1000); } this.storage.setItem(key, JSON.stringify(obj)); }; /** * 获取缓存值 * * @param {string} key * @returns {any} * @memberof BrowserStorageService */ BrowserStorageService.prototype.get = function (key) { return this.getValidData(key); }; BrowserStorageService.prototype.remove = function (key) { this.storage.removeItem(key); }; BrowserStorageService.prototype.getValidData = function (key) { var value = this.storage.getItem(key); try { var _value = JSON.parse(value); if (_value) { if (_value['expires'] == null || _value['expires'] >= new Date().getTime()) { return _value['data']; } else { // 数据已过期 this.remove(key); } } return null; } catch (error) { return value; } }; return BrowserStorageService; }()); function _localStorage() { return localStorage; } var BROWSER_LOCALSTORAGE = new InjectionToken('Browser LocalStorage', { providedIn: 'root', factory: _localStorage }); /** * localStorage生命周期是永久 * 只能存储字符串类型的对象 * * @export */ var NaLocalStorageService = /** @class */ (function (_super) { __extends(NaLocalStorageService, _super); function NaLocalStorageService(storage) { var _this = _super.call(this) || this; _this.storage = storage; _this.storage = storage; return _this; } NaLocalStorageService = __decorate([ Injectable(), __param(0, Inject(BROWSER_LOCALSTORAGE)), __metadata("design:paramtypes", [Object]) ], NaLocalStorageService); return NaLocalStorageService; }(BrowserStorageService)); function _sessionStorage() { return sessionStorage; } // #docregion storage-token var BROWSER_SESSIONSTORAGE = new InjectionToken('Browser SessionStorage', { providedIn: 'root', factory: _sessionStorage }); // #enddocregion storage-token var NaSessionStorageService = /** @class */ (function (_super) { __extends(NaSessionStorageService, _super); function NaSessionStorageService(storage) { var _this = _super.call(this) || this; _this.storage = storage; _this.storage = storage; return _this; } NaSessionStorageService = __decorate([ Injectable(), __param(0, Inject(BROWSER_SESSIONSTORAGE)), __metadata("design:paramtypes", [Object]) ], NaSessionStorageService); return NaSessionStorageService; }(BrowserStorageService)); var NaSelectivePreloadStrategy = /** @class */ (function () { function NaSelectivePreloadStrategy() { this.preloadedModules = []; } NaSelectivePreloadStrategy.prototype.preload = function (route, load) { if (route.data && route.data['preload']) { // add the route path to our preloaded module array this.preloadedModules.push(route.path); // log the route path to the console // console.log('Preloaded: ' + route.path); return load(); } else { return of(null); } }; NaSelectivePreloadStrategy.ngInjectableDef = ɵɵdefineInjectable({ factory: function NaSelectivePreloadStrategy_Factory() { return new NaSelectivePreloadStrategy(); }, token: NaSelectivePreloadStrategy, providedIn: "root" }); NaSelectivePreloadStrategy = __decorate([ Injectable({ providedIn: 'root' }) ], NaSelectivePreloadStrategy); return NaSelectivePreloadStrategy; }()); /** * 把应用级、只用一次的组件收集到NaCoreModule中 * * @export */ var NaCoreModule = /** @class */ (function () { function NaCoreModule(parentModule) { throwIfAlreadyLoaded(parentModule, 'NaCoreModule'); } NaCoreModule = __decorate([ NgModule({ exports: [ // CommonModule, // BrowserModule, // BrowserAnimationsModule, NaMessageModule ], providers: [ NaLocalStorageService, NaSessionStorageService, NaSelectivePreloadStrategy, ] }), __param(0, Optional()), __param(0, SkipSelf()), __metadata("design:paramtypes", [NaCoreModule]) ], NaCoreModule); return NaCoreModule; }()); export { BROWSER_LOCALSTORAGE, BROWSER_SESSIONSTORAGE, DeleteEmptyFields, MultiTranslateHttpLoader, NA_DEFAULT_RESOURCES, NA_STARTUP_CONFIG, NA_TRANSLATE_RESOURCES, NaCoreModule, NaI18NDirective, NaI18NModule, NaI18NPipe, NaI18NService, NaLocalStorageService, NaMenuService, NaMessageModule, NaMessageService, NaMetaService, NaQRCodeComponent, NaQRCodeModule, NaQRCodeService, NaSelectivePreloadStrategy, NaSessionStorageService, NaSettingsComponent, NaSettingsModule, NaSettingsService, NaStartupModule, NaStartupService, NaStartupServiceFactory, NaTitleService, NaTranslateModule, NaTranslateService, ProgressBarComponent, ProgressBarModule, ProgressBarService, _localStorage, _sessionStorage, createTranslateLoader, preloaderFinished, throwIfAlreadyLoaded, BrowserStorageService as ɵa }; //# sourceMappingURL=ng-arthur-core.js.map