Skip to content

Commit 7a7e508

Browse files
committed
add version
1 parent 146fdd2 commit 7a7e508

2 files changed

Lines changed: 45 additions & 17 deletions

File tree

projects/sim-api/src/lib/simapi-config.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {ReplaySubject} from 'rxjs';
66
})
77
export class SimApiConfigService {
88
debug = true;
9+
fullVersion = true;
910
auth = {
1011
token_name: 'simapi-auth-token',
1112
check_url: '/auth/check',

projects/sim-api/src/lib/simapi.service.ts

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import {Injectable} from '@angular/core';
22
import {HttpClient, HttpHeaders} from '@angular/common/http';
3-
import {Observable} from 'rxjs';
3+
import {Observable, ReplaySubject, Subject} from 'rxjs';
44
import {SimApiConfigService} from './simapi-config.service';
55
import {SimApiVersion} from "../version";
6-
import {SimApiModule} from "./simapi.module";
76

87
type Callback = {
98
[key in number | string]: (data: any) => void | any;
@@ -15,37 +14,65 @@ declare const AppVersion: string;
1514
providedIn: 'root'
1615
})
1716
export 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

Comments
 (0)