feat(用户中心): 新增用户中心相关功能模块
实现用户中心完整功能,包括: 1. 新增登录页面及登录逻辑 2. 添加个人资料、修改密码、关于我们等子页面 3. 实现头像上传功能 4. 添加js-cookie依赖处理token存储 5. 完善用户信息类型定义和API接口 6. 新增tabbar"我的"入口及相关路由配置 新增工具函数: 1. 添加auth.ts处理认证相关逻辑 2. 实现toast.ts统一消息提示 3. 添加uploadFile.ts处理文件上传 4. 新增isTableBar判断页面是否为tabbar页
This commit is contained in:
86
src/api/login.ts
Normal file
86
src/api/login.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { ICaptcha, IUpdateInfo, IUpdatePassword, IUserInfoVo, IUserLogin } from './login.typings'
|
||||
import { http } from '@/utils/http'
|
||||
|
||||
/**
|
||||
* 登录表单
|
||||
*/
|
||||
export interface ILoginForm {
|
||||
username: string
|
||||
password: string
|
||||
code: string
|
||||
uuid: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取验证码
|
||||
* @returns ICaptcha 验证码
|
||||
*/
|
||||
export const getCode = () => {
|
||||
return http.get<ICaptcha>('/user/getCode')
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
* @param loginForm 登录表单
|
||||
*/
|
||||
export const login = (loginForm: ILoginForm) => {
|
||||
return http.post<IUserLogin>('/user/login', loginForm)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
export const getUserInfo = (token: string) => {
|
||||
return http.get<IUserInfoVo>('/user/info', { token })
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
export const logout = () => {
|
||||
return http.get<void>('/user/logout')
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
*/
|
||||
export const updateInfo = (data: IUpdateInfo) => {
|
||||
return http.post('/user/updateInfo', data)
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户密码
|
||||
*/
|
||||
export const updateUserPassword = (data: IUpdatePassword) => {
|
||||
return http.post('/user/updatePassword', data)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信登录凭证
|
||||
* @returns Promise 包含微信登录凭证(code)
|
||||
*/
|
||||
export const getWxCode = () => {
|
||||
return new Promise<UniApp.LoginRes>((resolve, reject) => {
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: (res) => resolve(res),
|
||||
fail: (err) => reject(new Error(err)),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信登录参数
|
||||
*/
|
||||
export interface IWxLoginParams {
|
||||
code: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信登录
|
||||
* @param params 微信登录参数,包含code
|
||||
* @returns Promise 包含登录结果
|
||||
*/
|
||||
export const wxLogin = (params: IWxLoginParams) => {
|
||||
return http.post<IUserLogin>('/app/wx/login', {}, params)
|
||||
}
|
||||
63
src/api/login.typings.ts
Normal file
63
src/api/login.typings.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
export type IUserInfoVo = {
|
||||
id: number
|
||||
username: string
|
||||
name: string
|
||||
sex: string
|
||||
email: string
|
||||
phone: string
|
||||
avatar: string
|
||||
createTime: string
|
||||
roles: string[]
|
||||
permissions: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录返回的信息
|
||||
*/
|
||||
export type IUserLogin = {
|
||||
id: string
|
||||
username: string
|
||||
token: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取验证码
|
||||
*/
|
||||
export type ICaptcha = {
|
||||
captchaEnabled: boolean
|
||||
uuid: string
|
||||
image: string
|
||||
}
|
||||
/**
|
||||
* 上传成功的信息
|
||||
*/
|
||||
export type IUploadSuccessInfo = {
|
||||
fileId: number
|
||||
originalName: string
|
||||
fileName: string
|
||||
storagePath: string
|
||||
fileHash: string
|
||||
fileType: string
|
||||
fileBusinessType: string
|
||||
fileSize: number
|
||||
}
|
||||
/**
|
||||
* 更新用户信息
|
||||
*/
|
||||
export type IUpdateInfo = {
|
||||
id: number
|
||||
name: string
|
||||
sex: string
|
||||
}
|
||||
/**
|
||||
* 更新用户信息
|
||||
*/
|
||||
export type IUpdatePassword = {
|
||||
id: number
|
||||
oldPassword: string
|
||||
newPassword: string
|
||||
confirmPassword: string
|
||||
}
|
||||
Reference in New Issue
Block a user