index.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import request from '@/config/axios'
  2. import { getRefreshToken } from '@/utils/auth'
  3. import type { RegisterVO, UserLoginVO } from './types'
  4. export interface SmsCodeVO {
  5. mobile: string
  6. scene: number
  7. }
  8. export interface SmsLoginVO {
  9. mobile: string
  10. code: string
  11. }
  12. // 登录
  13. export const login = (data: UserLoginVO) => {
  14. return request.post({ url: '/system/auth/login', data })
  15. }
  16. // 注册
  17. export const register = (data: RegisterVO) => {
  18. return request.post({ url: '/system/auth/register', data })
  19. }
  20. // 刷新访问令牌
  21. export const refreshToken = () => {
  22. return request.post({ url: '/system/auth/refresh-token?refreshToken=' + getRefreshToken() })
  23. }
  24. // 使用租户名,获得租户编号
  25. export const getTenantIdByName = (name: string) => {
  26. return request.get({ url: '/system/tenant/get-id-by-name?name=' + name })
  27. }
  28. // 使用租户域名,获得租户信息
  29. export const getTenantByWebsite = (website: string) => {
  30. return request.get({ url: '/system/tenant/get-by-website?website=' + website })
  31. }
  32. // 登出
  33. export const loginOut = () => {
  34. return request.post({ url: '/system/auth/logout' })
  35. }
  36. // 获取用户权限信息
  37. export const getInfo = () => {
  38. return request.get({ url: '/system/auth/get-permission-info' })
  39. }
  40. //获取登录验证码
  41. export const sendSmsCode = (data: SmsCodeVO) => {
  42. return request.post({ url: '/system/auth/send-sms-code', data })
  43. }
  44. // 短信验证码登录
  45. export const smsLogin = (data: SmsLoginVO) => {
  46. return request.post({ url: '/system/auth/sms-login', data })
  47. }
  48. // 社交快捷登录,使用 code 授权码
  49. export function socialLogin(type: string, code: string, state: string) {
  50. return request.post({
  51. url: '/system/auth/social-login',
  52. data: {
  53. type,
  54. code,
  55. state
  56. }
  57. })
  58. }
  59. // 社交授权的跳转
  60. export const socialAuthRedirect = (type: number, redirectUri: string) => {
  61. return request.get({
  62. url: '/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri
  63. })
  64. }
  65. // 获取验证图片以及 token
  66. export const getCode = (data) => {
  67. return request.postOriginal({ url: 'system/captcha/get', data })
  68. }
  69. // 滑动或者点选验证
  70. export const reqCheck = (data) => {
  71. return request.postOriginal({ url: 'system/captcha/check', data })
  72. }