| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- // 系统管理员认证API端点(系统级,路径前缀 /sys)
- import type { AxiosInstance } from 'axios';
- import type { LoginResponse, SystemUser, ChangePasswordRequest } from '@smartcut/types';
- import type { ApiResponse } from '@smartcut/types';
- export class SystemAuthApi {
- constructor(private client: AxiosInstance) {}
- /**
- * 系统管理员登录(无需 factory_id)
- */
- async login(data: { username: string; password: string }): Promise<LoginResponse> {
- const response = await this.client.post<ApiResponse<LoginResponse>>('/sys/auth/login', data);
- if (!response.data.data) {
- throw new Error(response.data.msg || '登录失败');
- }
- return response.data.data;
- }
- /**
- * 获取当前系统管理员信息
- */
- async getProfile(): Promise<SystemUser> {
- const response = await this.client.get<ApiResponse<SystemUser>>('/sys/auth/profile');
- return response.data.data;
- }
- /**
- * 修改密码
- */
- async changePassword(data: ChangePasswordRequest): Promise<void> {
- await this.client.put<ApiResponse>('/sys/auth/password', data);
- }
- /**
- * 登出(撤销后端 jti)
- */
- async logout(): Promise<void> {
- await this.client.post<ApiResponse>('/sys/auth/logout');
- }
- }
|