index.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { defHttp } from '@/config/axios'
  2. import { getRefreshToken } from '@/utils/auth'
  3. import type { UserLoginVO, TokenType, UserInfoVO } from './types'
  4. export interface CodeImgResult {
  5. captchaOnOff: boolean
  6. img: string
  7. uuid: string
  8. }
  9. export interface SmsCodeVO {
  10. mobile: string
  11. scene: number
  12. }
  13. export interface SmsLoginVO {
  14. mobile: string
  15. code: string
  16. }
  17. // 获取验证码
  18. export const getCodeImgApi = () => {
  19. return defHttp.get<CodeImgResult>({ url: '/system/captcha/get-image' })
  20. }
  21. // 登录
  22. export const loginApi = (params: UserLoginVO) => {
  23. return defHttp.post<TokenType>({ url: '/system/auth/login', params })
  24. }
  25. // 刷新访问令牌
  26. export const refreshToken = () => {
  27. return defHttp.post({ url: '/system/auth/refresh-token?refreshToken=' + getRefreshToken() })
  28. }
  29. // 使用租户名,获得租户编号
  30. export const getTenantIdByNameApi = (name: string) => {
  31. return defHttp.get({ url: '/system/tenant/get-id-by-name?name=' + name })
  32. }
  33. // 登出
  34. export const loginOutApi = () => {
  35. return defHttp.delete({ url: '/system/auth/logout' })
  36. }
  37. // 获取用户权限信息
  38. export const getInfoApi = () => {
  39. return defHttp.get<UserInfoVO>({ url: '/system/auth/get-permission-info' })
  40. }
  41. // 路由
  42. export const getAsyncRoutesApi = () => {
  43. return defHttp.get({ url: '/system/auth/list-menus' })
  44. }
  45. //获取登录验证码
  46. export const sendSmsCodeApi = (params: SmsCodeVO) => {
  47. return defHttp.post({ url: '/system/auth/send-sms-code', params })
  48. }
  49. // 短信验证码登录
  50. export const smsLoginApi = (params: SmsLoginVO) => {
  51. return defHttp.post({ url: '/system/auth/sms-login', params })
  52. }