11import { Injectable } from '@angular/core' ;
22import { HttpClient , HttpHeaders } from '@angular/common/http' ;
3- import { Observable } from 'rxjs' ;
3+ import { Observable , ReplaySubject , Subject } from 'rxjs' ;
44import { SimApiConfigService } from './simapi-config.service' ;
55import { SimApiVersion } from "../version" ;
6- import { SimApiModule } from "./simapi.module" ;
76
87type Callback = {
98 [ key in number | string ] : ( data : any ) => void | any ;
@@ -15,37 +14,65 @@ declare const AppVersion: string;
1514 providedIn : 'root'
1615} )
1716export class SimApiService {
17+ versions = new ReplaySubject < {
18+ uiApp : string ,
19+ uiSimApi : string ,
20+ apiApp : string ,
21+ apiSimApi : string ,
22+ apiAppFull : string ,
23+ apiSimApiFull : string
24+ } > ( ) ;
25+ private endpoints : { [ name : string ] : string } = { } ;
26+ private debugMode : boolean = false ;
27+
28+ // 业务错误代码预处理(处理完后依旧会传给后面)
29+ private businessCallback : Callback = { } ;
30+
31+ // 网络请求处理
32+ private responseCallback : Callback = { } ;
33+
34+ public headers : any = { } ;
35+
1836 constructor ( private http : HttpClient , private config : SimApiConfigService ) {
1937 config . realTime$ . subscribe ( x => {
2038 this . endpoints = x . api . endpoints ;
2139 this . debugMode = x . debug ;
2240 this . businessCallback = x . api . businessCallback ;
2341 this . responseCallback = x . api . responseCallback ;
42+ if ( x . fullVersion ) {
43+ this . getVersions ( ) ;
44+ }
2445 } ) ;
46+ this . versions . next ( {
47+ uiApp : typeof AppVersion !== 'undefined' ? AppVersion : '0.0.0' ,
48+ uiSimApi : SimApiVersion ,
49+ apiApp : '0.0.0' ,
50+ apiSimApi : '0.0.0' ,
51+ apiAppFull : '0.0.0' ,
52+ apiSimApiFull : '0.0.0'
53+ } )
2554 }
2655
56+
2757 // 判断是否DEBUG模式
2858 get isDebug ( ) : boolean {
2959 return this . debugMode ;
3060 }
3161
32- get versions ( ) {
33- return {
34- App : typeof AppVersion !== 'undefined' ? AppVersion : '0.0.0' ,
35- SimApi : SimApiVersion
36- }
62+ getVersions ( ) {
63+ this . query ( "/versions" ) . subscribe ( resp => {
64+ this . versions . next ( {
65+ uiApp : typeof AppVersion !== 'undefined' ? AppVersion : '0.0.0' ,
66+ uiSimApi : SimApiVersion ,
67+ apiApp : resp . data . App . split ( "+" ) [ 0 ] ,
68+ apiSimApi : resp . data . SimApi . split ( "+" ) [ 0 ] ,
69+ apiAppFull : resp . data . App ,
70+ apiSimApiFull : resp . data . SimApi
71+ } )
72+ console . log ( `UI主应用版本: ${ typeof AppVersion !== 'undefined' ? AppVersion : '0.0.0' } \nUISimApi版本: ${ SimApiVersion } \nAPI主应用版本: ${ resp . data . App } \nAPISimApi版本: ${ resp . data . SimApi } ` ) ;
73+ } )
3774 }
3875
39- private endpoints : { [ name : string ] : string } = { } ;
40- private debugMode : boolean = false ;
41-
42- // 业务错误代码预处理(处理完后依旧会传给后面)
43- private businessCallback : Callback = { } ;
44-
45- // 网络请求处理
46- private responseCallback : Callback = { } ;
47-
48- public headers : any = { } ;
4976
5077 // 输出DEBUG信息(非DEBUG模式无输出)
5178 debug ( title : string , data : any ) : void {
0 commit comments