auth.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import request from '@/sheep/request';
  2. import {
  3. t
  4. } from '@/locale';
  5. const AuthUtil = {
  6. // 使用手机 + 密码登录
  7. login: (data) => {
  8. return request({
  9. url: '/member/auth/login',
  10. method: 'POST',
  11. data,
  12. custom: {
  13. showSuccess: true,
  14. loadingMsg: t('common.logging_in'),
  15. successMsg: t('common.login_success'),
  16. },
  17. });
  18. },
  19. // 使用手机 + 验证码登录
  20. smsLogin: (data) => {
  21. return request({
  22. url: '/member/auth/sms-login',
  23. method: 'POST',
  24. data,
  25. custom: {
  26. showSuccess: true,
  27. loadingMsg: t('common.logging_in'),
  28. successMsg: t('common.login_success'),
  29. },
  30. });
  31. },
  32. // 账号注册
  33. register: (data) => {
  34. return request({
  35. url: '/member/auth/sms-register',
  36. method: 'POST',
  37. data,
  38. custom: {
  39. showSuccess: true,
  40. loadingMsg: t('common.registering'),
  41. successMsg: t('common.register_success'),
  42. },
  43. });
  44. },
  45. // 注册校验用户名是否重复
  46. verifyUsername: (username) => {
  47. return request({
  48. url: '/member/user/verifyUsername?username='+username,
  49. method: 'GET',
  50. });
  51. },
  52. // 根据用户名和手机号查询用户
  53. verifyPhone: (username,mobile) => {
  54. return request({
  55. url: '/member/user/getUserByUserNameWithMobile?username='+username+'&mobile='+mobile,
  56. method: 'GET',
  57. });
  58. },
  59. // 发送手机验证码
  60. sendSmsCode: (mobile, scene) => {
  61. return request({
  62. url: '/member/auth/send-sms-code',
  63. method: 'POST',
  64. data: {
  65. mobile,
  66. scene,
  67. },
  68. custom: {
  69. loadingMsg: t('common.sending'),
  70. showSuccess: true,
  71. successMsg: t('common.send_success'),
  72. },
  73. });
  74. },
  75. // 校验手机验证码
  76. validatePhone: (mobile,code,scene) => {
  77. return request({
  78. url: '/member/auth/validate-sms-code',
  79. method: 'POST',
  80. data: {
  81. mobile,
  82. code,
  83. scene
  84. },
  85. });
  86. },
  87. // 微信公众号登录选择账号登录
  88. selectUsernameLogin: (data) => {
  89. return request({
  90. url: '/member/auth/select-username-login',
  91. method: 'POST',
  92. data,
  93. custom: {
  94. showSuccess: true,
  95. loadingMsg: t('common.logging_in'),
  96. successMsg: t('common.login_success'),
  97. },
  98. });
  99. },
  100. // 微信公众号注册
  101. officialRegister: (data) => {
  102. return request({
  103. url: '/member/auth/social-register',
  104. method: 'POST',
  105. data,
  106. custom: {
  107. showSuccess: true,
  108. loadingMsg: t('common.registering'),
  109. successMsg: t('common.register_success'),
  110. },
  111. });
  112. },
  113. // 微信公众号首次登录校验手机
  114. OfficialEnterLogin: (reqVO, registerReqVO) => {
  115. return request({
  116. url: '/member/auth/social-login-validate-sms-code',
  117. method: 'POST',
  118. data: {
  119. reqVO,
  120. registerReqVO
  121. },
  122. });
  123. },
  124. // 登出系统
  125. logout: () => {
  126. return request({
  127. url: '/member/auth/logout',
  128. method: 'POST',
  129. });
  130. },
  131. // 刷新令牌
  132. refreshToken: (refreshToken) => {
  133. return request({
  134. url: '/member/auth/refresh-token',
  135. method: 'POST',
  136. params: {
  137. refreshToken
  138. },
  139. custom: {
  140. loading: false, // 不用加载中
  141. showError: false, // 不展示错误提示
  142. },
  143. });
  144. },
  145. // 社交授权的跳转
  146. socialAuthRedirect: (type, redirectUri) => {
  147. return request({
  148. url: '/member/auth/social-auth-redirect',
  149. method: 'GET',
  150. params: {
  151. type,
  152. redirectUri,
  153. },
  154. custom: {
  155. showSuccess: true,
  156. loadingMsg: t('common.logging_in'),
  157. },
  158. });
  159. },
  160. // 社交快捷登录
  161. socialLogin: (type, code, state) => {
  162. return request({
  163. url: '/member/auth/social-login',
  164. method: 'POST',
  165. data: {
  166. type,
  167. code,
  168. state,
  169. },
  170. custom: {
  171. showSuccess: true,
  172. loadingMsg: t('common.logging_in'),
  173. },
  174. });
  175. },
  176. // 微信小程序的一键登录
  177. weixinMiniAppLogin: (phoneCode, loginCode, state) => {
  178. return request({
  179. url: '/member/auth/weixin-mini-app-login',
  180. method: 'POST',
  181. data: {
  182. phoneCode,
  183. loginCode,
  184. state
  185. },
  186. custom: {
  187. showSuccess: true,
  188. loadingMsg: t('common.logging_in'),
  189. successMsg: t('common.login_success'),
  190. },
  191. });
  192. },
  193. // 创建微信 JS SDK 初始化所需的签名
  194. createWeixinMpJsapiSignature: (url) => {
  195. return request({
  196. url: '/member/auth/create-weixin-jsapi-signature',
  197. method: 'POST',
  198. params: {
  199. url
  200. },
  201. custom: {
  202. showError: false,
  203. showLoading: false,
  204. },
  205. })
  206. },
  207. // 获得消费者跳转到平台或者商户的链接
  208. getConsumerRedirectUrl: () => {
  209. return request({
  210. url: '/member/auth/redirectLogin',
  211. method: 'GET',
  212. });
  213. }
  214. };
  215. export default AuthUtil;