Files
18xchat/assets/Scripts/chat18x/network/services/AuthService.ts
T

33 lines
968 B
TypeScript
Raw Normal View History

2025-08-15 00:36:38 +08:00
import type { ApiResponse } from "../client/types";
2025-08-29 16:39:41 +08:00
import proto from "db://assets/Scripts/proto/proto.pb.js";
import type { IAuthService } from "./IAuthService";
import { HttpAuthService } from "./HttpAuthService";
import { MockAuthService } from "./MockAuthService";
2025-08-15 00:36:38 +08:00
2025-08-29 16:39:41 +08:00
// 模拟开关
const USE_MOCK = false;
export class AuthService implements IAuthService {
2025-08-15 00:36:38 +08:00
private static _I: AuthService | null = null;
public static get I(): AuthService {
if (!AuthService._I) AuthService._I = new AuthService();
return AuthService._I;
}
2025-08-29 16:39:41 +08:00
private impl: IAuthService;
private constructor() {
this.impl = USE_MOCK ? new MockAuthService() : new HttpAuthService();
}
/** 运行期动态切换 */
public switch(useMock: boolean) {
this.impl = useMock ? new MockAuthService() : new HttpAuthService();
}
2025-08-15 00:36:38 +08:00
// 登录
2025-08-25 11:30:50 +08:00
public async login(req: proto.cs.ICSLoginReq): Promise<ApiResponse<proto.cs.ICSLoginRes>> {
2025-08-29 16:39:41 +08:00
return this.impl.login(req);
2025-08-15 00:36:38 +08:00
}
}