feat(health): 新增日照时长监测卡片与 HealthKit 集成
- iOS 端集成 HealthKit 日照时间 (TimeInDaylight) 数据获取接口 - 新增 SunlightCard 组件,支持查看今日数据及最近30天历史趋势图表 - 更新统计页和自定义设置页,支持开启/关闭日照卡片 - 优化 HealthDataCard 组件,支持自定义图标组件和副标题显示 - 更新多语言文件及应用版本号至 1.1.6
This commit is contained in:
@@ -801,6 +801,50 @@ export async function fetchOxygenSaturation(options: HealthDataOptions): Promise
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchTimeInDaylight(options: HealthDataOptions): Promise<number | null> {
|
||||
try {
|
||||
const result = await HealthKitManager.getTimeInDaylight(options);
|
||||
|
||||
if (result && result.totalValue !== undefined) {
|
||||
logSuccess('晒太阳时长', result);
|
||||
return result.totalValue;
|
||||
} else {
|
||||
logWarning('晒太阳时长', '为空或格式错误');
|
||||
return null;
|
||||
}
|
||||
} catch (error) {
|
||||
logError('晒太阳时长', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export interface SunlightHistoryPoint {
|
||||
date: string;
|
||||
value: number;
|
||||
}
|
||||
|
||||
export async function fetchTimeInDaylightHistory(options: HealthDataOptions): Promise<SunlightHistoryPoint[]> {
|
||||
try {
|
||||
const result = await HealthKitManager.getTimeInDaylightSamples(options);
|
||||
|
||||
if (result && result.data && Array.isArray(result.data)) {
|
||||
logSuccess('晒太阳历史', result);
|
||||
return result.data
|
||||
.filter((item: any) => item && typeof item.value === 'number' && item.date)
|
||||
.map((item: any) => ({
|
||||
date: item.date,
|
||||
value: Number(item.value)
|
||||
}));
|
||||
} else {
|
||||
logWarning('晒太阳历史', '为空或格式错误');
|
||||
return [];
|
||||
}
|
||||
} catch (error) {
|
||||
logError('晒太阳历史', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchWristTemperature(options: HealthDataOptions, targetDate?: Date): Promise<number | null> {
|
||||
try {
|
||||
const result = await HealthKitManager.getWristTemperatureSamples(options);
|
||||
|
||||
Reference in New Issue
Block a user