协议修改

This commit is contained in:
chen wei bo
2025-08-25 11:31:15 +08:00
parent da18ae3155
commit 6a6510e34a
11 changed files with 6533 additions and 21936 deletions
@@ -15,7 +15,7 @@ export class ApiClient {
}
private constructor(private http = HttpManager.I) {}
private get baseUrl() { return AppConfig.I.getHttpBase() }
private get token() { return DataManager.I.getDataById<LoginData>(DataId.Login).getToken();}
private get token() { return DataManager.I.getDataById<LoginData>(DataId.Login).token;}
public async call<Req, Res>(ep: Endpoint<Req, Res>, req: Req): Promise<ApiResponse<Res>> {
const url = `${this.baseUrl}/${ep.path.replace(/^\/+/, "")}`;
@@ -67,12 +67,12 @@ export class ApiClient {
if (parsed && typeof parsed === "object" && typeof parsed.code === "number") {
return {
code: parsed.code,
msg: parsed.msg ?? (parsed.code === 1 ? "ok" : "error"),
data: parsed.Data as Res
msg: parsed.msg ?? (parsed.code === 0 ? "ok" : "error"),
data: parsed.data as Res
};
}
// 否则我们包一层
return { code: ApiCode.OK, msg: "ok", data: parsed.Data as Res };
return { code: ApiCode.OK, msg: "ok", data: parsed.data as Res };
} else if (ep.codec === "proto") {
const data = ProtoCodec.decode<Res>(ep.resType!, r.body);
// proto 场景一般没有 {code,msg} 包装,我们统一包一层
@@ -5,7 +5,7 @@ export interface ApiResponse<T = any> {
}
export const ApiCode = {
OK: 1,
OK: 0,
AUTH_EXPIRED: -401,
HTTP_ERROR: -400,
TIMEOUT: -408,