auth.js 2.9 KB

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