passwordApi.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { authService } from './authService';
  2. // API Base URL
  3. const API_BASE_URL = import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:8010';
  4. // 密码强度等级
  5. export type PasswordStrengthLevel = 'weak' | 'medium' | 'strong';
  6. // 密码强度检测响应
  7. export interface PasswordStrengthResponse {
  8. strength: PasswordStrengthLevel;
  9. score: number;
  10. suggestions: string[];
  11. meets_requirements: boolean;
  12. }
  13. /**
  14. * 密码强度API服务类
  15. */
  16. class PasswordApiService {
  17. private baseUrl = `${API_BASE_URL}/api/password`;
  18. /**
  19. * 检测密码强度
  20. */
  21. async checkPasswordStrength(password: string): Promise<PasswordStrengthResponse> {
  22. const response = await fetch(`${this.baseUrl}/check-strength`, {
  23. method: 'POST',
  24. headers: {
  25. 'Content-Type': 'application/json'
  26. },
  27. body: JSON.stringify({ password }),
  28. });
  29. if (!response.ok) {
  30. throw new Error('密码强度检测失败');
  31. }
  32. return response.json();
  33. }
  34. }
  35. // 导出单例
  36. export const passwordApi = new PasswordApiService();