Files
18xchat/assets/Scripts/chat18x/network/services/ShopService.ts
T
2025-08-29 16:40:14 +08:00

33 lines
989 B
TypeScript

import type { ApiResponse } from "../client/types";
import proto from "db://assets/Scripts/proto/proto.pb.js";
import type { IShopService } from "./IShopService";
import { HttpShopService } from "./HttpShopService";
import { MockShopService } from "./MockShopService";
// 模拟开关
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 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>> {
return this.impl.reqShopList(req);
}
}