37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import type { ApiResponse } from "../client/types";
|
|
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
|
import type { IAuthService } from "./IAuthService";
|
|
import { HttpAuthService } from "./HttpAuthService";
|
|
import { MockAuthService } from "./MockAuthService";
|
|
|
|
// 模拟开关
|
|
const USE_MOCK = false;
|
|
|
|
export class AuthService implements IAuthService {
|
|
private static _I: AuthService | null = null;
|
|
public static get I(): AuthService {
|
|
if (!AuthService._I) AuthService._I = new AuthService();
|
|
return AuthService._I;
|
|
}
|
|
|
|
private impl: IAuthService;
|
|
|
|
private constructor() {
|
|
this.impl = USE_MOCK ? new MockAuthService() : new HttpAuthService();
|
|
}
|
|
|
|
/** 运行期动态切换 */
|
|
public switch(useMock: boolean) {
|
|
this.impl = useMock ? new MockAuthService() : new HttpAuthService();
|
|
}
|
|
|
|
// 登录
|
|
public async login(req: proto.cs.ICSLoginReq): Promise<ApiResponse<proto.cs.ICSLoginRes>> {
|
|
return this.impl.login(req);
|
|
}
|
|
/** 上报事件 */
|
|
public async pointEvent(req: proto.cs.ICSPointEventReq): Promise<ApiResponse<proto.cs.ICSPointEventRes>> {
|
|
return this.impl.pointEvent(req);
|
|
}
|
|
}
|