|
@@ -1,6 +1,6 @@
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { Component, OnInit } from '@angular/core';
|
|
-import { CloudObject, CloudQuery } from 'src/lib/ncloud';
|
|
|
|
-//import { ParseService } from '../../services/parse.service';
|
|
|
|
|
|
+import { CloudObject, CloudQuery,CloudUser } from 'src/lib/ncloud';
|
|
|
|
+import { AlertController } from '@ionic/angular';
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
selector: 'app-thanks-cloud',
|
|
selector: 'app-thanks-cloud',
|
|
@@ -12,141 +12,204 @@ export class ThanksCloudPage implements OnInit {
|
|
|
|
|
|
constructor(
|
|
constructor(
|
|
//private parseService: ParseService
|
|
//private parseService: ParseService
|
|
|
|
+ private alertController: AlertController
|
|
) {
|
|
) {
|
|
- this.loadThanksType()
|
|
|
|
|
|
+ this.checkLoginAndLoadData();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ currentUser: CloudUser | null = null;
|
|
thanksList: CloudObject[]=[];
|
|
thanksList: CloudObject[]=[];
|
|
|
|
+
|
|
async loadThanksType(){
|
|
async loadThanksType(){
|
|
|
|
|
|
- //修改前
|
|
|
|
let query=new CloudQuery("ThanksType")
|
|
let query=new CloudQuery("ThanksType")
|
|
this.thanksList=await query.find();
|
|
this.thanksList=await query.find();
|
|
- //修改后
|
|
|
|
- //this.parseService.fetchThanksList();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
ngOnInit() {
|
|
ngOnInit() {
|
|
- this.loadThanksType()
|
|
|
|
- this.thanksList=[];
|
|
|
|
|
|
+ //this.checkLoginAndLoadData();
|
|
}
|
|
}
|
|
- async importThanks(){
|
|
|
|
- const thanksDataset = [
|
|
|
|
- {
|
|
|
|
- Tid: 1,
|
|
|
|
- date: 17,
|
|
|
|
- weekday: "周五",
|
|
|
|
- time: "07:15",
|
|
|
|
- content: "清晨被窗外的鸟鸣唤醒,发现室友已经煮好了咖啡。阳光透过窗帘的缝隙在地板上画出一道金线,突然觉得平凡的生活里藏着好多温柔。",
|
|
|
|
- weather: "晴",
|
|
|
|
- mood: "☕️",
|
|
|
|
- tags:["情感分析","行动计划"],
|
|
|
|
- reflection: "原来幸福可以这么简单,明天我要早起为室友做早餐",
|
|
|
|
- actionStep: "记录3个晨间值得感恩的细节",
|
|
|
|
- emotionalImpact: "安全感+2 | 社会联结感+1",
|
|
|
|
- emotionalJournal: "安静→温暖→感恩的情绪流动"
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- Tid: 2,
|
|
|
|
- date: 18,
|
|
|
|
- weekday: "周六",
|
|
|
|
- time: "14:30",
|
|
|
|
- content: "去菜市场买了把新鲜的小雏菊,回家插在旧玻璃瓶里。路过的邻居夸花好看,还分享了她的插花技巧,平凡的午后变得格外明亮。",
|
|
|
|
- weather: "多云",
|
|
|
|
- mood: "🌼",
|
|
|
|
- tags:["情感分析","生活仪式感"],
|
|
|
|
- reflection: "生活中的小美好,往往藏在与他人的善意互动里,以后要多和邻居交流",
|
|
|
|
- actionStep: "每周尝试一种新的鲜花装饰房间",
|
|
|
|
- emotionalImpact: "愉悦感 + 3 | 归属感 + 1",
|
|
|
|
- emotionalJournal: "平淡→惊喜→满足的情绪转变"
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- Tid: 3,
|
|
|
|
- date: 19,
|
|
|
|
- weekday: "周日",
|
|
|
|
- time: "19:45",
|
|
|
|
- content: "加班到很晚,疲惫地走出公司,发现地铁站口的流浪歌手在唱我喜欢的歌。驻足听了一会儿,歌声好像驱散了所有的劳累。",
|
|
|
|
- weather: "阴",
|
|
|
|
- mood: "🎵",
|
|
|
|
- tags:["情感分析","自我疗愈"],
|
|
|
|
- reflection: "音乐真的有治愈人心的力量,以后要多给自己留一些听音乐的时间",
|
|
|
|
- actionStep: "整理一份专属治愈歌单",
|
|
|
|
- emotionalImpact: "压力缓解 + 3 | 平静感 + 2",
|
|
|
|
- emotionalJournal: "疲惫→舒缓→放松的情绪过渡"
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- Tid: 4,
|
|
|
|
- date: 20,
|
|
|
|
- weekday: "周一",
|
|
|
|
- time: "12:10",
|
|
|
|
- content: "午餐时和同事拼桌,聊到小时候的趣事,大家笑得前仰后合。原来一顿简单的午饭,也能成为拉近彼此距离的桥梁。",
|
|
|
|
- weather: "晴",
|
|
|
|
- mood: "😄",
|
|
|
|
- tags:["情感分析","职场社交"],
|
|
|
|
- reflection: "工作之余的轻松交流很重要,以后要多参与同事间的互动",
|
|
|
|
- actionStep: "主动发起一次同事间的午餐聚会",
|
|
|
|
- emotionalImpact: "幸福感 + 2 | 团队融入感 + 2",
|
|
|
|
- emotionalJournal: "平淡→欢乐→温暖的情绪变化"
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- Tid: 5,
|
|
|
|
- date: 21,
|
|
|
|
- weekday: "周二",
|
|
|
|
- time: "21:30",
|
|
|
|
- content: "下雨天忘记带伞,正发愁时,一位陌生的阿姨撑着伞邀请我共行。短短一段路,却让我感受到陌生人的善意如此珍贵。",
|
|
|
|
- weather: "雨",
|
|
|
|
- mood: "🌧️→☀️",
|
|
|
|
- tags:["情感分析","陌生人善意"],
|
|
|
|
- reflection: "原来善意可以传递,下次遇到他人有困难,我也要主动帮忙",
|
|
|
|
- actionStep: "本周内为一位陌生人提供一次帮助",
|
|
|
|
- emotionalImpact: "感动 + 3 | 对世界的信任感 + 2",
|
|
|
|
- emotionalJournal: "焦虑→惊喜→温暖的情绪起伏"
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- Tid: 6,
|
|
|
|
- date: 22,
|
|
|
|
- weekday: "周三",
|
|
|
|
- time: "08:20",
|
|
|
|
- content: "晨跑时发现小区里的石榴树结了小果子,嫩绿的叶片间藏着星星点点的生机。突然觉得,只要用心观察,处处都是生命的奇迹。",
|
|
|
|
- weather: "晴",
|
|
|
|
- mood: "🌱",
|
|
|
|
- tags:["情感分析","自然观察"],
|
|
|
|
- reflection: "生活需要放慢脚步,多留意身边的美好",
|
|
|
|
- actionStep: "每天记录一个自然观察小发现",
|
|
|
|
- emotionalImpact: "愉悦感 + 2 | 对生活的热爱 + 2",
|
|
|
|
- emotionalJournal: "平常→惊喜→热爱的情绪流动"
|
|
|
|
- }
|
|
|
|
- ];
|
|
|
|
- const ThanksType=new CloudObject("ThanksType");
|
|
|
|
- const query=new CloudQuery("ThanksType");
|
|
|
|
|
|
|
|
- for(const thanks of thanksDataset){
|
|
|
|
- try{
|
|
|
|
- const query=new CloudQuery("ThanksType");
|
|
|
|
- //检查是否已存在相同内容
|
|
|
|
- query.equalTo("Tid",thanks.Tid);
|
|
|
|
- const existing=await query.first();
|
|
|
|
|
|
+ async checkLoginAndLoadData() {
|
|
|
|
+ // 获取当前用户
|
|
|
|
+ this.currentUser = await CloudUser.current();
|
|
|
|
+ if (this.currentUser) {
|
|
|
|
+ await this.loadThanksList();
|
|
|
|
+ } else {
|
|
|
|
+ // 如果用户未登录,可以跳转到登录页面或显示登录提示
|
|
|
|
+ console.warn('用户未登录');
|
|
|
|
+ this.showLoginAlert();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- if(existing){
|
|
|
|
- console.log(`清单${thanks.content}"已存在,保存跳过`);
|
|
|
|
- continue;
|
|
|
|
|
|
+ async showLoginAlert() {
|
|
|
|
+ const alert = await this.alertController.create({
|
|
|
|
+ header: '未登录',
|
|
|
|
+ message: '请先登录才能查看和创建感恩清单',
|
|
|
|
+ buttons: [
|
|
|
|
+ {
|
|
|
|
+ text: '取消',
|
|
|
|
+ role: 'cancel'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ text: '去登录',
|
|
|
|
+ handler: () => {
|
|
|
|
+ // 这里可以导航到登录页面
|
|
|
|
+ // this.router.navigate(['/login']);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- //创建新感恩清单
|
|
|
|
- const newThanks=new CloudObject("ThanksType");
|
|
|
|
- newThanks.set(thanks);
|
|
|
|
- //保存到数据库
|
|
|
|
- await newThanks.save();
|
|
|
|
- console.log(`清单${thanks.content}保存成功`);
|
|
|
|
- }catch(error){
|
|
|
|
- console.error(`保存清单${thanks.content}时出错`,error);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- console.log("所有清单数据处理完成");
|
|
|
|
|
|
+ ]
|
|
|
|
+ });
|
|
|
|
+ await alert.present();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async loadThanksList() {
|
|
|
|
+ if (!this.currentUser) return;
|
|
|
|
+
|
|
|
|
+ // 创建查询,只获取当前用户的感恩清单
|
|
|
|
+ let query = new CloudQuery("ThanksType");
|
|
|
|
+ query.equalTo("user", {
|
|
|
|
+ __type: "Pointer",
|
|
|
|
+ className: "_User",
|
|
|
|
+ objectId: this.currentUser.id
|
|
|
|
+ });
|
|
|
|
+ query.include("user"); // 包含用户信息
|
|
|
|
+
|
|
|
|
+ this.thanksList = await query.find();
|
|
}
|
|
}
|
|
|
|
|
|
- addNewThanks(){
|
|
|
|
- console.log("添加清单")
|
|
|
|
|
|
+ async importThanks(){
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ async addNewThanks(){
|
|
|
|
+
|
|
|
|
+ if (!this.currentUser) {
|
|
|
|
+ this.showLoginAlert();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ const alert = await this.alertController.create({
|
|
|
|
+ header: '添加感恩清单',
|
|
|
|
+ inputs: [
|
|
|
|
+ {
|
|
|
|
+ name: 'content',
|
|
|
|
+ type: 'textarea',
|
|
|
|
+ placeholder: '感恩内容'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ name: 'weather',
|
|
|
|
+ type: 'text',
|
|
|
|
+ placeholder: '天气 (如: 晴)'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ name: 'mood',
|
|
|
|
+ type: 'text',
|
|
|
|
+ placeholder: '心情表情 (如: 😊)'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ name: 'tags',
|
|
|
|
+ type: 'text',
|
|
|
|
+ placeholder: '标签 (用逗号分隔, 如: 情感分析,生活仪式感)'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ name: 'reflection',
|
|
|
|
+ type: 'textarea',
|
|
|
|
+ placeholder: '反思记录'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ name: 'actionStep',
|
|
|
|
+ type: 'textarea',
|
|
|
|
+ placeholder: '行动计划'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ name: 'emotionalImpact',
|
|
|
|
+ type: 'text',
|
|
|
|
+ placeholder: '情感影响 (如: 幸福感 + 2)'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ name: 'emotionalJournal',
|
|
|
|
+ type: 'textarea',
|
|
|
|
+ placeholder: '情绪日记'
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ buttons: [
|
|
|
|
+ {
|
|
|
|
+ text: '取消',
|
|
|
|
+ role: 'cancel',
|
|
|
|
+ handler: () => {
|
|
|
|
+ return true; // 明确返回 true 表示取消操作
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ text: '保存',
|
|
|
|
+ handler: async (data) => {
|
|
|
|
+ if (!data.content) {
|
|
|
|
+ return false; // 阻止关闭
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 获取当前日期时间信息
|
|
|
|
+ const now = new Date();
|
|
|
|
+ const weekday = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][now.getDay()];
|
|
|
|
+ const date = now.getDate();
|
|
|
|
+ const hours = now.getHours().toString().padStart(2, '0');
|
|
|
|
+ const minutes = now.getMinutes().toString().padStart(2, '0');
|
|
|
|
+ const time = `${hours}:${minutes}`;
|
|
|
|
+
|
|
|
|
+ // 处理标签
|
|
|
|
+ const tags = data.tags ? data.tags.split(',').map((tag: string) => tag.trim()) : [];
|
|
|
|
+
|
|
|
|
+ // 创建新的感恩清单对象
|
|
|
|
+ const newThanks = new CloudObject("ThanksType");
|
|
|
|
+ newThanks.set({
|
|
|
|
+ Tid: Date.now(), // 使用时间戳作为临时ID
|
|
|
|
+ date: date,
|
|
|
|
+ weekday: weekday,
|
|
|
|
+ time: time,
|
|
|
|
+ content: data.content,
|
|
|
|
+ weather: data.weather || '晴',
|
|
|
|
+ mood: data.mood || '😊',
|
|
|
|
+ tags: tags,
|
|
|
|
+ reflection: data.reflection || '',
|
|
|
|
+ actionStep: data.actionStep || '',
|
|
|
|
+ emotionalImpact: data.emotionalImpact || '',
|
|
|
|
+ emotionalJournal: data.emotionalJournal || '',
|
|
|
|
+ // 关联当前用户
|
|
|
|
+ user: {
|
|
|
|
+ __type: "Pointer",
|
|
|
|
+ className: "_User",
|
|
|
|
+ objectId: this.currentUser?.id
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ // 保存到数据库
|
|
|
|
+ await newThanks.save();
|
|
|
|
+
|
|
|
|
+ // 重新加载列表
|
|
|
|
+ await this.loadThanksType();
|
|
|
|
+
|
|
|
|
+ // 显示成功提示
|
|
|
|
+ const successAlert = await this.alertController.create({
|
|
|
|
+ header: '成功',
|
|
|
|
+ message: '感恩清单已添加',
|
|
|
|
+ buttons: ['确定']
|
|
|
|
+ });
|
|
|
|
+ await successAlert.present();
|
|
|
|
+
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error('保存失败:', error);
|
|
|
|
+ const errorAlert = await this.alertController.create({
|
|
|
|
+ header: '错误',
|
|
|
|
+ message: '保存失败,请重试',
|
|
|
|
+ buttons: ['确定']
|
|
|
|
+ });
|
|
|
|
+ await errorAlert.present();
|
|
|
|
+ }
|
|
|
|
+ return true; // 明确返回 true 表示操作完成
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ await alert.present();
|
|
|
|
+ }
|
|
}
|
|
}
|