Initial project

This commit is contained in:
Timi
2025-07-08 16:33:11 +08:00
parent 1a5a16be74
commit f862530142
80 changed files with 8301 additions and 129 deletions
+85
View File
@@ -0,0 +1,85 @@
import {
Attachment,
axios,
CaptchaData,
CommonAPI,
LoginRequest,
LoginResponse,
RegisterRequest,
UserAttachType,
UserProfileView,
UserView
} from "~/index";
const BASE_URI = "/user";
async function register(captchaData: CaptchaData<RegisterRequest>): Promise<LoginResponse> {
return axios.post(`${BASE_URI}/register`, captchaData);
}
/**
* 登录
*
* @param captchaData 验证码登录对象
* @returns LoginResponse
*/
async function login(captchaData: CaptchaData<LoginRequest>): Promise<LoginResponse> {
return axios.post(`${BASE_URI}/login`, captchaData);
}
/**
* 验证是否已登录
*
* @returns true 为已登录
*/
async function login4Token(): Promise<LoginResponse> {
return axios.post(`${BASE_URI}/login/token`);
}
async function logout(): Promise<void> {
return axios.post(`${BASE_URI}/logout`);
}
/**
* 获取用户数据
*
* @param id 用户 ID
* @returns 用户数据
*/
async function view(id: number): Promise<UserView> {
return axios.post(`${BASE_URI}/view/${id}`);
}
function getAvatarURL(profile?: UserProfileView) {
if (profile && profile.attachmentList) {
return findAttachmentByType(profile.attachmentList, [UserAttachType.AVATAR, UserAttachType.DEFAULT_AVATAR]);
}
}
function getWrapperURL(profile?: UserProfileView) {
if (profile && profile.attachmentList) {
return findAttachmentByType(profile.attachmentList, [UserAttachType.WRAPPER, UserAttachType.DEFAULT_WRAPPER]);
}
}
function findAttachmentByType(attachmentList: Attachment[], types: UserAttachType[]) {
for (let i = 0; i < attachmentList.length; i++) {
const attachType = (<any>UserAttachType)[attachmentList[i].attachType!];
for (let type of types) {
if (attachType === type) {
return CommonAPI.getAttachmentReadAPI(attachmentList[i].mongoId);
}
}
}
}
export default {
register,
login,
login4Token,
logout,
view,
getAvatarURL,
getWrapperURL
};