auth.ts 955 B

123456789101112131415161718192021222324252627282930313233
  1. // 认证API端点
  2. import type { AxiosInstance } from 'axios';
  3. import type { LoginRequest, LoginResponse, User, SystemUser, ChangePasswordRequest } from '@smartcut/types';
  4. import type { ApiResponse } from '@smartcut/types';
  5. export class AuthApi {
  6. constructor(private client: AxiosInstance) {}
  7. /**
  8. * 用户登录
  9. * 新增factory_id参数(Query参数传递)
  10. */
  11. async login(data: LoginRequest): Promise<LoginResponse> {
  12. const response = await this.client.post<ApiResponse<LoginResponse>>('/auth/login', data);
  13. return response.data.data;
  14. }
  15. /**
  16. * 获取当前用户信息
  17. */
  18. async getProfile(): Promise<User | SystemUser> {
  19. const response = await this.client.get<ApiResponse<User | SystemUser>>('/auth/profile');
  20. return response.data.data;
  21. }
  22. /**
  23. * 修改密码
  24. */
  25. async changePassword(data: ChangePasswordRequest): Promise<void> {
  26. await this.client.put<ApiResponse>('/auth/password', data);
  27. }
  28. }