feat(auth): 预加载用户数据并优化登录状态同步

- 在启动屏预加载用户 token 与资料,避免首页白屏
- 新增 rehydrateUserSync 同步注入 Redux,减少异步等待
- 登录页兼容 ERR_REQUEST_CANCELED 取消场景
- 各页面统一依赖 isLoggedIn 判断,移除冗余控制台日志
- 步数卡片与详情页改为实时拉取健康数据,不再缓存至 Redux
- 后台任务注册移至顶层,防止重复定义
- 体重记录、HeaderBar 等 UI 细节样式微调
This commit is contained in:
richarjiang
2025-09-15 09:56:42 +08:00
parent 55d133c470
commit 91df01bd79
18 changed files with 967 additions and 1018 deletions

View File

@@ -8,7 +8,18 @@ import { TaskManagerTaskBody } from 'expo-task-manager';
export const BACKGROUND_TASK_IDENTIFIER = 'com.anonymous.digitalpilates.task';
// 定义后台任务
TaskManager.defineTask(BACKGROUND_TASK_IDENTIFIER, async (body: TaskManagerTaskBody) => {
try {
log.info(`[BackgroundTask] 后台任务执行, 任务 ID: ${BACKGROUND_TASK_IDENTIFIER}`);
await executeBackgroundTasks();
} catch (error) {
console.error('[BackgroundTask] 任务执行失败:', error);
return BackgroundTask.BackgroundTaskResult.Failed;
}
return BackgroundTask.BackgroundTaskResult.Success;
});
// 检查通知权限
async function checkNotificationPermissions(): Promise<boolean> {
@@ -147,7 +158,7 @@ async function executeBackgroundTasks(): Promise<void> {
await executeWaterReminderTask();
// 执行站立提醒检查任务
await executeStandReminderTask();
// await executeStandReminderTask();
console.log('后台任务执行完成');
} catch (error) {
@@ -173,24 +184,14 @@ export class BackgroundTaskManager {
/**
* 初始化后台任务管理器
*/
async initialize(innerAppMountedPromise: Promise<void>): Promise<void> {
async initialize(): Promise<void> {
if (this.isInitialized) {
console.log('后台任务管理器已初始化');
return;
}
try {
// 定义后台任务
TaskManager.defineTask(BACKGROUND_TASK_IDENTIFIER, async (body: TaskManagerTaskBody) => {
try {
log.info(`[BackgroundTask] 后台任务执行, 任务 ID: ${BACKGROUND_TASK_IDENTIFIER}`);
await executeBackgroundTasks();
// return BackgroundTask.BackgroundTaskResult.Success;
} catch (error) {
console.error('[BackgroundTask] 任务执行失败:', error);
// return BackgroundTask.BackgroundTaskResult.Failed;
}
});
if (await TaskManager.isTaskRegisteredAsync(BACKGROUND_TASK_IDENTIFIER)) {
@@ -201,7 +202,7 @@ export class BackgroundTaskManager {
log.info('[BackgroundTask] 任务未注册, 开始注册...');
// 注册后台任务
await BackgroundTask.registerTaskAsync(BACKGROUND_TASK_IDENTIFIER, {
minimumInterval: 15,
minimumInterval: 15 * 2,
});