33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import type { ApiResponse } from "../client/types";
|
|
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
|
import type { ICommonService } from "./ICommonService";
|
|
import { HttpCommonService } from "./HttpCommonService";
|
|
import { MockCommonService } from "./MockCommonService";
|
|
|
|
// 模拟开关
|
|
const USE_MOCK = true;
|
|
|
|
export class CommonService implements ICommonService {
|
|
private static _I: CommonService | null = null;
|
|
public static get I(): CommonService {
|
|
if (!CommonService._I) CommonService._I = new CommonService();
|
|
return CommonService._I;
|
|
}
|
|
|
|
private impl: ICommonService;
|
|
|
|
private constructor() {
|
|
this.impl = USE_MOCK ? new MockCommonService() : new HttpCommonService();
|
|
}
|
|
|
|
/** 运行期切换 */
|
|
public switch(useMock: boolean) {
|
|
this.impl = useMock ? new MockCommonService() : new HttpCommonService();
|
|
}
|
|
|
|
// 获取配置
|
|
public async reqResConfig(req: proto.cs.ICSGetResConfigReq): Promise<ApiResponse<proto.cs.ICSGetResConfigRes>> {
|
|
return this.impl.reqResConfig(req);
|
|
}
|
|
}
|