42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { api } from './api';
|
||
|
||
export type CircumferencePeriod = 'week' | 'month' | 'year';
|
||
|
||
export type CircumferenceAnalysisData = {
|
||
label: string;
|
||
chestCircumference: number | null;
|
||
waistCircumference: number | null;
|
||
upperHipCircumference: number | null;
|
||
armCircumference: number | null;
|
||
thighCircumference: number | null;
|
||
calfCircumference: number | null;
|
||
};
|
||
|
||
export type CircumferenceAnalysisResponse = {
|
||
code: number;
|
||
message: string;
|
||
data: CircumferenceAnalysisData[];
|
||
};
|
||
|
||
/**
|
||
* 获取围度分析报表数据
|
||
* @param period 时间范围:week(按周)、month(按月)、year(按年)
|
||
* @returns 围度分析数据
|
||
*/
|
||
export async function getCircumferenceAnalysis(period: CircumferencePeriod): Promise<CircumferenceAnalysisData[]> {
|
||
try {
|
||
const response = await api.get<CircumferenceAnalysisResponse>(
|
||
`/users/body-measurements/analysis?period=${period}`
|
||
);
|
||
|
||
// 根据API文档,支持返回 { data: ... } 或直接返回数组
|
||
if (Array.isArray(response)) {
|
||
return response;
|
||
}
|
||
|
||
return response.data || [];
|
||
} catch (error) {
|
||
console.error('获取围度分析数据失败:', error);
|
||
throw error;
|
||
}
|
||
} |