import { BrowserModule } from '@angular/platform-browser' ; import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ; import { NgModule , Injector , APP_INITIALIZER , LOCALE_ID } from '@angular/core' ; import { HttpClientModule } from '@angular/common/http' ; import { AbpModule , ABP_HTTP_PROVIDER , Abp } from '@abp' ; import { SharedModule } from '@shared/shared.module' ; import { DelonComponentModule } from '@shared/components' ; import { NgZorroAntdExtraModule } from 'ng-zorro-antd-extra' ; import { ServiceProxyModule } from '@shared/service-proxies/service-proxy.module' ; import { RootRoutingModule } from './root-routing.module' ; import { AppConsts } from '@shared/AppConsts' ; import { AppSessionService } from '@shared/session/app-session.service' ; import { API_BASE_URL } from '@shared/service-proxies/service-proxies' ; import { RootComponent } from './root.component' ; import { AppPreBootstrap } from './AppPreBootstrap' ; import { LocalizationService } from '@abp' ; import { NzLocaleService } from 'ng-zorro-antd' ; import { zhCN , enUS , trTR , zhTW , ruRU } from 'ng-zorro-antd' ; import { UEditorModule } from 'ngx-ueditor' ; import { registerLocaleData } from '@angular/common' ; import localeZhHans from '@angular/common/locales/zh-Hans' ; import localeZhHansExtra from '@angular/common/locales/extra/zh-Hans' ; function fixedLocale ( ) { localeZhHans [ 0 ] = 'zh-CN' ; registerLocaleData ( localeZhHans , localeZhHansExtra ) ; } function preloader ( ) { function remove ( ) { const body = document . querySelector ( 'body' ) ; const preloader = document . querySelector ( '.preloader' ) ; body . style . overflow = 'hidden' ; if ( ! preloader ) return ; preloader . addEventListener ( 'transitionend' , function ( ) { preloader . className = 'preloader-hidden' ; } ) ; preloader . className += ' preloader-hidden-add preloader-hidden-add-active' ; } setTimeout ( ( ) => { remove ( ) ; const body = document . querySelector ( 'body' ) ; body . style . overflow = '' ; } , 100 ) ; } ; function setNgZorroLocale ( injector ) { let nzLocalService = injector . get ( NzLocaleService ) ; let langName = Abp . localization . currentLanguage . name ; console . log ( 'current language: ' + langName ) ; let lang ; switch ( langName ) { case 'zh' : case 'zh-CN' : case 'zh-Hans' : lang = zhCN ; break ; case 'en' : case 'en-US' : lang = enUS ; break ; default : lang = zhCN ; break ; } console . log ( 'current language change to %o' , lang ) ; nzLocalService . setLocale ( lang ) ; } export function appInitializerFactory ( injector ) { return ( ) => { fixedLocale ( ) ; return new Promise < boolean > ( ( resolve , reject ) => { AppPreBootstrap . run ( injector , ( ) => { var appSessionService = injector . get ( AppSessionService ) ; appSessionService . init ( ) . then ( ( result ) => { setNgZorroLocale ( injector ) ; preloader ( ) ; resolve ( result ) ; } , ( err ) => { preloader ( ) ; reject ( err ) ; } ) ; } ) ; } ) ; } ; } export function getRemoteServiceBaseUrl ( ) { return AppConsts . remoteServiceBaseUrl ; } export function getCurrentLanguage ( ) { return Abp . localization . currentLanguage . name ; } @ NgModule ( { imports : [ BrowserModule , BrowserAnimationsModule , HttpClientModule , SharedModule . forRoot ( ) , DelonComponentModule . forRoot ( ) , AbpModule , ServiceProxyModule , RootRoutingModule , NgZorroAntdExtraModule . forRoot ( ) , UEditorModule . forRoot ( { path : '//apps.bdimg.com/libs/ueditor/1.4.3.1/' , options : { themePath : '//apps.bdimg.com/libs/ueditor/1.4.3.1/themes/' } } ) ] , declarations : [ RootComponent ] , providers : [ ABP_HTTP_PROVIDER , { provide : API_BASE_URL , useFactory : getRemoteServiceBaseUrl } , { provide : APP_INITIALIZER , useFactory : appInitializerFactory , deps : [ Injector ] , multi : true } , { provide : LOCALE_ID , useFactory : getCurrentLanguage } ] , bootstrap : [ RootComponent ] } ) export class RootModule { }