refactor: ♻️ aPI 路径基础 URL 提取

This commit is contained in:
hxr
2024-06-17 08:12:41 +08:00
parent e2cecf2905
commit 1449b078b1
6 changed files with 163 additions and 97 deletions

View File

@@ -1,12 +1,14 @@
import request from "@/utils/request";
import { CaptchaResult, LoginData, LoginResult } from "./model";
const AUTH_BASE_URL = "/api/v1/auth";
class AuthAPI {
/**
* 登录API
*
* @param data {LoginData}
* @returns
* @param data 登录数据
* @returns 登录结果
*/
static login(data: LoginData) {
const formData = new FormData();
@@ -15,7 +17,7 @@ class AuthAPI {
formData.append("captchaKey", data.captchaKey || "");
formData.append("captchaCode", data.captchaCode || "");
return request<any, LoginResult>({
url: "/api/v1/auth/login",
url: `${AUTH_BASE_URL}/login`,
method: "post",
data: formData,
headers: {
@@ -26,20 +28,24 @@ class AuthAPI {
/**
* 注销API
*
* @returns 请求结果
*/
static logout() {
return request({
url: "/api/v1/auth/logout",
url: `${AUTH_BASE_URL}/logout`,
method: "delete",
});
}
/**
* 获取验证码
*
* @returns 验证码结果
*/
static getCaptcha() {
return request<any, CaptchaResult>({
url: "/api/v1/auth/captcha",
url: `${AUTH_BASE_URL}/captcha`,
method: "get",
});
}