auth.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. deleteUser: () => {
  133. return request({
  134. url: '/member/auth/deleteUser',
  135. method: 'POST',
  136. });
  137. },
  138. // 刷新令牌
  139. refreshToken: (refreshToken) => {
  140. return request({
  141. url: '/member/auth/refresh-token',
  142. method: 'POST',
  143. params: {
  144. refreshToken
  145. },
  146. custom: {
  147. loading: false, // 不用加载中
  148. showError: false, // 不展示错误提示
  149. },
  150. });
  151. },
  152. // 社交授权的跳转
  153. socialAuthRedirect: (type, redirectUri) => {
  154. return request({
  155. url: '/member/auth/social-auth-redirect',
  156. method: 'GET',
  157. params: {
  158. type,
  159. redirectUri,
  160. },
  161. custom: {
  162. showSuccess: true,
  163. loadingMsg: t('common.logging_in'),
  164. },
  165. });
  166. },
  167. // 社交快捷登录
  168. socialLogin: (type, code, state) => {
  169. return request({
  170. url: '/member/auth/social-login',
  171. method: 'POST',
  172. data: {
  173. type,
  174. code,
  175. state,
  176. },
  177. custom: {
  178. showSuccess: true,
  179. loadingMsg: t('common.logging_in'),
  180. },
  181. });
  182. },
  183. // 微信小程序的一键登录
  184. weixinMiniAppLogin: (phoneCode, loginCode, state) => {
  185. return request({
  186. url: '/member/auth/weixin-mini-app-login',
  187. method: 'POST',
  188. data: {
  189. phoneCode,
  190. loginCode,
  191. state
  192. },
  193. custom: {
  194. showSuccess: true,
  195. loadingMsg: t('common.logging_in'),
  196. successMsg: t('common.login_success'),
  197. },
  198. });
  199. },
  200. // 创建微信 JS SDK 初始化所需的签名
  201. createWeixinMpJsapiSignature: (url) => {
  202. return request({
  203. url: '/member/auth/create-weixin-jsapi-signature',
  204. method: 'POST',
  205. params: {
  206. url
  207. },
  208. custom: {
  209. showError: false,
  210. showLoading: false,
  211. },
  212. })
  213. },
  214. // 获得消费者跳转到平台或者商户的链接
  215. getConsumerRedirectUrl: () => {
  216. return request({
  217. url: '/member/auth/redirectLogin',
  218. method: 'GET',
  219. });
  220. }
  221. };
  222. export default AuthUtil;