feat(ios): 添加用药计划Widget小组件支持
- 创建medicineExtension小组件,支持iOS桌面显示用药计划 - 实现App Group数据共享机制,支持主应用与小组件数据同步 - 添加AppGroupUserDefaultsManager原生模块,提供跨应用数据访问能力 - 添加WidgetManager和WidgetCenterHelper,实现小组件刷新控制 - 在medications页面和Redux store中集成小组件数据同步逻辑 - 支持实时同步今日用药状态(待服用/已服用/已错过)到小组件 - 配置App Group entitlements (group.com.anonymous.digitalpilates) - 更新Xcode项目配置,添加WidgetKit和SwiftUI框架支持
This commit is contained in:
@@ -9,6 +9,7 @@ import { useColorScheme } from '@/hooks/useColorScheme';
|
||||
import { medicationNotificationService } from '@/services/medicationNotifications';
|
||||
import { fetchMedicationRecords, fetchMedications, selectMedicationDisplayItemsByDate } from '@/store/medicationsSlice';
|
||||
import { DEFAULT_MEMBER_NAME } from '@/store/userSlice';
|
||||
import { convertMedicationDataToWidget, refreshWidget, syncMedicationDataToWidget } from '@/utils/widgetDataSync';
|
||||
import { useFocusEffect } from '@react-navigation/native';
|
||||
import dayjs, { Dayjs } from 'dayjs';
|
||||
import 'dayjs/locale/zh-cn';
|
||||
@@ -105,10 +106,25 @@ export default function MedicationsScreen() {
|
||||
const medications = await dispatch(fetchMedications({ isActive: true })).unwrap();
|
||||
|
||||
// 并行执行获取药物记录和安排通知
|
||||
await Promise.all([
|
||||
const [recordsAction] = await Promise.all([
|
||||
dispatch(fetchMedicationRecords({ date: selectedKey })),
|
||||
medicationNotificationService.rescheduleAllMedicationNotifications(medications),
|
||||
]);
|
||||
|
||||
// 同步数据到小组件(仅同步今天的)
|
||||
const today = dayjs().format('YYYY-MM-DD');
|
||||
const records = recordsAction.payload as any;
|
||||
if (selectedKey === today && records?.records) {
|
||||
const medicationData = convertMedicationDataToWidget(
|
||||
records.records,
|
||||
medications,
|
||||
selectedKey
|
||||
);
|
||||
await syncMedicationDataToWidget(medicationData);
|
||||
|
||||
// 刷新小组件
|
||||
await refreshWidget();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('刷新数据或重新安排药品通知失败:', error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user