login.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import request from '@/utils/request'
  2. import { getRefreshToken } from '@/utils/auth'
  3. import service from '@/utils/request'
  4. // 登录方法
  5. export function login(username, password, captchaVerification, socialType, socialCode, socialState) {
  6. const data = {
  7. username,
  8. password,
  9. captchaVerification,
  10. // 社交相关
  11. socialType,
  12. socialCode,
  13. socialState
  14. }
  15. return request({
  16. url: '/system/auth/login',
  17. method: 'post',
  18. data: data
  19. })
  20. }
  21. // 获取用户详细信息
  22. export function getInfo() {
  23. return request({
  24. url: '/system/auth/get-permission-info',
  25. method: 'get'
  26. })
  27. }
  28. // 退出方法
  29. export function logout() {
  30. return request({
  31. url: '/system/auth/logout',
  32. method: 'post'
  33. })
  34. }
  35. // 社交授权的跳转
  36. export function socialAuthRedirect(type, redirectUri) {
  37. return request({
  38. url: '/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri,
  39. method: 'get'
  40. })
  41. }
  42. // 社交快捷登录,使用 code 授权码
  43. export function socialLogin(type, code, state) {
  44. return request({
  45. url: '/system/auth/social-login',
  46. method: 'post',
  47. data: {
  48. type,
  49. code,
  50. state
  51. }
  52. })
  53. }
  54. // 获取登录验证码
  55. export function sendSmsCode(mobile, scene) {
  56. return request({
  57. url: '/system/auth/send-sms-code',
  58. method: 'post',
  59. data: {
  60. mobile,
  61. scene
  62. }
  63. })
  64. }
  65. // 短信验证码登录
  66. export function smsLogin(mobile, code) {
  67. return request({
  68. url: '/system/auth/sms-login',
  69. method: 'post',
  70. data: {
  71. mobile,
  72. code
  73. }
  74. })
  75. }
  76. // 刷新访问令牌
  77. export function refreshToken() {
  78. return service({
  79. url: '/system/auth/refresh-token?refreshToken=' + getRefreshToken(),
  80. method: 'post'
  81. })
  82. }
  83. // ========== OAUTH 2.0 相关 ==========
  84. export function getAuthorize(clientId) {
  85. return request({
  86. url: '/system/oauth2/authorize?clientId=' + clientId,
  87. method: 'get'
  88. })
  89. }
  90. export function authorize(responseType, clientId, redirectUri, state,
  91. autoApprove, checkedScopes, uncheckedScopes) {
  92. // 构建 scopes
  93. const scopes = {}
  94. for (const scope of checkedScopes) {
  95. scopes[scope] = true
  96. }
  97. for (const scope of uncheckedScopes) {
  98. scopes[scope] = false
  99. }
  100. // 发起请求
  101. return service({
  102. url: '/system/oauth2/authorize',
  103. headers: {
  104. 'Content-type': 'application/x-www-form-urlencoded'
  105. },
  106. params: {
  107. response_type: responseType,
  108. client_id: clientId,
  109. redirect_uri: redirectUri,
  110. state: state,
  111. auto_approve: autoApprove,
  112. scope: JSON.stringify(scopes)
  113. },
  114. method: 'post'
  115. })
  116. }
  117. // 获取验证图片 以及token
  118. export function reqGet(data) {
  119. return request({
  120. url: 'system/captcha/get',
  121. method: 'post',
  122. data
  123. })
  124. }
  125. // 滑动或者点选验证
  126. export function reqCheck(data) {
  127. return request({
  128. url: '/system/captcha/check',
  129. method: 'post',
  130. data
  131. })
  132. }
  133. export class socialBindLogin {
  134. }