feat: 优化健康数据相关组件及功能

- 在 CoachScreen 中调整键盘高度计算,移除不必要的 insets.bottom
- 更新 Statistics 组件,移除未使用的健康数据相关函数,简化代码
- 修改多个统计卡片,移除不必要的图标属性,提升组件简洁性
- 优化 HealthDataCard 和其他统计卡片的样式,提升视觉一致性
- 更新健康数据获取逻辑,确保数据处理更为准确
- 移除 MoodCard 中的多余元素,简化心情记录展示
- 调整 StressMeter 和其他组件的样式,提升用户体验
This commit is contained in:
richarjiang
2025-08-25 12:44:40 +08:00
parent ee84a801fb
commit be0a8e7393
10 changed files with 83 additions and 197 deletions

View File

@@ -221,13 +221,13 @@ export async function fetchHealthDataForDate(date: Date): Promise<TodayHealthDat
const latestOxygen = res[res.length - 1];
if (latestOxygen && latestOxygen.value !== undefined && latestOxygen.value !== null) {
let value = Number(latestOxygen.value);
// 检查数据格式如果值小于1可能是小数形式0.0-1.0),需要转换为百分比
if (value > 0 && value < 1) {
value = value * 100;
console.log('血氧饱和度数据从小数转换为百分比:', latestOxygen.value, '->', value);
}
// 血氧饱和度通常在0-100之间验证数据有效性
if (value >= 0 && value <= 100) {
resolve(Number(value.toFixed(1)));
@@ -280,12 +280,12 @@ export async function fetchHealthDataForDate(date: Date): Promise<TodayHealthDat
sleepDuration,
hrv,
// 健身圆环数据
activeCalories: activitySummary?.activeEnergyBurned || 0,
activeCaloriesGoal: activitySummary?.activeEnergyBurnedGoal || 350,
exerciseMinutes: activitySummary?.appleExerciseTime || 0,
exerciseMinutesGoal: activitySummary?.appleExerciseTimeGoal || 30,
standHours: activitySummary?.appleStandHours || 0,
standHoursGoal: activitySummary?.appleStandHoursGoal || 12,
activeCalories: Math.round(activitySummary?.activeEnergyBurned || 0),
activeCaloriesGoal: Math.round(activitySummary?.activeEnergyBurnedGoal || 350),
exerciseMinutes: Math.round(activitySummary?.appleExerciseTime || 0),
exerciseMinutesGoal: Math.round(activitySummary?.appleExerciseTimeGoal || 30),
standHours: Math.round(activitySummary?.appleStandHours || 0),
standHoursGoal: Math.round(activitySummary?.appleStandHoursGoal || 12),
// 血氧饱和度和心率数据
oxygenSaturation,
heartRate
@@ -357,15 +357,15 @@ export async function updateWeight(weight: number) {
// 新增:测试血氧饱和度数据获取
export async function testOxygenSaturationData(date: Date = new Date()): Promise<void> {
console.log('=== 开始测试血氧饱和度数据获取 ===');
const start = dayjs(date).startOf('day').toDate();
const end = dayjs(date).endOf('day').toDate();
const options = {
startDate: start.toISOString(),
endDate: end.toISOString()
} as any;
return new Promise((resolve) => {
AppleHealthKit.getOxygenSaturationSamples(options, (err, res) => {
if (err) {
@@ -373,15 +373,15 @@ export async function testOxygenSaturationData(date: Date = new Date()): Promise
resolve();
return;
}
console.log('原始血氧饱和度数据:', res);
if (!res || !Array.isArray(res) || res.length === 0) {
console.warn('血氧饱和度数据为空');
resolve();
return;
}
// 分析所有数据样本
res.forEach((sample, index) => {
console.log(`样本 ${index + 1}:`, {
@@ -391,26 +391,26 @@ export async function testOxygenSaturationData(date: Date = new Date()): Promise
endDate: sample.endDate
});
});
// 获取最新的血氧饱和度值
const latestOxygen = res[res.length - 1];
if (latestOxygen && latestOxygen.value !== undefined && latestOxygen.value !== null) {
let value = Number(latestOxygen.value);
console.log('处理前的值:', latestOxygen.value);
console.log('转换为数字后的值:', value);
// 检查数据格式如果值小于1可能是小数形式0.0-1.0),需要转换为百分比
if (value > 0 && value < 1) {
const originalValue = value;
value = value * 100;
console.log('血氧饱和度数据从小数转换为百分比:', originalValue, '->', value);
}
console.log('最终处理后的值:', value);
console.log('数据有效性检查:', value >= 0 && value <= 100 ? '有效' : '无效');
}
console.log('=== 血氧饱和度数据测试完成 ===');
resolve();
});