feat(auth): 预加载用户数据并优化登录状态同步
- 在启动屏预加载用户 token 与资料,避免首页白屏 - 新增 rehydrateUserSync 同步注入 Redux,减少异步等待 - 登录页兼容 ERR_REQUEST_CANCELED 取消场景 - 各页面统一依赖 isLoggedIn 判断,移除冗余控制台日志 - 步数卡片与详情页改为实时拉取健康数据,不再缓存至 Redux - 后台任务注册移至顶层,防止重复定义 - 体重记录、HeaderBar 等 UI 细节样式微调
This commit is contained in:
@@ -54,7 +54,6 @@ export type HourlyStandData = {
|
||||
};
|
||||
|
||||
export type TodayHealthData = {
|
||||
steps: number;
|
||||
activeEnergyBurned: number; // kilocalories
|
||||
basalEnergyBurned: number; // kilocalories - 基础代谢率
|
||||
hrv: number | null; // 心率变异性 (ms)
|
||||
@@ -68,8 +67,6 @@ export type TodayHealthData = {
|
||||
// 新增血氧饱和度和心率数据
|
||||
oxygenSaturation: number | null;
|
||||
heartRate: number | null;
|
||||
// 每小时步数数据
|
||||
hourlySteps: HourlyStepData[];
|
||||
};
|
||||
|
||||
export async function ensureHealthPermissions(): Promise<boolean> {
|
||||
@@ -172,7 +169,7 @@ function validateHeartRate(value: any): number | null {
|
||||
}
|
||||
|
||||
// 健康数据获取函数
|
||||
async function fetchStepCount(date: Date): Promise<number> {
|
||||
export async function fetchStepCount(date: Date): Promise<number> {
|
||||
return new Promise((resolve) => {
|
||||
AppleHealthKit.getStepCount({
|
||||
date: dayjs(date).toDate().toISOString()
|
||||
@@ -193,7 +190,7 @@ async function fetchStepCount(date: Date): Promise<number> {
|
||||
|
||||
|
||||
// 使用样本数据获取每小时步数
|
||||
async function fetchHourlyStepSamples(date: Date): Promise<HourlyStepData[]> {
|
||||
export async function fetchHourlyStepSamples(date: Date): Promise<HourlyStepData[]> {
|
||||
return new Promise((resolve) => {
|
||||
const startOfDay = dayjs(date).startOf('day');
|
||||
const endOfDay = dayjs(date).endOf('day');
|
||||
@@ -565,7 +562,6 @@ export async function fetchMaximumHeartRate(options: HealthDataOptions): Promise
|
||||
// 默认健康数据
|
||||
function getDefaultHealthData(): TodayHealthData {
|
||||
return {
|
||||
steps: 0,
|
||||
activeEnergyBurned: 0,
|
||||
basalEnergyBurned: 0,
|
||||
hrv: null,
|
||||
@@ -577,7 +573,6 @@ function getDefaultHealthData(): TodayHealthData {
|
||||
standHoursGoal: 12,
|
||||
oxygenSaturation: null,
|
||||
heartRate: null,
|
||||
hourlySteps: Array.from({ length: 24 }, (_, i) => ({ hour: i, steps: 0 }))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -590,8 +585,6 @@ export async function fetchHealthDataForDate(date: Date): Promise<TodayHealthDat
|
||||
|
||||
// 并行获取所有健康数据
|
||||
const [
|
||||
steps,
|
||||
hourlySteps,
|
||||
activeEnergyBurned,
|
||||
basalEnergyBurned,
|
||||
hrv,
|
||||
@@ -599,8 +592,6 @@ export async function fetchHealthDataForDate(date: Date): Promise<TodayHealthDat
|
||||
oxygenSaturation,
|
||||
heartRate
|
||||
] = await Promise.all([
|
||||
fetchStepCount(date),
|
||||
fetchHourlyStepSamples(date),
|
||||
fetchActiveEnergyBurned(options),
|
||||
fetchBasalEnergyBurned(options),
|
||||
fetchHeartRateVariability(options),
|
||||
@@ -610,8 +601,6 @@ export async function fetchHealthDataForDate(date: Date): Promise<TodayHealthDat
|
||||
]);
|
||||
|
||||
return {
|
||||
steps,
|
||||
hourlySteps,
|
||||
activeEnergyBurned,
|
||||
basalEnergyBurned,
|
||||
hrv,
|
||||
|
||||
Reference in New Issue
Block a user