diff --git a/src/api/file/index.ts b/src/api/file/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..1e19bf904a700037f4794dbb85b748a4bff965a0 --- /dev/null +++ b/src/api/file/index.ts @@ -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 { + 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; + // 业务状态码 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; +} diff --git a/src/api/system/user.ts b/src/api/system/user.ts index fac9f94d24dc60ba7be381681b63ff55c7db8b45..1886536e5e15c8911c0776a806eb511defc470fb 100644 --- a/src/api/system/user.ts +++ b/src/api/system/user.ts @@ -27,6 +27,63 @@ const UserAPI = { data: queryParams, }); }, + + /** 获取个人中心用户信息 */ + getProfile() { + return request({ + 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; +} diff --git a/src/pages/mine/profile/index.vue b/src/pages/mine/profile/index.vue index 3c1397e73e93b80f38ac9b13c3d3ae7dab9f1326..a44bdf4ff2a0bb21625ea2553ce2b1a355316f87 100644 --- a/src/pages/mine/profile/index.vue +++ b/src/pages/mine/profile/index.vue @@ -1,5 +1,506 @@ + +