auth.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import request from '@/common/request';
  2. const AuthUtil = {
  3. // 使用手机 + 密码登录
  4. login: (data) => {
  5. return request({
  6. url: '/call/api/user/p/phonePswLogin',
  7. method: 'POST',
  8. data,
  9. custom: {
  10. showSuccess: true,
  11. loadingMsg: '登录中',
  12. successMsg: '登录成功',
  13. },
  14. });
  15. },
  16. // 手机密码注册
  17. phonePswRegister: (data) => {
  18. return request({
  19. url: '/call/api/user/p/phonePswRegister',
  20. method: 'POST',
  21. data,
  22. custom: {
  23. showSuccess: true,
  24. loadingMsg: '注册中',
  25. successMsg: '注册成功',
  26. },
  27. });
  28. },
  29. // 图形验证码
  30. getCaptcha: () => {
  31. return request({
  32. url: '/captcha',
  33. method: 'GET',
  34. custom: {
  35. showLoading: false, // 不用加载中
  36. showError: false, // 不展示错误提示
  37. },
  38. });
  39. },
  40. // 登出系统
  41. logout: () => {
  42. return request({
  43. url: '/call/api/user/logout',
  44. method: 'post',
  45. });
  46. },
  47. // 刷新令牌
  48. refreshToken: (token) => {
  49. return request({
  50. url: '/token/update',
  51. method: 'POST',
  52. params: {
  53. token,
  54. },
  55. custom: {
  56. showLoading: false, // 不用加载中
  57. showError: false, // 不展示错误提示
  58. },
  59. });
  60. },
  61. // 使用手机 + 验证码登录
  62. smsLogin: (data) => {
  63. return request({
  64. url: '/member/auth/sms-login',
  65. method: 'POST',
  66. data,
  67. custom: {
  68. showSuccess: true,
  69. loadingMsg: '登录中',
  70. successMsg: '登录成功',
  71. },
  72. });
  73. },
  74. // 发送手机验证码
  75. sendSmsCode: (mobile, scene) => {
  76. return request({
  77. url: '/member/auth/send-sms-code',
  78. method: 'POST',
  79. data: {
  80. mobile,
  81. scene,
  82. },
  83. custom: {
  84. loadingMsg: '发送中',
  85. showSuccess: true,
  86. successMsg: '发送成功',
  87. },
  88. });
  89. },
  90. // 社交授权的跳转
  91. socialAuthRedirect: (type, redirectUri) => {
  92. return request({
  93. url: '/member/auth/social-auth-redirect',
  94. method: 'GET',
  95. params: {
  96. type,
  97. redirectUri,
  98. },
  99. custom: {
  100. showSuccess: true,
  101. loadingMsg: '登陆中',
  102. },
  103. });
  104. },
  105. // 社交快捷登录
  106. socialLogin: (type, code, state) => {
  107. return request({
  108. url: '/member/auth/social-login',
  109. method: 'POST',
  110. data: {
  111. type,
  112. code,
  113. state,
  114. },
  115. custom: {
  116. showSuccess: true,
  117. loadingMsg: '登陆中',
  118. },
  119. });
  120. },
  121. // 微信小程序的一键登录
  122. weixinMiniAppLogin: (phoneCode, loginCode, state) => {
  123. return request({
  124. url: '/member/auth/weixin-mini-app-login',
  125. method: 'POST',
  126. data: {
  127. phoneCode,
  128. loginCode,
  129. state,
  130. },
  131. custom: {
  132. showSuccess: true,
  133. loadingMsg: '登陆中',
  134. successMsg: '登录成功',
  135. },
  136. });
  137. },
  138. // 创建微信 JS SDK 初始化所需的签名
  139. createWeixinMpJsapiSignature: (url) => {
  140. return request({
  141. url: '/member/auth/create-weixin-jsapi-signature',
  142. method: 'POST',
  143. params: {
  144. url,
  145. },
  146. custom: {
  147. showError: false,
  148. showLoading: false,
  149. },
  150. });
  151. },
  152. //
  153. };
  154. export default AuthUtil;