feat: 个人中心

This commit is contained in:
zhangyuanpeng
2024-11-14 13:16:58 +08:00
parent ec00cda60f
commit 251b60863a
3 changed files with 717 additions and 1 deletions

75
src/api/file/index.ts Normal file
View File

@@ -0,0 +1,75 @@
import { getToken } from "@/utils/cache";
import { ResultCodeEnum } from "@/enums/ResultCodeEnum";
// H5 使用 VITE_APP_BASE_API 作为代理路径,其他平台使用 VITE_APP_API_URL 作为请求路径
let baseApi = import.meta.env.VITE_APP_API_URL;
// #ifdef H5
baseApi = import.meta.env.VITE_APP_BASE_API;
// #endif
const FileAPI = {
/**
* 文件上传地址
*/
uploadUrl: baseApi + "/api/v1/files",
/**
* 上传文件
*
* @param filePath
*/
upload(filePath: string): Promise<FileInfo> {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: this.uploadUrl,
filePath: filePath,
name: "file",
header: {
Authorization: getToken() ? `Bearer ${getToken()}` : "",
},
formData: {},
success: (response) => {
const resData = JSON.parse(response.data) as ResponseData<FileInfo>;
// 业务状态码 00000 表示成功
if (resData.code === ResultCodeEnum.SUCCESS) {
resolve(resData.data);
} else {
// 其他业务处理失败
uni.showToast({
title: resData.msg || "文件上传失败",
icon: "none",
});
reject({
message: resData.msg || "业务处理失败",
code: resData.code,
});
}
},
fail: (error) => {
console.log("fail error", error);
uni.showToast({
title: "文件上传请求失败",
icon: "none",
duration: 2000,
});
reject({
message: "文件上传请求失败",
error,
});
},
});
});
},
};
export default FileAPI;
/**
* 文件API类型声明
*/
export interface FileInfo {
/** 文件名 */
name: string;
/** 文件路径 */
url: string;
}

View File

@@ -27,6 +27,63 @@ const UserAPI = {
data: queryParams,
});
},
/** 获取个人中心用户信息 */
getProfile() {
return request<UserProfileVO>({
url: `${USER_BASE_URL}/profile`,
method: "GET",
});
},
/** 修改个人中心用户信息 */
updateProfile(data: UserProfileForm) {
return request({
url: `${USER_BASE_URL}/profile`,
method: "PUT",
data: data,
});
},
/** 修改个人中心用户密码 */
changePassword(data: PasswordChangeForm) {
return request({
url: `${USER_BASE_URL}/password`,
method: "PUT",
data: data,
});
},
/**
* 发送手机/邮箱验证码
*
* @param contact 联系方式 手机号/邮箱
* @param contactType 联系方式类型 MOBILE:手机;EMAIL:邮箱
*/
sendVerificationCode(contact: string, contactType: string) {
return request({
url: `${USER_BASE_URL}/send-verification-code?contact=${contact}&contactType=${contactType}`,
method: "POST",
});
},
/** 绑定个人中心用户手机 */
bindMobile(data: MobileBindingForm) {
return request({
url: `${USER_BASE_URL}/mobile`,
method: "PUT",
data: data,
});
},
/** 绑定个人中心用户邮箱 */
bindEmail(data: EmailBindingForm) {
return request({
url: `${USER_BASE_URL}/email`,
method: "PUT",
data: data,
});
},
};
export default UserAPI;
@@ -93,3 +150,86 @@ export interface UserPageVO {
/** 用户名 */
username?: string;
}
/** 个人中心用户信息 */
export interface UserProfileVO {
/** 用户ID */
id?: number;
/** 用户名 */
username?: string;
/** 昵称 */
nickname?: string;
/** 头像URL */
avatar?: string;
/** 性别 */
gender?: number;
/** 手机号 */
mobile?: string;
/** 邮箱 */
email?: string;
/** 部门名称 */
deptName?: string;
/** 角色名称,多个使用英文逗号(,)分割 */
roleNames?: string;
/** 创建时间 */
createTime?: Date;
}
/** 个人中心用户信息表单 */
export interface UserProfileForm {
/** 用户ID */
id?: number;
/** 用户名 */
username?: string;
/** 昵称 */
nickname?: string;
/** 头像URL */
avatar?: string;
/** 性别 */
gender?: number;
/** 手机号 */
mobile?: string;
/** 邮箱 */
email?: string;
}
/** 修改密码表单 */
export interface PasswordChangeForm {
/** 原密码 */
oldPassword?: string;
/** 新密码 */
newPassword?: string;
/** 确认新密码 */
confirmPassword?: string;
}
/** 修改手机表单 */
export interface MobileBindingForm {
/** 手机号 */
mobile?: string;
/** 验证码 */
code?: string;
}
/** 修改邮箱表单 */
export interface EmailBindingForm {
/** 邮箱 */
email?: string;
/** 验证码 */
code?: string;
}