login.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import type { IAuthLoginRes, ICaptcha, IDoubleTokenRes, IUpdateInfo, IUpdatePassword, IUserInfoRes } from './types/login'
  2. // import { http } from '@/http/http'
  3. import { API_DOMAINS, http } from '@/http/alova'
  4. /**
  5. * 登录表单
  6. */
  7. export interface ILoginForm {
  8. username: string
  9. password: string
  10. }
  11. /**
  12. * 获取验证码
  13. * @returns ICaptcha 验证码
  14. */
  15. export function getCode() {
  16. return http.Get<ICaptcha>('/user/getCode')
  17. }
  18. /**
  19. * 用户登录
  20. * @param loginForm 登录表单
  21. */
  22. export function login(loginForm: ILoginForm) {
  23. return http.Post<IAuthLoginRes>('/auth/login', loginForm)
  24. }
  25. /**
  26. * 刷新token
  27. * @param refreshToken 刷新token
  28. */
  29. export function refreshToken(refreshToken: string) {
  30. return http.Post<IDoubleTokenRes>('/auth/refreshToken', { refreshToken })
  31. }
  32. /**
  33. * 获取用户信息
  34. */
  35. export function getUserInfo() {
  36. return http.Get<IUserInfoRes>('/couponCenter/APP/couponCenterUser/queryInformationAndStatus')
  37. }
  38. /**
  39. * 退出登录
  40. */
  41. export function logout() {
  42. return http.Post<void>('/couponCenter/APP/wx/logout')
  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. export function getUserProfile() {
  64. return new Promise<UniApp.GetUserProfileRes>((resolve, reject) => {
  65. uni.getUserProfile({
  66. provider: 'weixin',
  67. desc: '用于获取登录用户信息',
  68. success: res => resolve(res),
  69. fail: err => reject(new Error(err)),
  70. })
  71. })
  72. }
  73. /**
  74. * 微信登录
  75. * @param params 微信登录参数,包含code
  76. * @returns Promise 包含登录结果
  77. */
  78. export function wxLogin(code: string) {
  79. return http.Post<IAuthLoginRes>('/couponCenter/APP/wx/login', { code }, {
  80. meta: {
  81. ignoreAuth: true,
  82. },
  83. })
  84. }
  85. export function addInviteConversion(params) {
  86. return http.Get(`/couponCenter/APP/shareRecord/addInviteConversion?shareRecordId=${params.shareRecordId}`)
  87. }