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

33 lines
968 B
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);
}
}