提交 474e6960 编写于 作者: H haoxr

refactor: 登录表单参数从URL移入到请求体的FormData

上级 db69d6e7
import request from '@/utils/request'; import request from "@/utils/request";
import { AxiosPromise } from 'axios'; import { AxiosPromise } from "axios";
import { CaptchaResult, LoginData, LoginResult } from './types'; import { CaptchaResult, LoginData, LoginResult } from "./types";
/** /**
* 登录API * 登录API
...@@ -9,10 +9,18 @@ import { CaptchaResult, LoginData, LoginResult } from './types'; ...@@ -9,10 +9,18 @@ import { CaptchaResult, LoginData, LoginResult } from './types';
* @returns * @returns
*/ */
export function loginApi(data: LoginData): AxiosPromise<LoginResult> { export function loginApi(data: LoginData): AxiosPromise<LoginResult> {
const formData = new FormData();
formData.append("username", data.username);
formData.append("password", data.password);
formData.append("verifyCodeKey", data.verifyCodeKey || "");
formData.append("verifyCode", data.verifyCode || "");
return request({ return request({
url: '/api/v1/auth/login', url: "/api/v1/auth/login",
method: 'post', method: "post",
params: data data: formData,
headers: {
"Content-Type": "multipart/form-data",
},
}); });
} }
...@@ -21,19 +29,17 @@ export function loginApi(data: LoginData): AxiosPromise<LoginResult> { ...@@ -21,19 +29,17 @@ export function loginApi(data: LoginData): AxiosPromise<LoginResult> {
*/ */
export function logoutApi() { export function logoutApi() {
return request({ return request({
url: '/api/v1/auth/logout', url: "/api/v1/auth/logout",
method: 'delete' method: "delete",
}); });
} }
/** /**
* 获取验证码 * 获取验证码
*/ */
export function getCaptchaApi(): AxiosPromise<CaptchaResult> { export function getCaptchaApi(): AxiosPromise<CaptchaResult> {
return request({ return request({
url: '/api/v1/auth/captcha', url: "/api/v1/auth/captcha",
method: 'get' method: "get",
}); });
} }
...@@ -5,11 +5,11 @@ export interface LoginData { ...@@ -5,11 +5,11 @@ export interface LoginData {
/** /**
* 用户名 * 用户名
*/ */
username?: string; username: string;
/** /**
* 密码 * 密码
*/ */
password?: string; password: string;
/** /**
* 验证码缓存key * 验证码缓存key
...@@ -57,4 +57,3 @@ export interface CaptchaResult { ...@@ -57,4 +57,3 @@ export interface CaptchaResult {
*/ */
verifyCodeBase64: string; verifyCodeBase64: string;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册