auth.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { baseRequestClient, requestClient } from '#/api/request';
  2. export namespace AuthApi {
  3. /** 登录接口参数 */
  4. export interface LoginParams {
  5. password: string;
  6. username: string;
  7. }
  8. /** 登录接口返回值 */
  9. export interface LoginResult {
  10. accessToken: string;
  11. desc: string;
  12. realName: string;
  13. userId: string;
  14. username: string;
  15. }
  16. export interface RefreshTokenResult {
  17. data: string;
  18. status: number;
  19. }
  20. }
  21. /**
  22. * 登录
  23. */
  24. export async function loginApi(data: AuthApi.LoginParams) {
  25. return requestClient.post<AuthApi.LoginResult>('/auth/login', data);
  26. }
  27. /**
  28. * 刷新accessToken
  29. */
  30. export async function refreshTokenApi() {
  31. return baseRequestClient.post<AuthApi.RefreshTokenResult>('/auth/refresh', {
  32. withCredentials: true,
  33. });
  34. }
  35. /**
  36. * 退出登录
  37. */
  38. export async function logoutApi() {
  39. return baseRequestClient.post('/auth/logout', {
  40. withCredentials: true,
  41. });
  42. }
  43. /**
  44. * 获取用户权限码
  45. */
  46. export async function getAccessCodesApi() {
  47. return requestClient.get<string[]>('/auth/codes');
  48. }