1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
| import request from "@/utils/request";
|
| const AUTH_BASE_URL = "/api/v1/auth";
|
| const AuthAPI = {
| /** 登录接口*/
| login(data: LoginFormData) {
| const formData = new FormData();
| formData.append("username", data.username);
| formData.append("password", data.password);
| formData.append("captchaKey", data.captchaKey);
| formData.append("captchaCode", data.captchaCode);
| return request<any, LoginResult>({
| url: `${AUTH_BASE_URL}/login`,
| method: "post",
| data: formData,
| headers: {
| "Content-Type": "multipart/form-data",
| },
| });
| },
|
| /** 刷新 token 接口*/
| refreshToken(refreshToken: string) {
| return request<any, LoginResult>({
| url: `${AUTH_BASE_URL}/refresh-token`,
| method: "post",
| data: { refreshToken: refreshToken },
| headers: {
| Authorization: "no-auth",
| },
| });
| },
|
| /** 注销接口*/
| logout() {
| return request({
| url: `${AUTH_BASE_URL}/logout`,
| method: "delete",
| });
| },
|
| /** 获取验证码接口*/
| getCaptcha() {
| return request<any, CaptchaResult>({
| url: `${AUTH_BASE_URL}/captcha`,
| method: "get",
| });
| },
| };
|
| export default AuthAPI;
|
| /** 登录请求参数 */
| export interface LoginFormData {
| /** 用户名 */
| username: string;
| /** 密码 */
| password: string;
| /** 验证码缓存key */
| captchaKey: string;
| /** 验证码 */
| captchaCode: string;
| }
|
| /** 登录响应 */
| export interface LoginResult {
| /** 访问令牌 */
| accessToken: string;
| /** 令牌类型 */
| tokenType: string;
| /** 过期时间(秒) */
| expiresIn: number;
| }
|
| /** 验证码响应 */
| export interface CaptchaResult {
| /** 验证码缓存key */
| captchaKey: string;
| /** 验证码图片Base64字符串 */
| captchaBase64: string;
| }
|
|