login.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import type { ICaptcha, IUpdateInfo, IUpdatePassword, IUserInfoVo, IUserLogin } from './login.typings'
  2. import { http } from '@/utils/http'
  3. /**
  4. * 登录表单
  5. */
  6. export interface ILoginForm {
  7. username: string
  8. password: string
  9. code: string
  10. uuid: string
  11. }
  12. /**
  13. * 获取验证码
  14. * @returns ICaptcha 验证码
  15. */
  16. export function getCode() {
  17. return http.get<ICaptcha>('/user/getCode')
  18. }
  19. /**
  20. * 用户登录
  21. * @param loginForm 登录表单
  22. */
  23. export function login(loginForm: ILoginForm) {
  24. return http.post<IUserLogin>('/user/login', loginForm)
  25. }
  26. /**
  27. * 获取用户信息
  28. */
  29. export function getUserInfo() {
  30. return http.get<IUserInfoVo>('/user/info')
  31. }
  32. /**
  33. * 退出登录
  34. */
  35. export function logout() {
  36. return http.get<void>('/user/logout')
  37. }
  38. /**
  39. * 修改用户信息
  40. */
  41. export function updateInfo(data: IUpdateInfo) {
  42. return http.post('/user/updateInfo', data)
  43. }
  44. /**
  45. * 修改用户密码
  46. */
  47. export function updateUserPassword(data: IUpdatePassword) {
  48. return http.post('/user/updatePassword', data)
  49. }
  50. /**
  51. * 获取微信登录凭证
  52. * @returns Promise 包含微信登录凭证(code)
  53. */
  54. export function getWxCode() {
  55. return new Promise<UniApp.LoginRes>((resolve, reject) => {
  56. uni.login({
  57. provider: 'weixin',
  58. success: res => resolve(res),
  59. fail: err => reject(new Error(err)),
  60. })
  61. })
  62. }
  63. /**
  64. * 微信登录参数
  65. */
  66. /**
  67. * 微信登录
  68. * @param params 微信登录参数,包含code
  69. * @returns Promise 包含登录结果
  70. */
  71. export function wxLogin(data: { code: string }) {
  72. return http.post<IUserLogin>('/user/wxLogin', data)
  73. }