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> { return this.impl.reqShopList(req); } }