/* * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* eslint-disable import/order */ /* eslint-disable import/no-duplicates */ import { HttpClientModule } from '@angular/common/http'; import { default as ngLang } from '@angular/common/locales/zh'; import { APP_INITIALIZER, LOCALE_ID, NgModule, Type } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { SimpleInterceptor } from '@delon/auth'; import { DELON_LOCALE, zh_CN as delonLang, ALAIN_I18N_TOKEN } from '@delon/theme'; import { NZ_DATE_LOCALE, NZ_I18N, zh_CN as zorroLang } from 'ng-zorro-antd/i18n'; import { NzNotificationModule } from 'ng-zorro-antd/notification'; // #region default language // 参考:https://ng-alain.com/docs/i18n import { I18NService } from '@core'; import { zhCN as dateLang } from 'date-fns/locale'; const LANG = { abbr: 'zh', ng: ngLang, zorro: zorroLang, date: dateLang, delon: delonLang }; // register angular import { registerLocaleData } from '@angular/common'; registerLocaleData(LANG.ng, LANG.abbr); const LANG_PROVIDES = [ { provide: LOCALE_ID, useValue: LANG.abbr }, { provide: NZ_I18N, useValue: LANG.zorro }, { provide: NZ_DATE_LOCALE, useValue: LANG.date }, { provide: DELON_LOCALE, useValue: LANG.delon } ]; // #endregion // #region i18n services const I18NSERVICE_PROVIDES = [{ provide: ALAIN_I18N_TOKEN, useClass: I18NService, multi: false }]; // #endregion // #region global third module import { BidiModule } from '@angular/cdk/bidi'; const GLOBAL_THIRD_MODULES: Array> = [BidiModule]; // #endregion // #region JSON Schema form (using @delon/form) import { JsonSchemaModule } from '@shared'; const FORM_MODULES = [JsonSchemaModule]; // #endregion // #region Http Interceptors import { HTTP_INTERCEPTORS } from '@angular/common/http'; import { DefaultInterceptor } from '@core'; const INTERCEPTOR_PROVIDES = [ { provide: HTTP_INTERCEPTORS, useClass: SimpleInterceptor, multi: true }, { provide: HTTP_INTERCEPTORS, useClass: DefaultInterceptor, multi: true } ]; // #endregion // #region Startup Service import { StartupService } from '@core'; export function StartupServiceFactory(startupService: StartupService): () => Observable { return () => startupService.load(); } const APPINIT_PROVIDES = [ StartupService, { provide: APP_INITIALIZER, useFactory: StartupServiceFactory, deps: [StartupService], multi: true } ]; // #endregion import { AppComponent } from './app.component'; import { CoreModule } from './core/core.module'; import { GlobalConfigModule } from './global-config.module'; import { LayoutModule } from './layout/layout.module'; import { RoutesModule } from './routes/routes.module'; import { SharedModule } from './shared/shared.module'; import { STWidgetModule } from './shared/st-widget/st-widget.module'; import { Observable } from 'rxjs'; @NgModule({ declarations: [AppComponent], imports: [ BrowserModule, BrowserAnimationsModule, HttpClientModule, GlobalConfigModule.forRoot(), CoreModule, SharedModule, LayoutModule, RoutesModule, STWidgetModule, NzNotificationModule, ...GLOBAL_THIRD_MODULES, ...FORM_MODULES ], providers: [...LANG_PROVIDES, ...INTERCEPTOR_PROVIDES, ...I18NSERVICE_PROVIDES, ...APPINIT_PROVIDES], bootstrap: [AppComponent] }) export class AppModule { }