|
1 | | -import { Component, Inject, LOCALE_ID } from '@angular/core'; |
2 | | -import { MenuItem } from './models/MenuItem'; |
3 | | -import { Router, NavigationStart } from '@angular/router'; |
4 | | -import { LoadingService } from './services/LoadingService'; |
5 | | -import { OAuthService } from 'angular-oauth2-oidc'; |
6 | | -import * as authConfig from './shared/authConfig'; |
| 1 | +import { Component, Inject, LOCALE_ID } from "@angular/core"; |
| 2 | +import { MenuItem } from "./models/MenuItem"; |
| 3 | +import { Router, NavigationStart } from "@angular/router"; |
| 4 | +import { LoadingService } from "./services/LoadingService"; |
| 5 | +import { OAuthService } from "angular-oauth2-oidc"; |
| 6 | +import * as authConfig from "./shared/authConfig"; |
7 | 7 |
|
8 | 8 | @Component({ |
9 | | - selector: 'app-root', |
10 | | - templateUrl: './app.component.html', |
11 | | - styleUrls: ['./app.component.less'], |
12 | | - standalone: false |
| 9 | + selector: "app-root", |
| 10 | + templateUrl: "./app.component.html", |
| 11 | + styleUrls: ["./app.component.less"], |
| 12 | + standalone: false, |
13 | 13 | }) |
14 | 14 | export class AppComponent { |
15 | | - constructor(public loadingSvc: LoadingService, |
16 | | - private router:Router, |
17 | | - private oauth: OAuthService, |
18 | | - @Inject(LOCALE_ID) public currentLocale: string |
19 | | - ) { |
| 15 | + constructor( |
| 16 | + public loadingSvc: LoadingService, |
| 17 | + private router: Router, |
| 18 | + private oauth: OAuthService, |
| 19 | + @Inject(LOCALE_ID) public currentLocale: string |
| 20 | + ) { |
20 | 21 | this.oauth.configure(authConfig.authCodeFlowConfig); |
21 | 22 | this.oauth.loadDiscoveryDocument(); |
22 | 23 |
|
23 | 24 | this.loadingSvc.isLoading = true; |
24 | | - this.router.events.subscribe((e) => { if(e instanceof NavigationStart) {this.loadingSvc.isLoading = true;} }); |
| 25 | + this.router.events.subscribe((e) => { |
| 26 | + if (e instanceof NavigationStart) { |
| 27 | + this.loadingSvc.isLoading = true; |
| 28 | + } |
| 29 | + }); |
| 30 | + |
| 31 | + console.debug(`Current locale_id is ${currentLocale}`); |
25 | 32 | } |
26 | 33 |
|
27 | | - title = 'OpenReservation'; |
| 34 | + title = "OpenReservation"; |
28 | 35 | year = new Date().getFullYear(); |
29 | 36 |
|
30 | 37 | menus: Array<MenuItem> = [ |
31 | 38 | { Title: "首页", Link: "/" }, |
32 | | - { Title: "我的", Link: "/account/reservations"}, |
33 | | - { Title: "预约", Link: "/reservations/new"}, |
| 39 | + { Title: "我的", Link: "/account/reservations" }, |
| 40 | + { Title: "预约", Link: "/reservations/new" }, |
34 | 41 | { Title: "公告", Link: "/notice" }, |
35 | 42 | { Title: "关于", Link: "/about" }, |
36 | 43 | ]; |
37 | 44 |
|
38 | | - |
39 | | - localeChanged(event:any) { |
| 45 | + localeChanged(event: any) { |
40 | 46 | var newLocale = event.value; |
41 | | - var newLocation = location.href.replace(`/${this.currentLocale}/`, `/${newLocale}/`); |
| 47 | + if (newLocale === this.currentLocale){ |
| 48 | + return; |
| 49 | + } |
| 50 | + // update locale |
| 51 | + var newLocation = location.href.replace( |
| 52 | + `/${this.currentLocale}/`, |
| 53 | + `/${newLocale}/` |
| 54 | + ); |
42 | 55 | if (newLocation === location.href) return; |
43 | 56 |
|
44 | | - console.log(`newLocation: ${newLocation}`); |
| 57 | + console.debug(`newLocation: ${newLocation}`); |
45 | 58 | location.assign(newLocation); |
46 | 59 | } |
47 | 60 | } |
0 commit comments