协议数据模拟测试
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 { IShopService } from "./IShopService";
|
||||
import { HttpShopService } from "./HttpShopService";
|
||||
import { MockShopService } from "./MockShopService";
|
||||
|
||||
export class ShopService {
|
||||
// 模拟开关
|
||||
const USE_MOCK = true;
|
||||
|
||||
export class ShopService implements IShopService {
|
||||
private static _I: ShopService | null = null;
|
||||
public static get I(): ShopService {
|
||||
if (!ShopService._I) ShopService._I = new ShopService();
|
||||
return ShopService._I;
|
||||
}
|
||||
private constructor(private api = ApiClient.I) {}
|
||||
|
||||
private impl: IShopService;
|
||||
|
||||
private constructor() {
|
||||
this.impl = USE_MOCK ? new MockShopService() : new HttpShopService();
|
||||
}
|
||||
|
||||
/** 运行期切换 */
|
||||
public switch(useMock: boolean) {
|
||||
this.impl = useMock ? new MockShopService() : new HttpShopService();
|
||||
}
|
||||
|
||||
// 获取商品列表
|
||||
public async reqShopList(req: proto.cs.ICSGetShopReq): Promise<ApiResponse<proto.cs.ICSGetShopRes>> {
|
||||
let epData: Endpoint<proto.cs.ICSGetShopReq, proto.cs.ICSGetShopRes> = {
|
||||
path: "api/logic/shop",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true
|
||||
};
|
||||
return this.api.call(epData, req);
|
||||
return this.impl.reqShopList(req);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user