import { Injectable } from '@angular/core' import { HttpClient } from '@angular/common/http' import { Observable, of, throwError } from 'rxjs' import { tap, catchError } from 'rxjs/operators' import { WebSiteConfig } from '@cdk/public-api' @Injectable({ providedIn: 'root', }) export class ConfigService { private configUrl = 'assets/config.json' private appConfig: WebSiteConfig | null = null constructor(private http: HttpClient) {} loadConfig(): Observable { if (this.appConfig) { return of(this.appConfig) } console.log(123) return this.http.get(this.configUrl).pipe( tap((config) => { this.appConfig = config }), catchError((error) => { console.error('加载 config.json 失败:', error) return throwError(() => new Error('无法加载应用配置')) }), ) } getConfig(): WebSiteConfig | null { return this.appConfig } }