|
@@ -1,5 +1,6 @@
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { Router } from '@angular/router';
|
|
import { Router } from '@angular/router';
|
|
|
|
+import { CommonModule, NgFor, NgIf, DatePipe } from '@angular/common';
|
|
import {
|
|
import {
|
|
IonHeader,
|
|
IonHeader,
|
|
IonToolbar,
|
|
IonToolbar,
|
|
@@ -16,9 +17,14 @@ import {
|
|
IonItem,
|
|
IonItem,
|
|
IonLabel,
|
|
IonLabel,
|
|
IonBadge,
|
|
IonBadge,
|
|
- IonProgressBar
|
|
|
|
|
|
+ IonProgressBar,
|
|
|
|
+ IonItemSliding,
|
|
|
|
+ IonItemOptions,
|
|
|
|
+ IonItemOption,
|
|
|
|
+ IonCheckbox,
|
|
|
|
+ AlertController,
|
|
|
|
+ IonButton
|
|
} from '@ionic/angular/standalone';
|
|
} from '@ionic/angular/standalone';
|
|
-import { NgIf } from '@angular/common';
|
|
|
|
import { addIcons } from 'ionicons';
|
|
import { addIcons } from 'ionicons';
|
|
import {
|
|
import {
|
|
notifications,
|
|
notifications,
|
|
@@ -26,8 +32,14 @@ import {
|
|
barChart,
|
|
barChart,
|
|
people,
|
|
people,
|
|
star,
|
|
star,
|
|
- heart // 添加 heart 图标
|
|
|
|
|
|
+ heart,
|
|
|
|
+ calendar,
|
|
|
|
+ checkmarkCircle,
|
|
|
|
+ ellipseOutline,
|
|
|
|
+ refreshOutline
|
|
} from 'ionicons/icons';
|
|
} from 'ionicons/icons';
|
|
|
|
+import { DailyPlanService, DailyPlan } from '../services/daily-plan.service';
|
|
|
|
+import { FormsModule } from '@angular/forms';
|
|
|
|
|
|
interface Notification {
|
|
interface Notification {
|
|
id: number;
|
|
id: number;
|
|
@@ -41,6 +53,7 @@ interface Notification {
|
|
styleUrls: ['tab2.page.scss'],
|
|
styleUrls: ['tab2.page.scss'],
|
|
standalone: true,
|
|
standalone: true,
|
|
imports: [
|
|
imports: [
|
|
|
|
+ CommonModule,
|
|
IonHeader,
|
|
IonHeader,
|
|
IonToolbar,
|
|
IonToolbar,
|
|
IonTitle,
|
|
IonTitle,
|
|
@@ -57,23 +70,40 @@ interface Notification {
|
|
IonLabel,
|
|
IonLabel,
|
|
IonBadge,
|
|
IonBadge,
|
|
IonProgressBar,
|
|
IonProgressBar,
|
|
- NgIf
|
|
|
|
|
|
+ NgFor,
|
|
|
|
+ NgIf,
|
|
|
|
+ DatePipe,
|
|
|
|
+ IonItemSliding,
|
|
|
|
+ IonItemOptions,
|
|
|
|
+ IonItemOption,
|
|
|
|
+ IonCheckbox,
|
|
|
|
+ FormsModule,
|
|
|
|
+ IonButton
|
|
]
|
|
]
|
|
})
|
|
})
|
|
export class Tab2Page implements OnInit {
|
|
export class Tab2Page implements OnInit {
|
|
notifications: Notification[] = [];
|
|
notifications: Notification[] = [];
|
|
- dailyProgress: number = 0.65; // 示例进度
|
|
|
|
- completedTasks: number = 13;
|
|
|
|
- totalTasks: number = 20;
|
|
|
|
|
|
+ dailyProgress: number = 0;
|
|
|
|
+ completedTasks: number = 0;
|
|
|
|
+ totalTasks: number = 0;
|
|
|
|
+ todayPlans: DailyPlan[] = [];
|
|
|
|
|
|
- constructor(private router: Router) {
|
|
|
|
|
|
+ constructor(
|
|
|
|
+ private router: Router,
|
|
|
|
+ private dailyPlanService: DailyPlanService,
|
|
|
|
+ private alertController: AlertController
|
|
|
|
+ ) {
|
|
addIcons({
|
|
addIcons({
|
|
notifications,
|
|
notifications,
|
|
bulb,
|
|
bulb,
|
|
barChart,
|
|
barChart,
|
|
people,
|
|
people,
|
|
star,
|
|
star,
|
|
- heart // 添加 heart 图标
|
|
|
|
|
|
+ heart,
|
|
|
|
+ calendar,
|
|
|
|
+ checkmarkCircle,
|
|
|
|
+ ellipseOutline,
|
|
|
|
+ refreshOutline
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -86,6 +116,29 @@ export class Tab2Page implements OnInit {
|
|
date: new Date()
|
|
date: new Date()
|
|
}
|
|
}
|
|
];
|
|
];
|
|
|
|
+ this.loadTodayPlans();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async loadTodayPlans() {
|
|
|
|
+ try {
|
|
|
|
+ // 获取今天的日期,格式化为 ISO 字符串的日期部分
|
|
|
|
+ const today = new Date().toISOString();
|
|
|
|
+ this.todayPlans = await this.dailyPlanService.getDailyPlans(today);
|
|
|
|
+
|
|
|
|
+ // 更新进度
|
|
|
|
+ if (this.todayPlans.length > 0) {
|
|
|
|
+ const completed = this.todayPlans.filter(plan => plan.completed).length;
|
|
|
|
+ this.completedTasks = completed;
|
|
|
|
+ this.totalTasks = this.todayPlans.length;
|
|
|
|
+ this.dailyProgress = completed / this.todayPlans.length;
|
|
|
|
+ } else {
|
|
|
|
+ this.completedTasks = 0;
|
|
|
|
+ this.totalTasks = 0;
|
|
|
|
+ this.dailyProgress = 0;
|
|
|
|
+ }
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error('加载今日计划失败:', error);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
navigateToFeature(feature: string) {
|
|
navigateToFeature(feature: string) {
|
|
@@ -105,8 +158,110 @@ export class Tab2Page implements OnInit {
|
|
case 'favorites':
|
|
case 'favorites':
|
|
this.router.navigate(['/tabs/favorite-exercises']);
|
|
this.router.navigate(['/tabs/favorite-exercises']);
|
|
break;
|
|
break;
|
|
|
|
+ case 'daily-plan':
|
|
|
|
+ this.router.navigate(['/daily-plan']);
|
|
|
|
+ break;
|
|
default:
|
|
default:
|
|
console.log(`Navigating to ${feature}`);
|
|
console.log(`Navigating to ${feature}`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ async onPlanStatusChange(plan: DailyPlan) {
|
|
|
|
+ try {
|
|
|
|
+ await this.dailyPlanService.updatePlanStatus(plan.id, plan.completed);
|
|
|
|
+ // 更新进度
|
|
|
|
+ const completed = this.todayPlans.filter(p => p.completed).length;
|
|
|
|
+ this.completedTasks = completed;
|
|
|
|
+ this.dailyProgress = completed / this.todayPlans.length;
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error('更新状态失败:', error);
|
|
|
|
+ plan.completed = !plan.completed; // 恢复原状态
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async editPlan(plan: DailyPlan, event: Event) {
|
|
|
|
+ event.stopPropagation(); // 阻止事件冒泡
|
|
|
|
+ const alert = await this.alertController.create({
|
|
|
|
+ header: '编辑学习计划',
|
|
|
|
+ inputs: [
|
|
|
|
+ {
|
|
|
|
+ name: 'content',
|
|
|
|
+ type: 'text',
|
|
|
|
+ value: plan.content,
|
|
|
|
+ placeholder: '学习内容'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ name: 'timeSlot',
|
|
|
|
+ type: 'text',
|
|
|
|
+ value: plan.timeSlot,
|
|
|
|
+ placeholder: '时间段'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ name: 'duration',
|
|
|
|
+ type: 'number',
|
|
|
|
+ value: plan.duration,
|
|
|
|
+ placeholder: '预计时长(分钟)'
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ buttons: [
|
|
|
|
+ {
|
|
|
|
+ text: '取消',
|
|
|
|
+ role: 'cancel'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ text: '保存',
|
|
|
|
+ handler: async (data) => {
|
|
|
|
+ if (!data.content || !data.timeSlot || !data.duration) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ await this.dailyPlanService.updatePlan(plan.id, {
|
|
|
|
+ ...plan,
|
|
|
|
+ content: data.content,
|
|
|
|
+ timeSlot: data.timeSlot,
|
|
|
|
+ duration: parseInt(data.duration)
|
|
|
|
+ });
|
|
|
|
+ await this.loadTodayPlans(); // 重新加载计划列表
|
|
|
|
+ return true;
|
|
|
|
+ } catch (error) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ });
|
|
|
|
+ await alert.present();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async deletePlan(plan: DailyPlan, event: Event) {
|
|
|
|
+ event.stopPropagation(); // 阻止事件冒泡
|
|
|
|
+ const alert = await this.alertController.create({
|
|
|
|
+ header: '确认删除',
|
|
|
|
+ message: '确定要删除这个学习计划吗?',
|
|
|
|
+ buttons: [
|
|
|
|
+ {
|
|
|
|
+ text: '取消',
|
|
|
|
+ role: 'cancel'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ text: '删除',
|
|
|
|
+ handler: async () => {
|
|
|
|
+ try {
|
|
|
|
+ await this.dailyPlanService.deletePlan(plan.id);
|
|
|
|
+ await this.loadTodayPlans(); // 重新加载计划列表
|
|
|
|
+ return true;
|
|
|
|
+ } catch (error) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ });
|
|
|
|
+ await alert.present();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async refreshPlans(event: Event) {
|
|
|
|
+ event.stopPropagation(); // 阻止事件冒泡,避免触发卡片的点击事件
|
|
|
|
+ await this.loadTodayPlans();
|
|
|
|
+ }
|
|
}
|
|
}
|