Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: configure app using provide #2442

Merged
merged 16 commits into from Nov 25, 2023
2 changes: 1 addition & 1 deletion .nvmrc
@@ -1 +1 @@
16.15.0
18.13.0
5 changes: 2 additions & 3 deletions .vscode/extensions.json
@@ -1,5 +1,4 @@
{
"recommendations": [
"cipchk.ng-alain-extension-pack"
]
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
"recommendations": ["cipchk.ng-alain-extension-pack"]
}
16 changes: 10 additions & 6 deletions .vscode/launch.json
@@ -1,16 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "ng serve",
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:4200",
"webRoot": "${workspaceRoot}",
"sourceMaps": true
"preLaunchTask": "npm: start",
"url": "http://localhost:4200/"
},
{
"name": "ng test",
"type": "chrome",
"request": "launch",
"preLaunchTask": "npm: test",
"url": "http://localhost:9876/debug.html"
}
]
}
7 changes: 2 additions & 5 deletions azure-pipelines.yml
Expand Up @@ -19,18 +19,15 @@ stages:
steps:
- task: NodeTool@0
inputs:
versionSpec: '18.10.0'
versionSource: 'fromFile'
versionFilePath: '.nvmrc'
displayName: 'Install Node.js'

- stage: build
dependsOn: env
jobs:
- job: Build
steps:
- task: NodeTool@0
inputs:
versionSpec: '18.10.0'
displayName: 'Install Node.js'
- script: yarn install
displayName: 'Install'
- script: |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -92,7 +92,7 @@
"eslint-plugin-deprecation": "~2.0.0",
"@angular/language-service": "^17.0.0",
"source-map-explorer": "^2.5.3",
"prettier": "^3.0.3",
"prettier": "^3.1.0",
"stylelint": "^15.11.0",
"stylelint-config-standard": "^34.0.0",
"stylelint-declaration-block-no-ignored-properties": "^2.7.0",
Expand Down
2 changes: 1 addition & 1 deletion proxy.conf.js
Expand Up @@ -9,7 +9,7 @@ module.exports = {
/**
* The following means that all requests are directed to the backend `https://localhost:9000/`
*/
// '/': {
// '/api': {
// target: 'https://localhost:9000/',
// secure: false, // Ignore invalid SSL certificates
// changeOrigin: true
Expand Down
6 changes: 4 additions & 2 deletions src/app/app.component.ts
@@ -1,13 +1,15 @@
import { Component, ElementRef, OnInit, Renderer2 } from '@angular/core';
import { NavigationEnd, NavigationError, RouteConfigLoadStart, Router } from '@angular/router';
import { NavigationEnd, NavigationError, RouteConfigLoadStart, Router, RouterOutlet } from '@angular/router';
import { TitleService, VERSION as VERSION_ALAIN, stepPreloader } from '@delon/theme';
import { environment } from '@env/environment';
import { NzModalService } from 'ng-zorro-antd/modal';
import { VERSION as VERSION_ZORRO } from 'ng-zorro-antd/version';

@Component({
selector: 'app-root',
template: ` <router-outlet />`
template: ` <router-outlet />`,
standalone: true,
imports: [RouterOutlet]
})
export class AppComponent implements OnInit {
private donePreloader = stepPreloader();
Expand Down
70 changes: 70 additions & 0 deletions src/app/app.config.ts
@@ -0,0 +1,70 @@
import { provideHttpClient, withInterceptors } from '@angular/common/http';
import { default as ngLang } from '@angular/common/locales/zh';
import { ApplicationConfig, EnvironmentProviders, Provider } from '@angular/core';
import { provideAnimations } from '@angular/platform-browser/animations';
import { provideRouter, withComponentInputBinding, withInMemoryScrolling, withHashLocation, RouterFeatures } from '@angular/router';
import { I18NService, defaultInterceptor, provideStartup } from '@core';
import { provideCellWidgets } from '@delon/abc/cell';
import { provideSTWidgets } from '@delon/abc/st';
import { authSimpleInterceptor, provideAuth } from '@delon/auth';
import { provideSFConfig } from '@delon/form';
import { AlainProvideLang, provideAlain, zh_CN as delonLang } from '@delon/theme';
import { AlainConfig } from '@delon/util/config';
import { environment } from '@env/environment';
import { CELL_WIDGETS, SF_WIDGETS, ST_WIDGETS } from '@shared';
import { zhCN as dateLang } from 'date-fns/locale';
import { NzConfig, provideNzConfig } from 'ng-zorro-antd/core/config';
import { zh_CN as zorroLang } from 'ng-zorro-antd/i18n';

import { provideBindAuthRefresh } from './core/net';
import { routes } from './routes/routes';
import { ICONS } from '../style-icons';
import { ICONS_AUTO } from '../style-icons-auto';

const defaultLang: AlainProvideLang = {
abbr: 'zh-CN',
ng: ngLang,
zorro: zorroLang,
date: dateLang,
delon: delonLang
};

const alainConfig: AlainConfig = {
st: { modal: { size: 'lg' } },
pageHeader: { homeI18n: 'home' },
lodop: {
license: `A59B099A586B3851E0F0D7FDBF37B603`,
licenseA: `C94CEE276DB2187AE6B65D56B3FC2848`
},
auth: { login_url: '/passport/login' }
};

const ngZorroConfig: NzConfig = {};

const routerFeatures: RouterFeatures[] = [withComponentInputBinding(), withInMemoryScrolling({ scrollPositionRestoration: 'top' })];
if (environment.useHash) routerFeatures.push(withHashLocation());

const providers: Array<Provider | EnvironmentProviders> = [
provideHttpClient(withInterceptors([...(environment.interceptorFns ?? []), authSimpleInterceptor, defaultInterceptor])),
provideAnimations(),
provideRouter(routes, ...routerFeatures),
provideAlain({ config: alainConfig, defaultLang, i18nClass: I18NService, icons: [...ICONS_AUTO, ...ICONS] }),
provideNzConfig(ngZorroConfig),
provideAuth(),
provideCellWidgets(...CELL_WIDGETS),
provideSTWidgets(...ST_WIDGETS),
provideSFConfig({
widgets: [...SF_WIDGETS]
}),
provideStartup(),
...(environment.providers || [])
];

// If you use `@delon/auth` to refresh the token, additional registration `provideBindAuthRefresh` is required
if (environment.api?.refreshTokenEnabled && environment.api.refreshTokenType === 'auth-refresh') {
providers.push(provideBindAuthRefresh());
}

export const appConfig: ApplicationConfig = {
providers: providers
};
107 changes: 0 additions & 107 deletions src/app/app.module.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/app/core/core.module.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/app/core/index.ts
@@ -1,5 +1,4 @@
export * from './i18n/i18n.service';
export * from './module-import-guard';
export * from './net/default.interceptor';
export * from './startup/startup.service';
export * from './start-page.guard';
6 changes: 0 additions & 6 deletions src/app/core/module-import-guard.ts

This file was deleted.