diff --git a/src/api/auth/auth.ts b/src/api/auth/auth.ts index 3b9d06c..e158615 100644 --- a/src/api/auth/auth.ts +++ b/src/api/auth/auth.ts @@ -1,5 +1,6 @@ import request from "@/plugins/axios"; import type { ApiResponse } from "../response"; +import { HttpMethod } from "@/constants"; /** * 认证服务 API 类型定义 @@ -21,6 +22,7 @@ export interface LoginResponse { accessTokenExpireTime: number | null; refreshTokenExpireTime: number | null; } + /** * 注册请求参数 */ @@ -29,10 +31,12 @@ export interface RegisterRequest { userPassword: string; checkPassword: string; } + /** * 注册响应数据 */ export type RegisterResponse = string; + // 刷新令牌响应数据 export interface RefreshTokenResponse { id: number | null; @@ -56,7 +60,11 @@ export interface RefreshTokenResponse { export const login = ( data: LoginRequest ): Promise> => { - return request.post("/v1/auth/login", data); + return request({ + url: "/v1/auth/login", + method: HttpMethod.POST, + data, + }); }; /** @@ -67,8 +75,13 @@ export const login = ( export const register = ( data: RegisterRequest ): Promise> => { - return request.post("/v1/user/register", data); + return request({ + url: "/v1/user/register", + method: HttpMethod.POST, + data, + }); }; + /** * 令牌刷新 * @param refreshToken 刷新令牌 @@ -77,7 +90,9 @@ export const register = ( export const refreshToken = ( refreshToken: string ): Promise> => { - return request.post("/v1/auth/refresh", null, { + return request({ + url: "/v1/auth/refresh", + method: HttpMethod.POST, params: { refreshToken, }, @@ -92,7 +107,11 @@ export const refreshToken = ( export const getAccessToken = ( data: LoginRequest ): Promise> => { - return request.post("/v1/auth/auth", data); + return request({ + url: "/v1/auth/auth", + method: HttpMethod.POST, + data, + }); }; /** @@ -100,5 +119,8 @@ export const getAccessToken = ( * @returns 验证结果 */ export const validateToken = (): Promise> => { - return request.post("/v1/auth/validate"); + return request({ + url: "/v1/auth/validate", + method: HttpMethod.POST, + }); }; diff --git a/src/api/auth/user.ts b/src/api/auth/user.ts index aee391a..1c6c40a 100644 --- a/src/api/auth/user.ts +++ b/src/api/auth/user.ts @@ -1,96 +1,190 @@ import request from "@/plugins/axios"; import type { ApiResponse } from "../response"; +import { HttpMethod } from "@/constants"; /** - * -*/ -/** - * 用户信息 - */ + * 用户信息 + */ export interface UserInfo { - /** - * id - */ - id: number; + /** + * id + */ + id: number; - /** - * 用户账号 - */ - userAccount: string; + /** + * 用户账号 + */ + userAccount: string; + /** + * 开放平台id + */ + unionId?: string; - /** - * 开放平台id - */ - unionId?: string; + /** + * 公众号openId + */ + mpOpenId?: string; - /** - * 公众号openId - */ - mpOpenId?: string; + /** + * 用户昵称 + */ + userName: string; - /** - * 用户昵称 - */ - userName: string; + /** + * 用户头像 是一个文件id,需要去文件服务查询文件详情,拿到文件url,和当前前端url + “/file/” 拼接起来,才能访问到文件 + */ + userAvatar?: string; - /** - * 用户头像 是一个文件id,需要去文件服务查询文件详情,拿到文件url,和当前前端url + “/file/” 拼接起来,才能访问到文件 - */ - userAvatar?: string; + /** + * 用户邮箱 + */ + userEmail?: string; - /** - * 用户邮箱 - */ - userEmail?: string; + /** + * 用户邮箱是否验证 + */ + userEmailVerified?: boolean; - /** - * 用户邮箱是否验证 - */ - userEmailVerified?: boolean; + /** + * 用户简介 + */ + userProfile?: string; - /** - * 用户简介 - */ - userProfile?: string; + /** + * 用户角色:user/admin/ban + */ + userRole: "user" | "admin" | "ban"; - /** - * 用户角色:user/admin/ban - */ - userRole: 'user' | 'admin' | 'ban'; + /** + * 创建时间 + */ + createTime: string; - /** - * 创建时间 - */ - createTime: string; - - /** - * 更新时间 - */ - updateTime: string; + /** + * 更新时间 + */ + updateTime: string; } + /** * 获取当前登录用户信息 * @returns 当前登录用户信息 */ export const getUserInfoByToken = (): Promise> => { - return request({ - url: "/v1/auth/getUserInfo", - method: "GET", - }) -} + return request({ + url: "/v1/auth/getUserInfo", + method: HttpMethod.GET, + }); +}; /** * 更新用户头像 * @param fileId 文件id - * @returns + * @returns */ -export const updateUserAvatar = (fileId: string): Promise> => { - return request({ - url: "/v1/user/avatar", - method: "PUT", - data: { - fileId: fileId, - } - }) -} \ No newline at end of file +export const updateUserAvatar = ( + fileId: string, +): Promise> => { + return request({ + url: "/v1/user/avatar", + method: HttpMethod.PUT, + data: { + fileId: fileId, + }, + }); +}; + +/** + * 发送邮箱验证码 + * @param email 邮箱 + * @returns + */ +export const sendEmailVerifyCode = ( + email: string, +): Promise> => { + return request({ + url: "/v1/user/email/send-code", + method: HttpMethod.GET, + params: { + email: email, + }, + }); +}; + +/** + * 绑定邮箱 + * @param email 邮箱 + * @param verifyCode 验证码 + * @returns + */ +export const bindEmail = ( + email: string, + verifyCode: string, +): Promise> => { + return request({ + url: "/v1/user/email/bind", + method: HttpMethod.POST, + data: { + email: email, + verifyCode: verifyCode, + }, + }); +}; + +/** + * 解绑邮箱 + * @param email 邮箱 + * @returns + */ +export const unbindEmail = (email: string): Promise> => { + return request({ + url: "/v1/user/email/unbind", + method: HttpMethod.POST, + data: { + email: email, + }, + }); +}; + +/** + * 修改用户密码 + * @param oldPassword 旧密码 + * @param newPassword 新密码 + * @returns + */ +export const updateUserPassword = ( + oldPassword: string, + newPassword: string, +): Promise> => { + return request({ + url: "/v1/user/password", + method: HttpMethod.PUT, + data: { + oldPassword: oldPassword, + newPassword: newPassword, + }, + }); +}; + +// 更新请求体对象 +export interface UpdateUserProfileRequest { + userName?: string; + userProfile?: string; +} +/** + * 更新用户个人信息 + * @param userProfile 更新用户个人信息请求体 + * @returns + */ +export const updateUserProfile = ( + userProfile: UpdateUserProfileRequest, +): Promise> => { + return request({ + url: "/v1/user/profile", + method: HttpMethod.PUT, + data: userProfile, + }); +}; + + diff --git a/src/api/file/file.ts b/src/api/file/file.ts index edce3d7..e2662b8 100644 --- a/src/api/file/file.ts +++ b/src/api/file/file.ts @@ -1,12 +1,14 @@ import request from "@/plugins/axios"; import type { ApiResponse } from "../response"; +import { HttpMethod } from "@/constants"; + /** * 分页查询文件列表 */ export const getFileList = async(current: number,size: number) =>{ return request({ url: "/v1/file/page", - method: "GET", + method: HttpMethod.GET, params: { current, size, @@ -17,23 +19,24 @@ export const getFileList = async(current: number,size: number) =>{ /** * 根据ID查询文件详情 * @param id 文件id - * @returns + * @returns */ export const getFileById = async (id: string): Promise> => { return request({ url: "/v1/file/" + id, - method: "GET", + method: HttpMethod.GET, }); } + /** * 检查文件是否已经上传,本地计算文件哈希 - * @param hash - * @returns + * @param hash + * @returns */ export const checkHash = async (hash: string) => { return request({ url: "/v1/file/check", - method: "GET", + method: HttpMethod.GET, params: { hash, }, @@ -42,8 +45,8 @@ export const checkHash = async (hash: string) => { /** * 上传文件 - * @param file - * @returns + * @param file + * @returns */ export const uploadFile = async (file: File, hash: string) : Promise> => { const formData = new FormData(); @@ -51,20 +54,20 @@ export const uploadFile = async (file: File, hash: string) : Promise { return request({ url: "/v1/file/" + id, - method: "DELETE", + method: HttpMethod.DELETE, }); } diff --git a/src/constants/http.ts b/src/constants/http.ts new file mode 100644 index 0000000..ac0537e --- /dev/null +++ b/src/constants/http.ts @@ -0,0 +1,15 @@ +/** + * HTTP 请求方法常量 + */ +export const HttpMethod = { + GET: 'GET', + POST: 'POST', + PUT: 'PUT', + DELETE: 'DELETE', + PATCH: 'PATCH', + HEAD: 'HEAD', + OPTIONS: 'OPTIONS', +} as const; + +// 导出类型以供使用 +export type HttpMethod = (typeof HttpMethod)[keyof typeof HttpMethod]; diff --git a/src/constants/index.ts b/src/constants/index.ts new file mode 100644 index 0000000..c202386 --- /dev/null +++ b/src/constants/index.ts @@ -0,0 +1 @@ +export * from './http'; diff --git a/src/views/user/UserProfileView.vue b/src/views/user/UserProfileView.vue index 2005f0c..2e15c38 100644 --- a/src/views/user/UserProfileView.vue +++ b/src/views/user/UserProfileView.vue @@ -1,129 +1,398 @@ -