geo/frontend/lib/api/health-score.ts

43 lines
1.1 KiB
TypeScript

import { API_BASE } from "./client";
export interface HealthScoreDimension {
name: string;
score: number;
max_score: number;
percentage: number;
status: string;
}
export interface HealthScoreRecommendation {
priority: string;
dimension: string;
title: string;
description: string;
}
export interface HealthScoreResponse {
brand_name: string;
overall_score: number;
health_level: string;
health_level_label: string;
dimensions: HealthScoreDimension[];
recommendations: HealthScoreRecommendation[];
is_full_report: boolean;
cached: boolean;
}
export const healthScoreApi = {
getHealthScore: async (brand: string, competitors?: string[]): Promise<HealthScoreResponse> => {
const params = new URLSearchParams({ brand });
if (competitors && competitors.length > 0) {
params.set("competitors", competitors.join(","));
}
const res = await fetch(`${API_BASE}/api/v1/public/health-score?${params}`);
if (!res.ok) {
const error = await res.json().catch(() => ({}));
throw new Error(error.detail || `请求失败 (HTTP ${res.status})`);
}
return res.json();
},
};