|
@@ -11,14 +11,13 @@ import { addIcons } from 'ionicons';
|
|
|
import {
|
|
|
notificationsOutline, calendarNumber, checkmarkCircle, ellipseOutline,
|
|
|
timeOutline, barbell, body, walk, add, refresh, fitness,
|
|
|
- flame, bicycle, trophy, ellipsisHorizontal, footsteps, footstepsOutline, chatbubbleEllipses, barChartOutline, calendarClearOutline, star, checkmarkCircleOutline } from 'ionicons/icons';
|
|
|
+ flame, bicycle, trophy, ellipsisHorizontal, footsteps, footstepsOutline, chatbubbleEllipses, barChartOutline, calendarClearOutline, star, checkmarkCircleOutline, trashOutline } from 'ionicons/icons';
|
|
|
|
|
|
// 引用fmode-ng智能体组件
|
|
|
import { ChatPanelOptions, FmodeChat, FmodeChatMessage, openChatPanelModal } from 'fmode-ng';
|
|
|
import Parse from "parse";
|
|
|
import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
|
|
|
-
|
|
|
-
|
|
|
+import { AlertController,ToastController } from '@ionic/angular';
|
|
|
// 导入计划创建模态框组件
|
|
|
import { PlanCreationModalComponent } from './plan-creation-modal.component';
|
|
|
|
|
@@ -26,6 +25,7 @@ import { PlanCreationModalComponent } from './plan-creation-modal.component';
|
|
|
selector: 'app-tab2',
|
|
|
templateUrl: 'tab2.page.html',
|
|
|
styleUrls: ['tab2.page.scss'],
|
|
|
+ providers: [AlertController],
|
|
|
standalone: true,
|
|
|
imports: [
|
|
|
CommonModule,
|
|
@@ -148,8 +148,10 @@ export class Tab2Page {
|
|
|
|
|
|
constructor(
|
|
|
private modalCtrl: ModalController,
|
|
|
+ private alertCtrl: AlertController,
|
|
|
+ private toastCtrl: ToastController
|
|
|
) {
|
|
|
- addIcons({notificationsOutline,calendarNumber,refresh,barChartOutline,timeOutline,footsteps,calendarClearOutline,add,star,checkmarkCircleOutline,chatbubbleEllipses,checkmarkCircle,ellipseOutline,barbell,body,walk,fitness,flame,bicycle,trophy,ellipsisHorizontal,footstepsOutline});
|
|
|
+ addIcons({notificationsOutline,calendarNumber,refresh,barChartOutline,timeOutline,footsteps,trashOutline,calendarClearOutline,add,star,checkmarkCircleOutline,chatbubbleEllipses,checkmarkCircle,ellipseOutline,barbell,body,walk,fitness,flame,bicycle,trophy,ellipsisHorizontal,footstepsOutline});
|
|
|
|
|
|
// 初始化周数据
|
|
|
this.weekDays = this.generateWeekDays();
|
|
@@ -272,6 +274,81 @@ export class Tab2Page {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async confirmDelete(event: Event, plan: any) {
|
|
|
+ event.stopPropagation(); // 阻止事件冒泡
|
|
|
+
|
|
|
+ const alert = await this.alertCtrl.create({
|
|
|
+ header: '确认删除',
|
|
|
+ message: `确定要删除「${plan.name}」训练计划吗?此操作不可撤销!`,
|
|
|
+ cssClass: 'delete-confirm-alert',
|
|
|
+ buttons: [
|
|
|
+ {
|
|
|
+ text: '取消',
|
|
|
+ role: 'cancel',
|
|
|
+ cssClass: 'cancel-btn'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: '删除',
|
|
|
+ cssClass: 'delete-btn',
|
|
|
+ handler: () => {
|
|
|
+ this.deletePlan(plan);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ });
|
|
|
+
|
|
|
+ await alert.present();
|
|
|
+ }
|
|
|
+
|
|
|
+ async deletePlan(plan: any) {
|
|
|
+ try {
|
|
|
+ // 创建CloudObject实例
|
|
|
+ const planObj = new CloudObject('TrainingPlan');
|
|
|
+ planObj.id = plan.id;
|
|
|
+
|
|
|
+ // 显示加载状态
|
|
|
+ const loadingAlert = await this.alertCtrl.create({
|
|
|
+ message: '正在删除计划...',
|
|
|
+ backdropDismiss: false,
|
|
|
+ cssClass: 'deleting-alert'
|
|
|
+ });
|
|
|
+ await loadingAlert.present();
|
|
|
+
|
|
|
+ // 调用destroy方法删除计划
|
|
|
+ const success = await planObj.destroy();
|
|
|
+
|
|
|
+ // 关闭加载提示
|
|
|
+ await loadingAlert.dismiss();
|
|
|
+
|
|
|
+ if (success) {
|
|
|
+ // 更新前端列表
|
|
|
+ this.myPlans = this.myPlans.filter(p => p.id !== plan.id);
|
|
|
+
|
|
|
+ // 使用 Toast 显示成功消息(支持 duration)
|
|
|
+ const toast = await this.toastCtrl.create({
|
|
|
+ message: '计划已成功删除!',
|
|
|
+ duration: 2000,
|
|
|
+ cssClass: 'delete-success-toast',
|
|
|
+ position: 'top'
|
|
|
+ });
|
|
|
+ await toast.present();
|
|
|
+ } else {
|
|
|
+ throw new Error('删除失败');
|
|
|
+ }
|
|
|
+ } catch (error: any) {
|
|
|
+ console.error('删除计划时出错:', error);
|
|
|
+
|
|
|
+ // 显示错误提示
|
|
|
+ const errorAlert = await this.alertCtrl.create({
|
|
|
+ header: '删除失败',
|
|
|
+ message: error.message || '计划删除失败,请稍后重试',
|
|
|
+ buttons: ['确定'],
|
|
|
+ cssClass: 'delete-error-alert'
|
|
|
+ });
|
|
|
+ await errorAlert.present();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async loadPlanTasks(planId: string) {
|
|
|
const query = new CloudQuery('TrainingTask');
|
|
|
query.equalTo('plan', planId);
|