协议数据模拟测试

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,33 @@
import { ApiClient } from "../client/ApiClient";
import type { Endpoint } from "../client/endpoints";
// assets/Scripts/services/logic/ChatService.ts
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 { IChatService } from "./IChatService";
import { HttpChatService } from "./HttpChatService";
import { MockChatService } from "./MockChatService";
export class ChatService {
// 模拟开关
const USE_MOCK = true;
export class ChatService implements IChatService {
private static _I: ChatService | null = null;
public static get I(): ChatService {
if (!ChatService._I) ChatService._I = new ChatService();
return ChatService._I;
}
private constructor(private api = ApiClient.I) {}
// 购买聊天次数
private impl: IChatService;
private constructor() {
this.impl = USE_MOCK ? new MockChatService() : new HttpChatService();
}
/** 运行期动态切换 */
public switch(useMock: boolean) {
this.impl = useMock ? new MockChatService() : new HttpChatService();
}
// 对外 API 保持不变
public async reqBuyChat(req: proto.cs.ICSBuyChatReq): Promise<ApiResponse<proto.cs.ICSBuyChatRes>> {
let epData: Endpoint<proto.cs.ICSBuyChatReq, proto.cs.ICSBuyChatRes> = {
path: "api/logic/buyChat",
method: "POST",
codec: "json",
needsAuth: true
};
return this.api.call(epData, req);
return this.impl.reqBuyChat(req);
}
}