feat: 移除目标管理功能模块
删除了完整的目标管理功能,包括目标创建、编辑、任务管理等相关页面和组件。同时移除了相关的API服务、Redux状态管理、类型定义和通知功能。应用版本从1.0.20升级到1.0.21。
This commit is contained in:
@@ -78,214 +78,7 @@ export class WorkoutNotificationHelpers {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 目标相关的通知辅助函数
|
||||
*/
|
||||
export class GoalNotificationHelpers {
|
||||
/**
|
||||
* 发送目标达成通知
|
||||
*/
|
||||
static async sendGoalAchievementNotification(userName: string, goalName: string) {
|
||||
return notificationService.sendImmediateNotification({
|
||||
title: '目标达成',
|
||||
body: `${userName},恭喜您达成了目标:${goalName}!`,
|
||||
data: { type: 'goal_achievement', goalName },
|
||||
sound: true,
|
||||
priority: 'high',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送目标进度更新通知
|
||||
*/
|
||||
static async sendGoalProgressNotification(userName: string, goalName: string, progress: number) {
|
||||
return notificationService.sendImmediateNotification({
|
||||
title: '目标进度',
|
||||
body: `${userName},您的目标"${goalName}"已完成${progress}%!`,
|
||||
data: { type: 'goal_progress', goalName, progress },
|
||||
sound: true,
|
||||
priority: 'normal',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 安排目标提醒
|
||||
*/
|
||||
static async scheduleGoalReminder(userName: string, goalName: string, deadline: Date) {
|
||||
// 在截止日期前一天发送提醒
|
||||
const reminderDate = new Date(deadline);
|
||||
reminderDate.setDate(reminderDate.getDate() - 1);
|
||||
|
||||
return notificationService.scheduleNotificationAtDate(
|
||||
{
|
||||
title: '目标截止提醒',
|
||||
body: `${userName},您的目标"${goalName}"明天就要截止了,加油!`,
|
||||
data: { type: 'goal_deadline_reminder', goalName },
|
||||
sound: true,
|
||||
priority: 'high',
|
||||
},
|
||||
reminderDate
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据目标设置创建定时推送
|
||||
* @param goalData 目标数据
|
||||
* @param userName 用户名
|
||||
* @returns 通知ID数组
|
||||
*/
|
||||
static async scheduleGoalNotifications(
|
||||
goalData: {
|
||||
title: string;
|
||||
repeatType: 'daily' | 'weekly' | 'monthly';
|
||||
frequency: number;
|
||||
hasReminder: boolean;
|
||||
reminderTime?: string;
|
||||
customRepeatRule?: {
|
||||
weekdays?: number[];
|
||||
dayOfMonth?: number[];
|
||||
};
|
||||
startTime?: number;
|
||||
},
|
||||
userName: string
|
||||
): Promise<string[]> {
|
||||
const notificationIds: string[] = [];
|
||||
|
||||
// 如果没有开启提醒,直接返回
|
||||
if (!goalData.hasReminder || !goalData.reminderTime) {
|
||||
console.log('目标未开启提醒或未设置提醒时间');
|
||||
return notificationIds;
|
||||
}
|
||||
|
||||
try {
|
||||
// 解析提醒时间
|
||||
const [hours, minutes] = goalData.reminderTime.split(':').map(Number);
|
||||
|
||||
// 创建通知内容
|
||||
const notification: NotificationData = {
|
||||
title: '目标提醒',
|
||||
body: `${userName},该完成您的目标"${goalData.title}"了!`,
|
||||
data: {
|
||||
type: 'goal_reminder',
|
||||
goalTitle: goalData.title,
|
||||
repeatType: goalData.repeatType,
|
||||
frequency: goalData.frequency
|
||||
},
|
||||
sound: true,
|
||||
priority: 'high',
|
||||
};
|
||||
|
||||
// 根据重复类型创建不同的通知
|
||||
switch (goalData.repeatType) {
|
||||
case 'daily':
|
||||
// 每日重复 - 使用日历重复通知
|
||||
const dailyId = await notificationService.scheduleCalendarRepeatingNotification(
|
||||
notification,
|
||||
{
|
||||
type: Notifications.SchedulableTriggerInputTypes.DAILY,
|
||||
hour: hours,
|
||||
minute: minutes,
|
||||
}
|
||||
);
|
||||
notificationIds.push(dailyId);
|
||||
console.log(`已安排每日目标提醒,通知ID:${dailyId}`);
|
||||
break;
|
||||
|
||||
case 'weekly':
|
||||
// 每周重复 - 为每个选中的星期几创建单独的通知
|
||||
if (goalData.customRepeatRule?.weekdays && goalData.customRepeatRule.weekdays.length > 0) {
|
||||
for (const weekday of goalData.customRepeatRule.weekdays) {
|
||||
const weeklyId = await notificationService.scheduleCalendarRepeatingNotification(
|
||||
notification,
|
||||
{
|
||||
type: Notifications.SchedulableTriggerInputTypes.WEEKLY,
|
||||
hour: hours,
|
||||
minute: minutes,
|
||||
weekdays: [weekday],
|
||||
}
|
||||
);
|
||||
notificationIds.push(weeklyId);
|
||||
console.log(`已安排每周目标提醒,星期${weekday},通知ID:${weeklyId}`);
|
||||
}
|
||||
} else {
|
||||
// 默认每周重复
|
||||
const weeklyId = await notificationService.scheduleCalendarRepeatingNotification(
|
||||
notification,
|
||||
{
|
||||
type: Notifications.SchedulableTriggerInputTypes.WEEKLY,
|
||||
hour: hours,
|
||||
minute: minutes,
|
||||
}
|
||||
);
|
||||
notificationIds.push(weeklyId);
|
||||
console.log(`已安排每周目标提醒,通知ID:${weeklyId}`);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'monthly':
|
||||
// 每月重复 - 为每个选中的日期创建单独的通知
|
||||
if (goalData.customRepeatRule?.dayOfMonth && goalData.customRepeatRule.dayOfMonth.length > 0) {
|
||||
for (const dayOfMonth of goalData.customRepeatRule.dayOfMonth) {
|
||||
const monthlyId = await notificationService.scheduleCalendarRepeatingNotification(
|
||||
notification,
|
||||
{
|
||||
type: Notifications.SchedulableTriggerInputTypes.MONTHLY,
|
||||
hour: hours,
|
||||
minute: minutes,
|
||||
dayOfMonth: dayOfMonth,
|
||||
}
|
||||
);
|
||||
notificationIds.push(monthlyId);
|
||||
console.log(`已安排每月目标提醒,${dayOfMonth}号,通知ID:${monthlyId}`);
|
||||
}
|
||||
} else {
|
||||
// 默认每月重复
|
||||
const monthlyId = await notificationService.scheduleCalendarRepeatingNotification(
|
||||
notification,
|
||||
{
|
||||
type: Notifications.SchedulableTriggerInputTypes.MONTHLY,
|
||||
hour: hours,
|
||||
minute: minutes,
|
||||
dayOfMonth: 1,
|
||||
}
|
||||
);
|
||||
notificationIds.push(monthlyId);
|
||||
console.log(`已安排每月目标提醒,通知ID:${monthlyId}`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
console.log(`目标"${goalData.title}"的定时推送已创建完成,共${notificationIds.length}个通知`);
|
||||
return notificationIds;
|
||||
|
||||
} catch (error) {
|
||||
console.error('创建目标定时推送失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 取消特定目标的所有通知
|
||||
*/
|
||||
static async cancelGoalNotifications(goalTitle: string): Promise<void> {
|
||||
try {
|
||||
const notifications = await notificationService.getAllScheduledNotifications();
|
||||
|
||||
for (const notification of notifications) {
|
||||
if (notification.content.data?.type === 'goal_reminder' &&
|
||||
notification.content.data?.goalTitle === goalTitle) {
|
||||
await notificationService.cancelNotification(notification.identifier);
|
||||
console.log(`已取消目标"${goalTitle}"的通知:${notification.identifier}`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('取消目标通知失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
// GoalNotificationHelpers 类已删除,因为目标功能已移除
|
||||
|
||||
export class ChallengeNotificationHelpers {
|
||||
static buildChallengesTabUrl(): string {
|
||||
|
||||
Reference in New Issue
Block a user