Files
18xchat/assets/Scripts/chat18x/network/services/ShopService.ts
T

38 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-08-27 17:33:51 +08:00
import type { ApiResponse } from "../client/types";
2025-08-29 16:39:41 +08:00
import proto from "db://assets/Scripts/proto/proto.pb.js";
import type { IShopService } from "./IShopService";
import { HttpShopService } from "./HttpShopService";
import { MockShopService } from "./MockShopService";
2025-08-27 17:33:51 +08:00
2025-08-29 16:39:41 +08:00
// 模拟开关
const USE_MOCK = true;
export class ShopService implements IShopService {
2025-08-27 17:33:51 +08:00
private static _I: ShopService | null = null;
public static get I(): ShopService {
if (!ShopService._I) ShopService._I = new ShopService();
return ShopService._I;
}
2025-08-29 16:39:41 +08:00
private impl: IShopService;
private constructor() {
this.impl = USE_MOCK ? new MockShopService() : new HttpShopService();
}
/** 运行期切换 */
public switch(useMock: boolean) {
this.impl = useMock ? new MockShopService() : new HttpShopService();
}
2025-08-27 17:33:51 +08:00
// 获取商品列表
2025-09-08 19:44:45 +08:00
public async reqShopList(req: proto.cs.ICSGetPurchaseReq): Promise<ApiResponse<proto.cs.ICSGetPurchaseRes>> {
2025-08-29 16:39:41 +08:00
return this.impl.reqShopList(req);
2025-08-27 17:33:51 +08:00
}
2025-09-08 19:44:45 +08:00
// 使用余额购买商品
public async reqBuyGood(req: proto.cs.ICSBuyGoodReq): Promise<ApiResponse<proto.cs.ICSBuyGoodRes>> {
return this.impl.reqBuyGood(req);
}
2025-08-27 17:33:51 +08:00
}