auth.js 3.9 KB

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