Files
chazhi/src/api/login.ts
wangxiaowei 716160c113 调试接口
2025-12-23 17:55:14 +08:00

105 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { ICaptcha, IUpdateInfo, IUpdatePassword, IUserInfoVo, IUserLogin } from './types/login'
import { http } from '@/http/alova'
/**
* 登录表单
*/
export interface ILoginForm {
username: string
password: string
code: string
uuid: string
}
/**
* 手机密码登录
*/
export interface IMobileLoginForm {
account: string
terminal: number
scene: number
}
/**
* 获取验证码
* @returns ICaptcha 验证码
*/
export function getCode() {
return http.Get<ICaptcha>('/user/getCode')
}
/**
* 用户登录
* @param loginForm 登录表单
*/
export function login(loginForm: ILoginForm) {
return http.Post<IUserLogin>('/api/user/login', loginForm)
}
/**
* 用户登录
* @param loginForm 登录表单
*/
export function mobileLogin(loginForm: IMobileLoginForm) {
return http.Post<IUserLogin>('/api/login/account',
loginForm,
{
meta: { ignoreAuth: true } // 忽略认证
}
)
}
/**
* 获取用户信息
*/
export function getUserInfo() {
return http.Get<IUserInfoVo>('/api/user/info')
}
/**
* 退出登录
*/
export function logout() {
return http.Get<void>('/user/logout')
}
/**
* 修改用户信息
*/
export function updateInfo(data: IUpdateInfo) {
return http.Get('/user/updateInfo', data)
}
/**
* 获取微信登录凭证
* @returns Promise 包含微信登录凭证(code)
*/
export function 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 function wxLogin(data: { code: string }) {
return http.Post<IUserLogin>('/api/login/mnpLogin',
data,
{
meta: { ignoreAuth: true } // 忽略认证
}
)
}