协议数据模拟测试

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 { IAuthService } from "./IAuthService";
import { HttpAuthService } from "./HttpAuthService";
import { MockAuthService } from "./MockAuthService";
export class AuthService {
// 模拟开关
const USE_MOCK = false;
export class AuthService implements IAuthService {
private static _I: AuthService | null = null;
public static get I(): AuthService {
if (!AuthService._I) AuthService._I = new AuthService();
return AuthService._I;
}
private constructor(private api = ApiClient.I) {}
private impl: IAuthService;
private constructor() {
this.impl = USE_MOCK ? new MockAuthService() : new HttpAuthService();
}
/** 运行期动态切换 */
public switch(useMock: boolean) {
this.impl = useMock ? new MockAuthService() : new HttpAuthService();
}
// 登录
public async login(req: proto.cs.ICSLoginReq): Promise<ApiResponse<proto.cs.ICSLoginRes>> {
let epData: Endpoint<proto.cs.ICSLoginReq, proto.cs.ICSLoginRes> = {
path: "api/acc/login",
method: "POST",
codec: "json",
needsAuth: false
};
return this.api.call(epData, req);
return this.impl.login(req);
}
}