Skip to content

Commit

Permalink
✨ refactor(security-routing): 更新路由配置和标题策略服务,简化应用组件的加载逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
vnobo committed Jun 7, 2024
1 parent 958b296 commit 0c3d083
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 27 deletions.
1 change: 0 additions & 1 deletion ui-work/projects/web/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<div class="layui-layout">
{{ loadingShow() }}
<nz-spin [nzSpinning]="loadingShow()">
<router-outlet></router-outlet>
</nz-spin>
Expand Down
5 changes: 3 additions & 2 deletions ui-work/projects/web/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, OnInit, Signal} from '@angular/core';
import {Component, OnInit} from '@angular/core';
import {RouterOutlet} from '@angular/router';
import {AsyncPipe} from "@angular/common";
import {NzBackTopModule} from "ng-zorro-antd/back-top";
Expand All @@ -16,7 +16,7 @@ import {toSignal} from "@angular/core/rxjs-interop";
})
export class AppComponent implements OnInit {

loadingShow: Signal<boolean> = toSignal(this.loading.progress$.pipe(
loadingShow = toSignal(this.loading.progress$.pipe(
debounceTime(500),
distinctUntilChanged(),
tap((res) => console.log(`Loading show is: ${res}`))
Expand All @@ -26,6 +26,7 @@ export class AppComponent implements OnInit {
}

ngOnInit(): void {
this.loading.show();
}

}
12 changes: 3 additions & 9 deletions ui-work/projects/web/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
APP_ID,
ApplicationConfig,
importProvidersFrom,
provideExperimentalZonelessChangeDetection,
} from '@angular/core';
import {ApplicationConfig, importProvidersFrom, provideExperimentalZonelessChangeDetection,} from '@angular/core';
import {provideRouter, TitleStrategy} from '@angular/router';

import {routes} from './app.routes';
Expand All @@ -16,13 +11,12 @@ import {provideHttpClient, withFetch} from "@angular/common/http";

export const appConfig: ApplicationConfig = {
providers: [
{provide: APP_ID, useValue: 'PlateApp'},
{provide: TitleStrategy, useClass: PageTitleStrategy},
importProvidersFrom(BrowserAnimationsModule),
provideAnimationsAsync(),
provideNzConfig(ngZorroConfig),
provideRouter(routes),
provideHttpClient(withFetch()),
provideExperimentalZonelessChangeDetection()
provideExperimentalZonelessChangeDetection(),
{provide: TitleStrategy, useClass: PageTitleStrategy},
]
};
9 changes: 5 additions & 4 deletions ui-work/projects/web/src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {Routes} from '@angular/router';
import {PageNotFoundComponent} from "../pages/page-not-found/page-not-found.component";

export const routes: Routes = [{
path: 'home', loadChildren: () => import('../pages/pages.module').then(m => m.PagesModule)
},
export const routes: Routes = [
{
path: 'home', loadChildren: () => import('../pages/pages.module').then(m => m.PagesModule)
},
{
path: 'auth', loadChildren: () => import('../pages/security/security.module').then(m => m.SecurityModule)
},
{path: '', pathMatch: 'full', redirectTo: '/auth'},
{path: '', pathMatch: 'full', redirectTo: 'auth'},
{path: '**', component: PageNotFoundComponent}
];
4 changes: 2 additions & 2 deletions ui-work/projects/web/src/core/title-strategy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export class PageTitleStrategy extends TitleStrategy {
}

override updateTitle(routerState: RouterStateSnapshot) {
const title: string | undefined = this.buildTitle(routerState);
const title = this.buildTitle(routerState);
if (title !== undefined) {
this.title.setTitle(`盘子管理平台-${title}`);
this.title.setTitle(`盘子管理平台 | ${title}`);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import {NgModule} from '@angular/core';
import {RouterModule, Routes, TitleStrategy} from '@angular/router';
import {RouterModule, Routes} from '@angular/router';
import {LoginComponent} from "./login/login.component";
import {PageTitleStrategy} from "../../core/title-strategy.service";
import {LoginV1Component} from "./loginv1/login.component";

const routes: Routes = [
{path: 'login', component: LoginComponent, title: "系统登录"},
{path: 'login1', component: LoginV1Component, title: "系统登录"},
{path: '', component: LoginComponent}
{path: 'login', component: LoginComponent, title: '登录'},
{path: 'login1', component: LoginV1Component, title: '登录V1'},
{path: '', redirectTo: 'login', pathMatch: 'full'}
];

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
providers: [
{provide: TitleStrategy, useClass: PageTitleStrategy},
]
exports: [RouterModule]
})
export class SecurityRoutingModule {
}

0 comments on commit 0c3d083

Please sign in to comment.