login.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * @Page: 文件描述
  3. * @Author: Fengyu
  4. * @Date: 2025-12-11 16:03:49
  5. * @LastEditors: Fengyu
  6. * @LastEditTime: 2025-12-12 14:00:41
  7. */
  8. /*
  9. * @Author: wyd
  10. * @Date: 2024-02
  11. * @LastEditors: wyd
  12. * @LastEditTime: 2024-07
  13. * @Description: 登录api
  14. */
  15. import { http } from '@/utils/http'
  16. import type { loginItem, captchaItem, captchaResult, smsItem, registerItem, forgetItem, loginResult, useInfoResult } from '@/types/login'
  17. /**
  18. * @description: 登录
  19. * @param {*} data isBind 1微信未绑定系统用户 0已绑定
  20. * @return {*}
  21. */
  22. export const loginApi = (data: loginItem, isBind: number) => {
  23. if (isBind === 1) {
  24. // 微信登录且需要绑定
  25. return http<loginResult>({
  26. method: 'POST',
  27. url: '/xcxBind',
  28. data
  29. })
  30. }
  31. if (data.type === 1) {
  32. // 短信登录
  33. return http<loginResult>({
  34. method: 'POST',
  35. url: '/smsLogin',
  36. data
  37. })
  38. }
  39. // 账号密码登录
  40. return http<loginResult>({
  41. method: 'POST',
  42. url: '/mpLogin',
  43. data
  44. })
  45. }
  46. /**
  47. * @description: 获取用户信息
  48. * @param {*} data
  49. * @return {*}
  50. */
  51. export const getUserInfoApi = () => {
  52. return http<useInfoResult>({
  53. method: 'GET',
  54. url: '/getInfo'
  55. })
  56. }
  57. /**
  58. * @description: 获取验证码图片
  59. * @param {*} data
  60. * @return {*}
  61. */
  62. export const getCaptchaImageApi = (data?: captchaItem) => {
  63. return http<captchaResult>({
  64. method: 'GET',
  65. url: '/captchaImage',
  66. data
  67. })
  68. }
  69. /**
  70. * @description: 获取短信验证码
  71. * @param {*} data
  72. * @return {*}
  73. */
  74. export const getSmsApi = (data?: smsItem) => {
  75. return http({
  76. method: 'GET',
  77. url: '/captchaSms',
  78. data
  79. })
  80. }
  81. /**
  82. * @description: 注册
  83. * @param {*} data
  84. * @return {*}
  85. */
  86. export const registerApi = (data?: registerItem) => {
  87. return http({
  88. method: 'POST',
  89. url: '/register',
  90. data
  91. })
  92. }
  93. /**
  94. * @description: 忘记密码
  95. * @param {*} data
  96. * @return {*}
  97. */
  98. export const forgetApi = (data?: forgetItem) => {
  99. return http({
  100. method: 'POST',
  101. url: '/password/reset',
  102. data
  103. })
  104. }
  105. /**
  106. * @description: 微信登录
  107. * @param {*} data
  108. * @return {*}
  109. */
  110. export const weixinApi = (data: { code: string }) => {
  111. return http<loginResult>({
  112. method: 'POST',
  113. url: '/xcxLogin',
  114. header: {
  115. 'content-type': 'application/x-www-form-urlencoded'
  116. },
  117. data
  118. })
  119. }
  120. /**
  121. * @description: 退出登录
  122. * @param {*}
  123. * @return {*}
  124. */
  125. export const quiteApi = () => {
  126. return http({
  127. method: 'POST',
  128. url: '/logout'
  129. })
  130. }
  131. /**
  132. * @description: 手机号登录
  133. * @param {*} data
  134. * @return {*}
  135. */
  136. export const phoneLoginApi = (data: { code: string }) => {
  137. return http<loginResult>({
  138. method: 'POST',
  139. url: '/xcxPhoneLogin',
  140. header: {
  141. 'content-type': 'application/x-www-form-urlencoded'
  142. },
  143. data
  144. })
  145. }