feat(workout): 重构锻炼模块并新增详细数据展示
- 移除旧的锻炼会话页面和布局文件 - 新增锻炼详情模态框组件,支持心率区间、运动强度等详细数据展示 - 优化锻炼历史页面,增加月度统计卡片和交互式详情查看 - 新增锻炼详情服务,提供心率分析、METs计算等功能 - 更新应用版本至1.0.17并调整iOS后台任务配置 - 添加项目规则文档,明确React Native开发规范
This commit is contained in:
@@ -26,6 +26,18 @@ export interface WorkoutData {
|
||||
metadata: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface HeartRateSample {
|
||||
id: string;
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
value: number;
|
||||
source?: {
|
||||
name: string;
|
||||
bundleIdentifier: string;
|
||||
};
|
||||
metadata?: Record<string, any>;
|
||||
}
|
||||
|
||||
// 锻炼记录查询选项
|
||||
export interface WorkoutOptions extends HealthDataOptions {
|
||||
limit?: number; // 默认10条
|
||||
@@ -770,6 +782,44 @@ export async function fetchOxygenSaturation(options: HealthDataOptions): Promise
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchHeartRateSamplesForRange(
|
||||
startDate: Date,
|
||||
endDate: Date,
|
||||
limit: number = 2000
|
||||
): Promise<HeartRateSample[]> {
|
||||
try {
|
||||
const options = {
|
||||
startDate: dayjs(startDate).toISOString(),
|
||||
endDate: dayjs(endDate).toISOString(),
|
||||
limit,
|
||||
};
|
||||
|
||||
const result = await HealthKitManager.getHeartRateSamples(options);
|
||||
|
||||
if (result && Array.isArray(result.data)) {
|
||||
const samples: HeartRateSample[] = result.data
|
||||
.filter((sample: any) => sample && typeof sample.value === 'number' && !Number.isNaN(sample.value))
|
||||
.map((sample: any) => ({
|
||||
id: sample.id,
|
||||
startDate: sample.startDate,
|
||||
endDate: sample.endDate,
|
||||
value: Number(sample.value),
|
||||
source: sample.source,
|
||||
metadata: sample.metadata,
|
||||
}));
|
||||
|
||||
logSuccess('锻炼心率采样', { count: samples.length, startDate: options.startDate, endDate: options.endDate });
|
||||
return samples;
|
||||
}
|
||||
|
||||
logWarning('锻炼心率采样', '为空或格式错误');
|
||||
return [];
|
||||
} catch (error) {
|
||||
logError('锻炼心率采样', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchHeartRate(options: HealthDataOptions): Promise<number | null> {
|
||||
try {
|
||||
const result = await HealthKitManager.getHeartRateSamples(options);
|
||||
|
||||
Reference in New Issue
Block a user