|
@@ -4,7 +4,7 @@ import { addIcons } from 'ionicons';
|
|
import { checkmarkCircle, infiniteOutline, alertCircleOutline, bicycleOutline, logoGitlab, trash, calendar, helpCircle, create } from 'ionicons/icons';
|
|
import { checkmarkCircle, infiniteOutline, alertCircleOutline, bicycleOutline, logoGitlab, trash, calendar, helpCircle, create } from 'ionicons/icons';
|
|
import { CommonModule } from '@angular/common';
|
|
import { CommonModule } from '@angular/common';
|
|
import { FormsModule } from '@angular/forms';
|
|
import { FormsModule } from '@angular/forms';
|
|
-import { IonSelect, IonThumbnail, IonCardSubtitle, IonImg, IonCard, IonButtons, IonItem, IonList, IonHeader, IonIcon, IonToolbar, IonContent, IonSegment, IonSegmentButton, IonGrid, IonRow, IonCol, IonButton, IonLabel, IonBadge, IonInput, ModalController, IonCardTitle, IonCardContent, IonCardHeader, IonSelectOption } from '@ionic/angular/standalone';
|
|
|
|
|
|
+import { IonDatetime, IonSelect, IonThumbnail, IonCardSubtitle, IonImg, IonCard, IonButtons, IonItem, IonList, IonHeader, IonIcon, IonToolbar, IonContent, IonSegment, IonSegmentButton, IonGrid, IonRow, IonCol, IonButton, IonLabel, IonBadge, IonInput, ModalController, IonCardTitle, IonCardContent, IonCardHeader, IonSelectOption } from '@ionic/angular/standalone';
|
|
import { FmodeChatCompletion, ImagineWork, DalleOptions, ChatPanelOptions, FmodeChat, FmodeChatMessage, MarkdownPreviewModule, openChatPanelModal } from "fmode-ng";
|
|
import { FmodeChatCompletion, ImagineWork, DalleOptions, ChatPanelOptions, FmodeChat, FmodeChatMessage, MarkdownPreviewModule, openChatPanelModal } from "fmode-ng";
|
|
import { AgentTaskStep } from './agent/agent.task';
|
|
import { AgentTaskStep } from './agent/agent.task';
|
|
import { TaskPoemPictureDesc } from './agent/tasks/poem/poem-desc';
|
|
import { TaskPoemPictureDesc } from './agent/tasks/poem/poem-desc';
|
|
@@ -51,20 +51,26 @@ import { openUserLoginModal } from 'src/lib/user/modal-user-login/modal-user-log
|
|
IonButton,
|
|
IonButton,
|
|
IonLabel,
|
|
IonLabel,
|
|
IonBadge,
|
|
IonBadge,
|
|
- IonInput
|
|
|
|
|
|
+ IonInput,
|
|
|
|
+ IonDatetime
|
|
]
|
|
]
|
|
})
|
|
})
|
|
export class Tab2Page implements OnInit {
|
|
export class Tab2Page implements OnInit {
|
|
selectedTab: string = 'checkin'; // 默认选中的tab
|
|
selectedTab: string = 'checkin'; // 默认选中的tab
|
|
- planList: any[] = [
|
|
|
|
- ];
|
|
|
|
- coachList: any[] = [
|
|
|
|
- ];
|
|
|
|
|
|
+ planList: any[] = [];
|
|
|
|
+ coachList: any[] = [];
|
|
|
|
+ planUser: any;
|
|
currentUser: CloudUser | undefined
|
|
currentUser: CloudUser | undefined
|
|
constructor(private router: Router, private modalCtrl: ModalController, private cdr: ChangeDetectorRef, private alertController: AlertController) {
|
|
constructor(private router: Router, private modalCtrl: ModalController, private cdr: ChangeDetectorRef, private alertController: AlertController) {
|
|
addIcons({ alertCircleOutline, checkmarkCircle, calendar, helpCircle, trash, create, logoGitlab, bicycleOutline, infiniteOutline });
|
|
addIcons({ alertCircleOutline, checkmarkCircle, calendar, helpCircle, trash, create, logoGitlab, bicycleOutline, infiniteOutline });
|
|
this.currentUser = new CloudUser();
|
|
this.currentUser = new CloudUser();
|
|
}
|
|
}
|
|
|
|
+ ngOnInit() {
|
|
|
|
+ this.loadPlanList()
|
|
|
|
+ this.loadCoachList()
|
|
|
|
+ this.loadPlanUser()
|
|
|
|
+
|
|
|
|
+ }
|
|
async loadPlanList() {
|
|
async loadPlanList() {
|
|
let currentUser = new CloudUser();
|
|
let currentUser = new CloudUser();
|
|
const cloudQuery = new CloudQuery("fitPlan");
|
|
const cloudQuery = new CloudQuery("fitPlan");
|
|
@@ -72,28 +78,113 @@ export class Tab2Page implements OnInit {
|
|
cloudQuery.equalTo("user", currentUser.toPointer());
|
|
cloudQuery.equalTo("user", currentUser.toPointer());
|
|
this.planList = await cloudQuery.find();
|
|
this.planList = await cloudQuery.find();
|
|
console.log(this.planList)
|
|
console.log(this.planList)
|
|
|
|
+ //排序算法
|
|
this.planList.sort((a, b) => {
|
|
this.planList.sort((a, b) => {
|
|
const srcIdA = a.get("srcId").match(/\d+/);
|
|
const srcIdA = a.get("srcId").match(/\d+/);
|
|
const srcIdB = b.get("srcId").match(/\d+/);
|
|
const srcIdB = b.get("srcId").match(/\d+/);
|
|
if (srcIdA && srcIdB) {
|
|
if (srcIdA && srcIdB) {
|
|
const numA = parseInt(srcIdA[0], 10);
|
|
const numA = parseInt(srcIdA[0], 10);
|
|
- console.log(numA)
|
|
|
|
const numB = parseInt(srcIdB[0], 10);
|
|
const numB = parseInt(srcIdB[0], 10);
|
|
return numA - numB;
|
|
return numA - numB;
|
|
}
|
|
}
|
|
return 0;
|
|
return 0;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
async loadCoachList() {
|
|
async loadCoachList() {
|
|
let query = new CloudQuery("Coach");
|
|
let query = new CloudQuery("Coach");
|
|
this.coachList = await query.find();
|
|
this.coachList = await query.find();
|
|
}
|
|
}
|
|
- ngOnInit() {
|
|
|
|
- this.loadPlanList()
|
|
|
|
- this.loadCoachList()
|
|
|
|
|
|
+ async loadPlanUser() {
|
|
|
|
+ let currentUser = new CloudUser();
|
|
|
|
+ const cloudQuery = new CloudQuery("fitUser");
|
|
|
|
+ if (currentUser) {
|
|
|
|
+ cloudQuery.equalTo("user", currentUser.toPointer());
|
|
|
|
+ this.planUser = await cloudQuery.find();
|
|
|
|
+ console.log(this.planUser);
|
|
|
|
+
|
|
|
|
+ // 假设从数据库加载已打卡的日期列表
|
|
|
|
+ const checkedDays = this.planUser[0].checkeddays || [];
|
|
|
|
+ checkedDays.forEach((date: string) => {
|
|
|
|
+ this.checkInHistory.add(date); // 加载已打卡日期到 checkInHistory
|
|
|
|
+ });
|
|
|
|
+ console.log(this.checkInHistory)
|
|
|
|
+ this.days = this.planUser[0].days; // 获取已打卡天数
|
|
|
|
+ this.consecutiveDays = this.planUser[0].sucdays; // 获取连续打卡天数
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ selectedDate: Date = new Date();
|
|
|
|
+ days: number = 0; // 总打卡天数
|
|
|
|
+ consecutiveDays: number = 0; // 连续打卡天数
|
|
|
|
+ checkInHistory: Set<string> = new Set(); // 已打卡日期集合
|
|
|
|
+ //打卡页面
|
|
|
|
+ getEncouragement(bmi: number): string {
|
|
|
|
+ if (bmi < 18.5) {
|
|
|
|
+ return '您的BMI偏低,注意保持健康的饮食哦!(๑•́ ₃ •̀๑)';
|
|
|
|
+ } else if (bmi >= 18.5 && bmi < 24.9) {
|
|
|
|
+ return '您的BMI在正常范围,继续保持良好的生活方式!(。♥‿♥。)';
|
|
|
|
+ } else if (bmi >= 25 && bmi < 29.9) {
|
|
|
|
+ return '您的BMI稍微偏高,可以增加运动,控制饮食!(≧◡≦)';
|
|
|
|
+ } else {
|
|
|
|
+ return '您的BMI较高,建议积极锻炼,控制体重!(。•́︿•̀。)';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 计算连续打卡天数
|
|
|
|
+ calculateConsecutiveDays() {
|
|
|
|
+ let currentDate = new Date();
|
|
|
|
+ let count = 0;
|
|
|
|
+ for (let i = 0; i < 30; i++) {
|
|
|
|
+ let date = new Date(currentDate);
|
|
|
|
+ date.setDate(date.getDate() - i);
|
|
|
|
+ let formattedDate = this.formatDate(date);
|
|
|
|
+ if (this.checkInHistory.has(formattedDate)) {
|
|
|
|
+ count++;
|
|
|
|
+ } else {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ this.consecutiveDays = count;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ formatDate(date: Date): string {
|
|
|
|
+ return date.toISOString().split('T')[0];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async markAttendance() {
|
|
|
|
+ const currentDate = new Date();
|
|
|
|
+ const formattedDate = this.formatDate(currentDate);
|
|
|
|
+ if (!this.checkInHistory.has(formattedDate)) {
|
|
|
|
+ this.checkInHistory.add(formattedDate);
|
|
|
|
+ this.days = this.checkInHistory.size; // 更新总打卡天数
|
|
|
|
+ this.calculateConsecutiveDays(); // 更新连续打卡天数
|
|
|
|
+ // 获取当前用户数据并更新 checkeddays 字段
|
|
|
|
+ let currentUser = new CloudUser();
|
|
|
|
+ const cloudQuery = new CloudQuery("fitUser");
|
|
|
|
+ cloudQuery.equalTo("user", currentUser.toPointer());
|
|
|
|
+ const userData = await cloudQuery.find();
|
|
|
|
+ if (userData.length > 0) {
|
|
|
|
+ const user = userData[0];
|
|
|
|
+ let checkedDays = user.checkeddays || [];
|
|
|
|
+ checkedDays.push(formattedDate); // 添加新的打卡日期
|
|
|
|
+
|
|
|
|
+ // 更新数据库中的 checkeddays 字段
|
|
|
|
+ user.set({ "checkeddays": checkedDays });
|
|
|
|
+ user.set({ "days": this.days }); // 更新已打卡天数
|
|
|
|
+ user.set({ "sucdays": this.consecutiveDays }); // 更新连续打卡天数
|
|
|
|
+ await user.save();
|
|
|
|
+ this.loadPlanUser()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 处理日期变更
|
|
|
|
+ onDateChange(event: any) {
|
|
|
|
+ this.selectedDate = event.detail.value;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
async login() {
|
|
async login() {
|
|
let user = await openUserLoginModal(this.modalCtrl);
|
|
let user = await openUserLoginModal(this.modalCtrl);
|
|
if (user?.id) {
|
|
if (user?.id) {
|