Browse Source

feat:cloud

0225304 4 days ago
parent
commit
f047e0d0cd

+ 0 - 0
myapp/src/app/services/parse.service.ts


+ 2 - 2
myapp/src/app/tab1/test-message/test-message.page.ts

@@ -100,7 +100,7 @@ export class TestMessagePage implements OnInit {
     private locationBack: Location
   ) { 
     this.route.queryParams.subscribe(params=>{
-     console.log(params)
+     //console.log(params)
       //this.message=params
        
     //安全地从参数中提取并转换为Diary类型
@@ -115,7 +115,7 @@ export class TestMessagePage implements OnInit {
       // 添加Diary接口定义的所有必需属性
     };
     
-    console.log('转换后的Diary对象:', this.message);
+    //console.log('转换后的Diary对象:', this.message);
     })
   }
 

+ 25 - 3
myapp/src/app/tab2/tab2.page.ts

@@ -1,5 +1,6 @@
 import { Component } from '@angular/core';
 import { NavController } from '@ionic/angular';
+import { Router } from '@angular/router'; 
 
 @Component({
   selector: 'app-tab2',
@@ -10,10 +11,31 @@ import { NavController } from '@ionic/angular';
 export class Tab2Page {
 
   constructor(
-    private navCtrl:NavController
+    private navCtrl:NavController,
+    private router: Router
   ) {}
 
-  goThankslist(list?:string){
-    this.navCtrl.navigateForward(["tabs","tab2","thanks"])
+  goThankslist(thanks?:string){
+    this.navCtrl.navigateForward(["tabs","tab2","thanks"],{
+      
+    })
   }
+  navigateToDetail() { // 定义一个方法用于导航到详情页面
+    if (this.router.url !== '/detail') { // 检查当前 URL 是否不是目标页面
+      this.router.navigateByUrl('/detail').then(() => { // 如果不是,则导航到详情页面
+        console.log('Navigation completed.'); // 导航完成后打印日志
+      }).catch(error => { // 捕获并处理可能发生的错误
+        console.error('Navigation failed:', error); // 打印错误信息
+      });
+    } else { // 如果已经是目标页面
+      console.warn('Already on the detail page, no need to navigate.'); // 打印警告信息
+    }
+  }
+  // goMessage(message?:any){
+  //   console.log(message),
+  //   this.navCtrl.navigateForward(["tabs","tab1","message"],{
+  //     queryParams:message
+  //   })
+  //   return
+  // }
 }

+ 69 - 8
myapp/src/app/tab2/thanks-cloud/thanks-cloud.page.html

@@ -1,13 +1,74 @@
 <ion-header [translucent]="true">
-  <ion-toolbar>
-    <ion-title>thanks-cloud</ion-title>
+  <ion-toolbar color="primary">
+    <ion-buttons slot="start">
+      <ion-back-button defaultHref="/tabs/tab2"></ion-back-button>
+    </ion-buttons>
+    <ion-title>感恩清单</ion-title>
   </ion-toolbar>
 </ion-header>
 
-<ion-content [fullscreen]="true">
-  <ion-header collapse="condense">
-    <ion-toolbar>
-      <ion-title size="large">thanks-cloud</ion-title>
-    </ion-toolbar>
-  </ion-header>
+<ion-content class="ion-padding" [fullscreen]="true">
+  
+  <div *ngFor="let thanks of thanksList" class="gratitude-container">
+    
+    <!-- 单个感恩卡片 -->
+    <ion-card  class="gratitude-card">
+      <ion-card-header class="card-header">
+        <div class="date-section">
+          <div class="date-number">{{thanks.get('date')}}</div>
+          <div class="date-weekday">{{thanks.get('weekday')}}</div>
+        </div>
+        <div class="time-weather">
+          <div class="time">{{thanks.get('time')}}</div>
+          <div class="weather-mood">
+            <span class="weather">{{thanks.get('weather')}}</span>
+            <span class="mood">{{thanks.get('mood')}}</span>
+          </div>
+        </div>
+      </ion-card-header>
+
+      <ion-card-content class="card-content">
+        <div class="content-text">{{thanks.get('content')}}</div>
+        
+        <div class="tags-section">
+          <ion-chip *ngFor="let tag of thanks.get('tags')" outline color="primary">
+            <ion-label>{{tag}}</ion-label>
+          </ion-chip>
+        </div>
+
+        <ion-accordion-group>
+          <ion-accordion value="reflection">
+            <ion-item slot="header" color="light">
+              <ion-label>反思记录</ion-label>
+            </ion-item>
+            <div slot="content" class="accordion-content">{{thanks.get('reflection')}}</div>
+          </ion-accordion>
+          
+          <ion-accordion value="action">
+            <ion-item slot="header" color="light">
+              <ion-label>行动计划</ion-label>
+            </ion-item>
+            <div slot="content" class="accordion-content">{{thanks.get('actionStep')}}</div>
+          </ion-accordion>
+          
+          <ion-accordion value="impact">
+            <ion-item slot="header" color="light">
+              <ion-label>情感影响</ion-label>
+            </ion-item>
+            <div slot="content" class="accordion-content">{{thanks.get('emotionalImpact')}}</div>
+          </ion-accordion>
+          
+          <ion-accordion value="journal">
+            <ion-item slot="header" color="light">
+              <ion-label>情绪日记</ion-label>
+            </ion-item>
+            <div slot="content" class="accordion-content">{{thanks.get('emotionalJournal')}}</div>
+          </ion-accordion>
+        </ion-accordion-group>
+      </ion-card-content>
+    </ion-card>
+  </div>
+  <button class="import-btn" (click)="importThanks()">
+    导入数据
+  </button>
 </ion-content>

+ 180 - 0
myapp/src/app/tab2/thanks-cloud/thanks-cloud.page.scss

@@ -0,0 +1,180 @@
+/* thanks-cloud.page.scss */
+
+.gratitude-container {
+  max-width: 800px;
+  margin: 0 auto;
+  padding-bottom: 20px;
+}
+
+.gratitude-card {
+  margin-bottom: 24px;
+  border-radius: 12px;
+  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
+  transition: transform 0.3s ease, box-shadow 0.3s ease;
+  overflow: hidden;
+  
+  &:hover {
+    transform: translateY(-3px);
+    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
+  }
+}
+
+.card-header {
+  display: flex;
+  align-items: center;
+  padding: 16px;
+  background: linear-gradient(135deg, var(--ion-color-primary) 0%, var(--ion-color-primary-tint) 100%);
+  color: white;
+  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
+}
+
+.date-section {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  margin-right: 16px;
+  min-width: 50px;
+  
+  .date-number {
+    font-size: 28px;
+    font-weight: bold;
+    line-height: 1;
+  }
+  
+  .date-weekday {
+    font-size: 14px;
+    opacity: 0.9;
+    text-transform: uppercase;
+    letter-spacing: 1px;
+  }
+}
+
+.time-weather {
+  flex-grow: 1;
+  
+  .time {
+    font-size: 18px;
+    font-weight: 500;
+    margin-bottom: 4px;
+  }
+  
+  .weather-mood {
+    display: flex;
+    justify-content: space-between;
+    align-items: center;
+    
+    .weather {
+      font-size: 16px;
+      opacity: 0.9;
+    }
+    
+    .mood {
+      font-size: 24px;
+      margin-left: 8px;
+    }
+  }
+}
+
+.card-content {
+  padding: 0;
+  background: var(--ion-color-light);
+  
+  .content-text {
+    padding: 16px;
+    font-size: 16px;
+    line-height: 1.6;
+    color: var(--ion-color-dark);
+    border-bottom: 1px solid var(--ion-color-light-shade);
+    white-space: pre-line;
+  }
+}
+
+.tags-section {
+  padding: 12px 16px;
+  display: flex;
+  flex-wrap: wrap;
+  gap: 8px;
+  border-bottom: 1px solid var(--ion-color-light-shade);
+  
+  ion-chip {
+    --background: transparent;
+    --color: var(--ion-color-primary);
+    --border-color: var(--ion-color-primary-tint);
+    font-size: 12px;
+    height: 24px;
+    
+    ion-label {
+      padding: 0 8px;
+    }
+  }
+}
+
+.accordion-content {
+  padding: 16px;
+  font-size: 14px;
+  line-height: 1.6;
+  color: var(--ion-color-medium);
+  background-color: var(--ion-color-light);
+  white-space: pre-line;
+}
+
+ion-accordion {
+  margin: 0;
+  
+  ion-item {
+    --background: var(--ion-color-light);
+    --background-activated: var(--ion-color-light-shade);
+    --padding-start: 16px;
+    --padding-end: 16px;
+    
+    ion-label {
+      font-size: 14px;
+      font-weight: 500;
+      color: var(--ion-color-primary);
+    }
+  }
+  
+  &[expanded] {
+    ion-item {
+      --background: var(--ion-color-light-shade);
+    }
+  }
+}
+
+/* 响应式调整 */
+@media (max-width: 576px) {
+  .card-header {
+    flex-direction: column;
+    align-items: flex-start;
+    padding: 12px;
+  }
+  
+  .date-section {
+    flex-direction: row;
+    align-items: center;
+    margin-right: 0;
+    margin-bottom: 8px;
+    
+    .date-number {
+      font-size: 24px;
+      margin-right: 8px;
+    }
+    
+    .date-weekday {
+      font-size: 13px;
+    }
+  }
+  
+  .time-weather {
+    width: 100%;
+    
+    .time {
+      font-size: 16px;
+    }
+  }
+  
+  .content-text {
+    font-size: 15px;
+    padding: 12px;
+  }
+}

+ 132 - 1
myapp/src/app/tab2/thanks-cloud/thanks-cloud.page.ts

@@ -1,4 +1,6 @@
 import { Component, OnInit } from '@angular/core';
+import { CloudObject, CloudQuery } from 'src/lib/ncloud';
+//import { ParseService } from '../../services/parse.service';
 
 @Component({
   selector: 'app-thanks-cloud',
@@ -8,9 +10,138 @@ import { Component, OnInit } from '@angular/core';
 })
 export class ThanksCloudPage implements OnInit {
 
-  constructor() { }
+  constructor(
+    //private parseService: ParseService
+  ) { 
+    this.loadThanksType()
+  }
+
+  thanksList: CloudObject[]=[];
+  async loadThanksType(){
+
+    //修改前
+    let query=new CloudQuery("ThanksType")
+    this.thanksList=await query.find();
+    //修改后
+    //this.parseService.fetchThanksList();
+  } 
 
   ngOnInit() {
+    this.loadThanksType()
   }
+  async importThanks(){
+    const thanksDataset = [
+    {
+        id: 1,
+        date: 17,
+        weekday: "周五",
+        time: "07:15",
+        content: "清晨被窗外的鸟鸣唤醒,发现室友已经煮好了咖啡。阳光透过窗帘的缝隙在地板上画出一道金线,突然觉得平凡的生活里藏着好多温柔。",
+        weather: "晴",
+        mood: "☕️",
+        tags:["情感分析","行动计划"],
+        reflection: "原来幸福可以这么简单,明天我要早起为室友做早餐",
+        actionStep: "记录3个晨间值得感恩的细节",
+        emotionalImpact: "安全感+2 | 社会联结感+1",
+        emotionalJournal: "安静→温暖→感恩的情绪流动"
+    },
+    {​
+        id: 2,
+        date: 18,
+        weekday: "周六",
+        time: "14:30",
+        content: "去菜市场买了把新鲜的小雏菊,回家插在旧玻璃瓶里。路过的邻居夸花好看,还分享了她的插花技巧,平凡的午后变得格外明亮。",
+        weather: "多云",
+        mood: "🌼",
+        tags:["情感分析","生活仪式感"],
+        reflection: "生活中的小美好,往往藏在与他人的善意互动里,以后要多和邻居交流",
+        actionStep: "每周尝试一种新的鲜花装饰房间",
+        emotionalImpact: "愉悦感 + 3 | 归属感 + 1",
+        emotionalJournal: "平淡→惊喜→满足的情绪转变"
+    }​,
+    {​
+        id: 3,
+        date: 19,
+        weekday: "周日",
+        time: "19:45",
+        content: "加班到很晚,疲惫地走出公司,发现地铁站口的流浪歌手在唱我喜欢的歌。驻足听了一会儿,歌声好像驱散了所有的劳累。",
+        weather: "阴",
+        mood: "🎵",
+        tags:["情感分析","自我疗愈"],
+        reflection: "音乐真的有治愈人心的力量,以后要多给自己留一些听音乐的时间",
+        actionStep: "整理一份专属治愈歌单",
+        emotionalImpact: "压力缓解 + 3 | 平静感 + 2",
+        emotionalJournal: "疲惫→舒缓→放松的情绪过渡"
+    }​,
+    {​
+        id: 4,
+        date: 20,
+        weekday: "周一",
+        time: "12:10",
+        content: "午餐时和同事拼桌,聊到小时候的趣事,大家笑得前仰后合。原来一顿简单的午饭,也能成为拉近彼此距离的桥梁。",
+        weather: "晴",
+        mood: "😄",
+        tags:["情感分析","职场社交"],
+        reflection: "工作之余的轻松交流很重要,以后要多参与同事间的互动",
+        actionStep: "主动发起一次同事间的午餐聚会",
+        emotionalImpact: "幸福感 + 2 | 团队融入感 + 2",
+        emotionalJournal: "平淡→欢乐→温暖的情绪变化"
+    }​,
+    {​
+        id: 5,
+        date: 21,
+        weekday: "周二",
+        time: "21:30",
+        content: "下雨天忘记带伞,正发愁时,一位陌生的阿姨撑着伞邀请我共行。短短一段路,却让我感受到陌生人的善意如此珍贵。",
+        weather: "雨",
+        mood: "🌧️→☀️",
+        tags:["情感分析","陌生人善意"],
+        reflection: "原来善意可以传递,下次遇到他人有困难,我也要主动帮忙",
+        actionStep: "本周内为一位陌生人提供一次帮助",
+        emotionalImpact: "感动 + 3 | 对世界的信任感 + 2",
+        emotionalJournal: "焦虑→惊喜→温暖的情绪起伏"
+    }​,
+    {​
+        id: 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{
+        //检查是否已存在相同内容
+        query.equalTo("content",thanks.content);
+        const existing=await query.first();
+
+        if(existing){
+          console.log(`清单${thanks.content}"已存在,保存跳过`);
+          continue;
+        }
+        //创建新感恩清单
+        const newThanks=new CloudObject("ThanksType");
+        newThanks.set(thanks);
+        //保存到数据库
+        await newThanks.save();
+        console.log(`清单${thanks.content}保存成功`);
+      }catch(error){
+        console.error(`保存清单${thanks.content}时出错`,error);
+      }
+    }
+    console.log("所有清单数据处理完成");
+  }
+  
+    
+    
 }

+ 1 - 7
myapp/src/app/tab3/tab3.page.ts

@@ -167,13 +167,7 @@ openConsult(chatId?:string){
         }
       },
       onChatSaved:(chat:FmodeChat)=>{
-      
-        // 保存成功后存储chatId
-      // const newChatId = chat?.chatSession?.id;
-      // if(newChatId) {
-      //   this.saveLastChatId(newChatId);
-      // }
-
+       
         // chat?.chatSession?.id 本次会话的 chatId
         console.log("onChatSaved",chat,chat?.chatSession,chat?.chatSession?.id)
       }

+ 14 - 1
myapp/src/app/tabs/tabs-routing.module.ts

@@ -34,7 +34,20 @@ const routes: Routes = [
     path: '',
     redirectTo: '/tabs/tab1',
     pathMatch: 'full'
-  }
+  },
+  // {
+  // path: 'tab2',
+  // children: [
+  //   {
+  //     path: '',
+  //     loadChildren: () => import('../tab2/tab2.module').then(m => m.Tab2PageModule)
+  //   },
+  //   {
+  //       path: 'thanks',
+  //       loadComponent: () => import('../tab2/thanks-cloud/thanks-cloud.page').then(m => m.ThanksCloudPage)
+  //   }
+  // ]
+  // },
 ];
 
 @NgModule({

+ 1 - 1
myapp/src/environments/environment.ts

@@ -3,7 +3,7 @@
 // The list of file replacements can be found in `angular.json`.
 
 export const environment = {
-  production: false
+  production: false,
 };
 
 /*

+ 11 - 11
myapp/src/lib/ncloud.ts

@@ -29,7 +29,7 @@ export class CloudObject {
 
     async save() {
         let method = "POST";
-        let url = `https://dev.fmode.cn/parse/classes/${this.className}`;
+        let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}`;
 
         // 更新
         if (this.id) {
@@ -61,7 +61,7 @@ export class CloudObject {
 
     async destroy() {
         if (!this.id) return;
-        const response = await fetch(`https://dev.fmode.cn/parse/classes/${this.className}/${this.id}`, {
+        const response = await fetch(`http://dev.fmode.cn:1337/parse/classes/${this.className}/${this.id}`, {
             headers: {
                 "x-parse-application-id": "dev"
             },
@@ -117,7 +117,7 @@ export class CloudQuery {
     }
 
     async get(id: string) {
-        const url = `https://dev.fmode.cn/parse/classes/${this.className}/${id}?`;
+        const url = `http://dev.fmode.cn:1337/parse/classes/${this.className}/${id}?`;
 
         const response = await fetch(url, {
             headers: {
@@ -139,7 +139,7 @@ export class CloudQuery {
     }
 
     async find():Promise<Array<CloudObject>> {
-        let url = `https://dev.fmode.cn/parse/classes/${this.className}?`;
+        let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}?`;
 
         let queryStr = ``
         Object.keys(this.queryParams).forEach(key=>{
@@ -176,7 +176,7 @@ export class CloudQuery {
 
 
     async first() {
-        let url = `https://dev.fmode.cn/parse/classes/${this.className}?`;
+        let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}?`;
 
         if (Object.keys(this.queryParams["where"]).length) {
             const whereStr = JSON.stringify(this.queryParams["where"]);
@@ -236,7 +236,7 @@ export class CloudUser extends CloudObject {
             return null;
         }
         return this;
-        // const response = await fetch(`https://dev.fmode.cn/parse/users/me`, {
+        // const response = await fetch(`http://dev.fmode.cn:1337/parse/users/me`, {
         //     headers: {
         //         "x-parse-application-id": "dev",
         //         "x-parse-session-token": this.sessionToken // 使用sessionToken进行身份验证
@@ -254,7 +254,7 @@ export class CloudUser extends CloudObject {
 
     /** 登录 */
     async login(username: string, password: string):Promise<CloudUser|null> {
-        const response = await fetch(`https://dev.fmode.cn/parse/login`, {
+        const response = await fetch(`http://dev.fmode.cn:1337/parse/login`, {
             headers: {
                 "x-parse-application-id": "dev",
                 "Content-Type": "application/json"
@@ -286,7 +286,7 @@ export class CloudUser extends CloudObject {
             return;
         }
 
-        const response = await fetch(`https://dev.fmode.cn/parse/logout`, {
+        const response = await fetch(`http://dev.fmode.cn:1337/parse/logout`, {
             headers: {
                 "x-parse-application-id": "dev",
                 "x-parse-session-token": this.sessionToken
@@ -324,7 +324,7 @@ export class CloudUser extends CloudObject {
             ...additionalData // 合并额外的用户数据
         };
 
-        const response = await fetch(`https://dev.fmode.cn/parse/users`, {
+        const response = await fetch(`http://dev.fmode.cn:1337/parse/users`, {
             headers: {
                 "x-parse-application-id": "dev",
                 "Content-Type": "application/json"
@@ -351,7 +351,7 @@ export class CloudUser extends CloudObject {
 
     override async save() {
         let method = "POST";
-        let url = `https://dev.fmode.cn/parse/users`;
+        let url = `http://dev.fmode.cn:1337/parse/users`;
     
         // 更新用户信息
         if (this.id) {
@@ -409,7 +409,7 @@ export class CloudApi{
             reqOpts.body = JSON.stringify(body || options?.body);
             reqOpts.json = true;
         }
-        let host = `https://dev.fmode.cn`
+        let host = `http://dev.fmode.cn:1337`
         // host = `http://127.0.0.1:1337`
         let url = `${host}/api/`+path
         console.log(url,reqOpts)