feat:添加管理员登录
This commit is contained in:
37
src/api/admin-auth.ts
Normal file
37
src/api/admin-auth.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import {
|
||||
hasLotteryAdminApiBaseUrl,
|
||||
publicAdminRequest,
|
||||
} from "@/lib/admin-http";
|
||||
import type {
|
||||
AdminAuthCaptchaResponse,
|
||||
AdminAuthLoginRequest,
|
||||
AdminAuthLoginResponse,
|
||||
} from "@/types/api/admin-auth";
|
||||
|
||||
import { API_V1_PREFIX } from "@/api/paths";
|
||||
|
||||
/** `GET /api/v1/admin/auth/captcha`(无需 Token) */
|
||||
export async function getAdminCaptcha(): Promise<AdminAuthCaptchaResponse | null> {
|
||||
if (!hasLotteryAdminApiBaseUrl()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return await publicAdminRequest<AdminAuthCaptchaResponse>({
|
||||
url: `${API_V1_PREFIX}/admin/auth/captcha`,
|
||||
method: "GET",
|
||||
});
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** `POST /api/v1/admin/auth/login`(无需 Token) */
|
||||
export async function postAdminLogin(
|
||||
body: AdminAuthLoginRequest,
|
||||
): Promise<AdminAuthLoginResponse> {
|
||||
return publicAdminRequest<AdminAuthLoginResponse>({
|
||||
url: `${API_V1_PREFIX}/admin/auth/login`,
|
||||
method: "POST",
|
||||
data: body,
|
||||
});
|
||||
}
|
||||
18
src/api/admin-ping.ts
Normal file
18
src/api/admin-ping.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { adminRequest, hasLotteryAdminApiBaseUrl } from "@/lib/admin-http";
|
||||
import type { AdminPingResponse } from "@/types/api/admin-ping";
|
||||
|
||||
import { API_V1_PREFIX } from "@/api/paths";
|
||||
|
||||
/** `GET /api/v1/admin/ping`(需 Bearer Token) */
|
||||
export async function getAdminPing(): Promise<AdminPingResponse | null> {
|
||||
if (!hasLotteryAdminApiBaseUrl()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return await adminRequest.get<AdminPingResponse>(
|
||||
`${API_V1_PREFIX}/admin/ping`,
|
||||
);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
9
src/api/index.ts
Normal file
9
src/api/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export { API_V1_PREFIX } from "@/api/paths";
|
||||
export { getAdminCaptcha, postAdminLogin } from "@/api/admin-auth";
|
||||
export { getAdminPing } from "@/api/admin-ping";
|
||||
export type {
|
||||
AdminAuthCaptchaResponse,
|
||||
AdminAuthLoginRequest,
|
||||
AdminAuthLoginResponse,
|
||||
AdminPingResponse,
|
||||
} from "@/types/api";
|
||||
2
src/api/paths.ts
Normal file
2
src/api/paths.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
/** Laravel `routes/api.php`:`api` 前缀 + `v1` 分组 */
|
||||
export const API_V1_PREFIX = "/api/v1";
|
||||
Reference in New Issue
Block a user