login.js 2.6 KB

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