index.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import request from '@/config/axios'
  2. import { getRefreshToken } from '@/utils/auth'
  3. import type { UserLoginVO } from './types'
  4. import { service } from '@/config/axios/service'
  5. export interface CodeImgResult {
  6. captchaOnOff: boolean
  7. img: string
  8. uuid: string
  9. }
  10. export interface SmsCodeVO {
  11. mobile: string
  12. scene: number
  13. }
  14. export interface SmsLoginVO {
  15. mobile: string
  16. code: string
  17. }
  18. // 登录
  19. export const loginApi = (data: UserLoginVO) => {
  20. return request.post({ url: '/system/auth/login', data })
  21. }
  22. // 刷新访问令牌
  23. export const refreshToken = () => {
  24. return request.post({ url: '/system/auth/refresh-token?refreshToken=' + getRefreshToken() })
  25. }
  26. // 使用租户名,获得租户编号
  27. export const getTenantIdByNameApi = (name: string) => {
  28. return request.get({ url: '/system/tenant/get-id-by-name?name=' + name })
  29. }
  30. // 登出
  31. export const loginOutApi = () => {
  32. return request.post({ url: '/system/auth/logout' })
  33. }
  34. // 获取用户权限信息
  35. export const getInfoApi = () => {
  36. return request.get({ url: '/system/auth/get-permission-info' })
  37. }
  38. // 路由
  39. export const getAsyncRoutesApi = () => {
  40. return request.get({ url: '/system/auth/list-menus' })
  41. }
  42. //获取登录验证码
  43. export const sendSmsCodeApi = (data: SmsCodeVO) => {
  44. return request.post({ url: '/system/auth/send-sms-code', data })
  45. }
  46. // 短信验证码登录
  47. export const smsLoginApi = (data: SmsLoginVO) => {
  48. return request.post({ url: '/system/auth/sms-login', data })
  49. }
  50. // 社交授权的跳转
  51. export const socialAuthRedirectApi = (type: number, redirectUri: string) => {
  52. return request.get({
  53. url: '/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri
  54. })
  55. }
  56. // 获取验证图片 以及token
  57. export const getCodeApi = (data) => {
  58. return request.postOriginal({ url: 'system/captcha/get', data })
  59. }
  60. // 滑动或者点选验证
  61. export const reqCheckApi = (data) => {
  62. return request.postOriginal({ url: 'system/captcha/check', data })
  63. }
  64. // ========== OAUTH 2.0 相关 ==========
  65. export const getAuthorize = (clientId) => {
  66. return request.get({ url: '/system/oauth2/authorize?clientId=' + clientId })
  67. }
  68. export function authorize(
  69. responseType: string,
  70. clientId: string,
  71. redirectUri: string,
  72. state: string,
  73. autoApprove: boolean,
  74. checkedScopes: any,
  75. uncheckedScopes: any
  76. ) {
  77. // 构建 scopes
  78. const scopes = {}
  79. for (const scope of checkedScopes) {
  80. scopes[scope] = true
  81. }
  82. for (const scope of uncheckedScopes) {
  83. scopes[scope] = false
  84. }
  85. // 发起请求
  86. return service({
  87. url: '/system/oauth2/authorize',
  88. headers: {
  89. 'Content-type': 'application/x-www-form-urlencoded'
  90. },
  91. params: {
  92. response_type: responseType,
  93. client_id: clientId,
  94. redirect_uri: redirectUri,
  95. state: state,
  96. auto_approve: autoApprove,
  97. scope: JSON.stringify(scopes)
  98. },
  99. method: 'post'
  100. })
  101. }