2025-06-22 13:02:10 +08:00
|
|
|
|
import type { ICaptcha, IUpdateInfo, IUpdatePassword, IUserInfoVo, IUserLogin } from './types/login'
|
2025-05-27 23:19:09 +08:00
|
|
|
|
import { http } from '@/utils/http'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 登录表单
|
|
|
|
|
*/
|
|
|
|
|
export interface ILoginForm {
|
|
|
|
|
username: string
|
|
|
|
|
password: string
|
|
|
|
|
code: string
|
|
|
|
|
uuid: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取验证码
|
|
|
|
|
* @returns ICaptcha 验证码
|
|
|
|
|
*/
|
2025-06-21 16:56:24 +08:00
|
|
|
|
export function getCode() {
|
2025-05-27 23:19:09 +08:00
|
|
|
|
return http.get<ICaptcha>('/user/getCode')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户登录
|
|
|
|
|
* @param loginForm 登录表单
|
|
|
|
|
*/
|
2025-06-21 16:56:24 +08:00
|
|
|
|
export function login(loginForm: ILoginForm) {
|
2025-05-27 23:19:09 +08:00
|
|
|
|
return http.post<IUserLogin>('/user/login', loginForm)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取用户信息
|
|
|
|
|
*/
|
2025-06-21 16:56:24 +08:00
|
|
|
|
export function getUserInfo() {
|
2025-05-28 00:16:33 +08:00
|
|
|
|
return http.get<IUserInfoVo>('/user/info')
|
2025-05-27 23:19:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 退出登录
|
|
|
|
|
*/
|
2025-06-21 16:56:24 +08:00
|
|
|
|
export function logout() {
|
2025-05-27 23:19:09 +08:00
|
|
|
|
return http.get<void>('/user/logout')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改用户信息
|
|
|
|
|
*/
|
2025-06-21 16:56:24 +08:00
|
|
|
|
export function updateInfo(data: IUpdateInfo) {
|
2025-05-27 23:19:09 +08:00
|
|
|
|
return http.post('/user/updateInfo', data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改用户密码
|
|
|
|
|
*/
|
2025-06-21 16:56:24 +08:00
|
|
|
|
export function updateUserPassword(data: IUpdatePassword) {
|
2025-05-27 23:19:09 +08:00
|
|
|
|
return http.post('/user/updatePassword', data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取微信登录凭证
|
|
|
|
|
* @returns Promise 包含微信登录凭证(code)
|
|
|
|
|
*/
|
2025-06-21 16:56:24 +08:00
|
|
|
|
export function getWxCode() {
|
2025-05-27 23:19:09 +08:00
|
|
|
|
return new Promise<UniApp.LoginRes>((resolve, reject) => {
|
|
|
|
|
uni.login({
|
|
|
|
|
provider: 'weixin',
|
2025-06-21 16:56:24 +08:00
|
|
|
|
success: res => resolve(res),
|
|
|
|
|
fail: err => reject(new Error(err)),
|
2025-05-27 23:19:09 +08:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 微信登录参数
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 微信登录
|
|
|
|
|
* @param params 微信登录参数,包含code
|
|
|
|
|
* @returns Promise 包含登录结果
|
|
|
|
|
*/
|
2025-06-21 16:56:24 +08:00
|
|
|
|
export function wxLogin(data: { code: string }) {
|
2025-05-28 00:16:33 +08:00
|
|
|
|
return http.post<IUserLogin>('/user/wxLogin', data)
|
2025-05-27 23:19:09 +08:00
|
|
|
|
}
|