systemAuth.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // 系统管理员认证API端点(系统级,路径前缀 /sys)
  2. import type { AxiosInstance } from 'axios';
  3. import type { LoginResponse, SystemUser, ChangePasswordRequest } from '@smartcut/types';
  4. import type { ApiResponse } from '@smartcut/types';
  5. export class SystemAuthApi {
  6. constructor(private client: AxiosInstance) {}
  7. /**
  8. * 系统管理员登录(无需 factory_id)
  9. */
  10. async login(data: { username: string; password: string }): Promise<LoginResponse> {
  11. const response = await this.client.post<ApiResponse<LoginResponse>>('/sys/auth/login', data);
  12. if (!response.data.data) {
  13. throw new Error(response.data.msg || '登录失败');
  14. }
  15. return response.data.data;
  16. }
  17. /**
  18. * 获取当前系统管理员信息
  19. */
  20. async getProfile(): Promise<SystemUser> {
  21. const response = await this.client.get<ApiResponse<SystemUser>>('/sys/auth/profile');
  22. return response.data.data;
  23. }
  24. /**
  25. * 修改密码
  26. */
  27. async changePassword(data: ChangePasswordRequest): Promise<void> {
  28. await this.client.put<ApiResponse>('/sys/auth/password', data);
  29. }
  30. /**
  31. * 登出(撤销后端 jti)
  32. */
  33. async logout(): Promise<void> {
  34. await this.client.post<ApiResponse>('/sys/auth/logout');
  35. }
  36. }