协议数据模拟测试
This commit is contained in:
@@ -1,24 +1,32 @@
|
||||
import { ApiClient } from "../client/ApiClient";
|
||||
import type { Endpoint } from "../client/endpoints";
|
||||
import type { ApiResponse } from "../client/types";
|
||||
import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
import type { IThemeService } from "./IThemeService";
|
||||
import { HttpThemeService } from "./HttpThemeService";
|
||||
import { MockThemeService } from "./MockThemeService";
|
||||
|
||||
export class ThemeService {
|
||||
// 模拟开关
|
||||
const USE_MOCK = true;
|
||||
|
||||
export class ThemeService implements IThemeService {
|
||||
private static _I: ThemeService | null = null;
|
||||
public static get I(): ThemeService {
|
||||
if (!ThemeService._I) ThemeService._I = new ThemeService();
|
||||
return ThemeService._I;
|
||||
}
|
||||
private constructor(private api = ApiClient.I) {}
|
||||
|
||||
private impl: IThemeService;
|
||||
|
||||
private constructor() {
|
||||
this.impl = USE_MOCK ? new MockThemeService() : new HttpThemeService();
|
||||
}
|
||||
|
||||
/** 运行期切换 */
|
||||
public switch(useMock: boolean) {
|
||||
this.impl = useMock ? new MockThemeService() : new HttpThemeService();
|
||||
}
|
||||
|
||||
// 获取大厅分类列表
|
||||
public async reqHallTheme(req: proto.cs.ICSHallThemeReq): Promise<ApiResponse<proto.cs.ICSHallThemeRes>> {
|
||||
let epData: Endpoint<proto.cs.ICSHallThemeReq, proto.cs.ICSHallThemeRes> = {
|
||||
path: "api/logic/hallTheme",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true
|
||||
};
|
||||
return this.api.call(epData, req);
|
||||
return this.impl.reqHallTheme(req);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user