auth.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import http from '@/api'
  2. import type { BaseEntity } from '@/typings/api'
  3. export interface UserInfo extends BaseEntity {
  4. name: string
  5. sex: number
  6. username: string
  7. avatar: string
  8. email: string
  9. phone: string
  10. }
  11. export interface LoginForm {
  12. username: string
  13. password: string
  14. code: string
  15. uuid: string
  16. }
  17. export interface AuthResponse {
  18. accessToken: string
  19. refreshToken: string
  20. expiresIn: number
  21. tokenType: string
  22. scope: string[]
  23. }
  24. export interface VerificationCode {
  25. img: string
  26. uuid: string
  27. }
  28. /**
  29. * 登录
  30. * @param loginForm
  31. */
  32. export const login = (loginForm: LoginForm) => {
  33. return http.post<AuthResponse>('/auth/login', loginForm)
  34. }
  35. /**
  36. * 退出
  37. */
  38. export const logout = () => {
  39. return http.post<null>('/auth/logout')
  40. }
  41. /**
  42. * 刷新token
  43. */
  44. export const refreshToken = () => {
  45. return http.post<AuthResponse>('/auth/refresh')
  46. }
  47. /**
  48. * 获取验证码
  49. */
  50. export const getCodeImg = () => {
  51. return http.get<VerificationCode>('/auth/code')
  52. }
  53. /**
  54. * 获取用户信息
  55. */
  56. export const getInfo = () => {
  57. return http.get<UserInfo>('/auth/info')
  58. }