app.module.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* eslint-disable import/order */
  17. /* eslint-disable import/no-duplicates */
  18. import { HttpClientModule } from '@angular/common/http';
  19. import { default as ngLang } from '@angular/common/locales/zh';
  20. import { APP_INITIALIZER, LOCALE_ID, NgModule, Type } from '@angular/core';
  21. import { BrowserModule } from '@angular/platform-browser';
  22. import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
  23. import { SimpleInterceptor } from '@delon/auth';
  24. import { DELON_LOCALE, zh_CN as delonLang, ALAIN_I18N_TOKEN } from '@delon/theme';
  25. import { NZ_DATE_LOCALE, NZ_I18N, zh_CN as zorroLang } from 'ng-zorro-antd/i18n';
  26. import { NzNotificationModule } from 'ng-zorro-antd/notification';
  27. // #region default language
  28. // 参考:https://ng-alain.com/docs/i18n
  29. import { I18NService } from '@core';
  30. import { zhCN as dateLang } from 'date-fns/locale';
  31. const LANG = {
  32. abbr: 'zh',
  33. ng: ngLang,
  34. zorro: zorroLang,
  35. date: dateLang,
  36. delon: delonLang
  37. };
  38. // register angular
  39. import { registerLocaleData } from '@angular/common';
  40. registerLocaleData(LANG.ng, LANG.abbr);
  41. const LANG_PROVIDES = [
  42. { provide: LOCALE_ID, useValue: LANG.abbr },
  43. { provide: NZ_I18N, useValue: LANG.zorro },
  44. { provide: NZ_DATE_LOCALE, useValue: LANG.date },
  45. { provide: DELON_LOCALE, useValue: LANG.delon }
  46. ];
  47. // #endregion
  48. // #region i18n services
  49. const I18NSERVICE_PROVIDES = [{ provide: ALAIN_I18N_TOKEN, useClass: I18NService, multi: false }];
  50. // #endregion
  51. // #region global third module
  52. import { BidiModule } from '@angular/cdk/bidi';
  53. const GLOBAL_THIRD_MODULES: Array<Type<any>> = [BidiModule];
  54. // #endregion
  55. // #region JSON Schema form (using @delon/form)
  56. import { JsonSchemaModule } from '@shared';
  57. const FORM_MODULES = [JsonSchemaModule];
  58. // #endregion
  59. // #region Http Interceptors
  60. import { HTTP_INTERCEPTORS } from '@angular/common/http';
  61. import { DefaultInterceptor } from '@core';
  62. const INTERCEPTOR_PROVIDES = [
  63. { provide: HTTP_INTERCEPTORS, useClass: SimpleInterceptor, multi: true },
  64. { provide: HTTP_INTERCEPTORS, useClass: DefaultInterceptor, multi: true }
  65. ];
  66. // #endregion
  67. // #region Startup Service
  68. import { StartupService } from '@core';
  69. export function StartupServiceFactory(startupService: StartupService): () => Observable<void> {
  70. return () => startupService.load();
  71. }
  72. const APPINIT_PROVIDES = [
  73. StartupService,
  74. {
  75. provide: APP_INITIALIZER,
  76. useFactory: StartupServiceFactory,
  77. deps: [StartupService],
  78. multi: true
  79. }
  80. ];
  81. // #endregion
  82. import { AppComponent } from './app.component';
  83. import { CoreModule } from './core/core.module';
  84. import { GlobalConfigModule } from './global-config.module';
  85. import { LayoutModule } from './layout/layout.module';
  86. import { RoutesModule } from './routes/routes.module';
  87. import { SharedModule } from './shared/shared.module';
  88. import { STWidgetModule } from './shared/st-widget/st-widget.module';
  89. import { Observable } from 'rxjs';
  90. @NgModule({
  91. declarations: [AppComponent],
  92. imports: [
  93. BrowserModule,
  94. BrowserAnimationsModule,
  95. HttpClientModule,
  96. GlobalConfigModule.forRoot(),
  97. CoreModule,
  98. SharedModule,
  99. LayoutModule,
  100. RoutesModule,
  101. STWidgetModule,
  102. NzNotificationModule,
  103. ...GLOBAL_THIRD_MODULES,
  104. ...FORM_MODULES
  105. ],
  106. providers: [...LANG_PROVIDES, ...INTERCEPTOR_PROVIDES, ...I18NSERVICE_PROVIDES, ...APPINIT_PROVIDES],
  107. bootstrap: [AppComponent]
  108. })
  109. export class AppModule { }