refactor: API类型声明优化调整

Former-commit-id: 0ae696c2e872fa90feba0c5df9a92391c02d3e0b
This commit is contained in:
haoxr
2022-11-08 22:53:42 +08:00
parent 94b93f02a1
commit b39ff7b1f6
38 changed files with 468 additions and 513 deletions

39
src/api/auth/index.ts Normal file
View File

@@ -0,0 +1,39 @@
import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { LoginForm, VerifyCode } from './types';
/**
*
* @param data {LoginForm}
* @returns
*/
export function loginApi(data: LoginForm): AxiosPromise<string> {
return request({
url: '/api/v1/auth/login',
method: 'post',
params: data,
headers: {
Authorization: 'Basic dnVlMy1lbGVtZW50LWFkbWluOnNlY3JldA==' // 客户端信息Base64明文vue3-element-admin:secret
}
});
}
/**
* 注销
*/
export function logoutApi() {
return request({
url: '/api/v1/auth/logout',
method: 'delete'
});
}
/**
* 获取图片验证码
*/
export function getCaptcha(): AxiosPromise<VerifyCode> {
return request({
url: '/captcha?t=' + new Date().getTime().toString(),
method: 'get'
});
}

32
src/api/auth/types.ts Normal file
View File

@@ -0,0 +1,32 @@
/**
* 登录表单类型声明
*/
export interface LoginForm {
username: string;
password: string;
grant_type: string;
/**
* 验证码Code
*/
//verifyCode: string;
/**
* 验证码Code服务端缓存key(UUID)
*/
// verifyCodeKey: string;
}
/**
* 登录响应类型声明
*/
export interface LoginResult {
access_token: string;
token_type: string;
}
/**
* 验证码类型声明
*/
export interface VerifyCode {
verifyCodeImg: string;
verifyCodeKey: string;
}