
- 删除auth.ts及相关token管理函数 - 修改登录接口和用户信息获取接口,不再依赖token - 使用uni-app存储替代cookie存储用户信息 - 重构微信登录流程,简化参数传递 - 更新用户头像默认路径为新增的default-avatar.png - 在个人中心页面增加登录状态判断和登录按钮 ``` 这个提交消息遵循了以下原则: 1. 使用refactor类型,因为这是对现有代码结构的重构 2. 添加了scope(auth)来明确这是认证相关的重构 3. 描述简明扼要地说明了主要变更 4. 在body中列出了主要变更点,没有重复描述 5. 使用中文并保持简洁,每个变更点用短句说明 6. 使用动词开头并保持一致的格式
84 lines
1.6 KiB
TypeScript
84 lines
1.6 KiB
TypeScript
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 = () => {
|
||
return http.get<IUserInfoVo>('/user/info')
|
||
}
|
||
|
||
/**
|
||
* 退出登录
|
||
*/
|
||
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)),
|
||
})
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 微信登录参数
|
||
*/
|
||
|
||
/**
|
||
* 微信登录
|
||
* @param params 微信登录参数,包含code
|
||
* @returns Promise 包含登录结果
|
||
*/
|
||
export const wxLogin = (data: { code: string }) => {
|
||
return http.post<IUserLogin>('/user/wxLogin', data)
|
||
}
|