协议数据模拟测试

This commit is contained in:
chen wei bo
2025-08-29 16:40:14 +08:00
parent 5f51c19bc6
commit 1e7f2cf466
42 changed files with 702 additions and 90 deletions
@@ -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);
}
}