auth.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. verifyPhone: (username,mobile) => {
  51. return request({
  52. url: '/member/user/getUserByUserNameWithMobile?username='+username+'&mobile='+mobile,
  53. method: 'GET',
  54. });
  55. },
  56. // 发送手机验证码
  57. sendSmsCode: (mobile, scene) => {
  58. return request({
  59. url: '/member/auth/send-sms-code',
  60. method: 'POST',
  61. data: {
  62. mobile,
  63. scene,
  64. },
  65. custom: {
  66. loadingMsg: '发送中',
  67. showSuccess: true,
  68. successMsg: '发送成功',
  69. },
  70. });
  71. },
  72. // 校验手机验证码
  73. validatePhone: (mobile,code,scene) => {
  74. return request({
  75. url: '/member/auth/validate-sms-code',
  76. method: 'POST',
  77. data: {
  78. mobile,
  79. code,
  80. scene
  81. },
  82. });
  83. },
  84. // 微信公众号登录选择账号登录
  85. selectUsernameLogin: (data) => {
  86. return request({
  87. url: '/member/auth/select-username-login',
  88. method: 'POST',
  89. data,
  90. custom: {
  91. showSuccess: true,
  92. loadingMsg: '登录中',
  93. successMsg: '登录成功',
  94. },
  95. });
  96. },
  97. // 微信公众号注册
  98. officialRegister: (data) => {
  99. return request({
  100. url: '/member/auth/social-register',
  101. method: 'POST',
  102. data,
  103. custom: {
  104. showSuccess: true,
  105. loadingMsg: '注册中',
  106. successMsg: '注册成功',
  107. },
  108. });
  109. },
  110. // 微信公众号首次登录校验手机
  111. OfficialEnterLogin: (reqVO, registerReqVO) => {
  112. return request({
  113. url: '/member/auth/social-login-validate-sms-code',
  114. method: 'POST',
  115. data: {
  116. reqVO,
  117. registerReqVO
  118. },
  119. });
  120. },
  121. // 登出系统
  122. logout: () => {
  123. return request({
  124. url: '/member/auth/logout',
  125. method: 'POST',
  126. });
  127. },
  128. // 刷新令牌
  129. refreshToken: (refreshToken) => {
  130. return request({
  131. url: '/member/auth/refresh-token',
  132. method: 'POST',
  133. params: {
  134. refreshToken
  135. },
  136. custom: {
  137. loading: false, // 不用加载中
  138. showError: false, // 不展示错误提示
  139. },
  140. });
  141. },
  142. // 社交授权的跳转
  143. socialAuthRedirect: (type, redirectUri) => {
  144. return request({
  145. url: '/member/auth/social-auth-redirect',
  146. method: 'GET',
  147. params: {
  148. type,
  149. redirectUri,
  150. },
  151. custom: {
  152. showSuccess: true,
  153. loadingMsg: '登陆中',
  154. },
  155. });
  156. },
  157. // 社交快捷登录
  158. socialLogin: (type, code, state) => {
  159. return request({
  160. url: '/member/auth/social-login',
  161. method: 'POST',
  162. data: {
  163. type,
  164. code,
  165. state,
  166. },
  167. custom: {
  168. showSuccess: true,
  169. loadingMsg: '登陆中',
  170. },
  171. });
  172. },
  173. // 微信小程序的一键登录
  174. weixinMiniAppLogin: (phoneCode, loginCode, state) => {
  175. return request({
  176. url: '/member/auth/weixin-mini-app-login',
  177. method: 'POST',
  178. data: {
  179. phoneCode,
  180. loginCode,
  181. state
  182. },
  183. custom: {
  184. showSuccess: true,
  185. loadingMsg: '登陆中',
  186. successMsg: '登录成功',
  187. },
  188. });
  189. },
  190. // 创建微信 JS SDK 初始化所需的签名
  191. createWeixinMpJsapiSignature: (url) => {
  192. return request({
  193. url: '/member/auth/create-weixin-jsapi-signature',
  194. method: 'POST',
  195. params: {
  196. url
  197. },
  198. custom: {
  199. showError: false,
  200. showLoading: false,
  201. },
  202. })
  203. },
  204. // 获得消费者跳转到平台或者商户的链接
  205. getConsumerRedirectUrl: () => {
  206. return request({
  207. url: '/member/auth/redirectLogin',
  208. method: 'GET',
  209. });
  210. }
  211. };
  212. export default AuthUtil;