Browse Source

fit:diary cloud

0225304 1 day ago
parent
commit
43a1942fe6

+ 1 - 1
docs/schema.md

@@ -11,7 +11,7 @@ Array => JSON Array
 Object => JSON Object
 Date => Date
 File => Parse.File
-Pointer => other Parse.Object
+Pointer => other Parse.Object //指针类型的字段不需要用×××Id形式命名,直接写×××即可,
 Relation => Parse.Relation
 Null => null
 GeoPoint =>{latitude: 40.0, longitude: -30.0}

+ 1 - 0
myapp/src/app/app.component.ts

@@ -8,4 +8,5 @@ import { Component } from '@angular/core';
 })
 export class AppComponent {
   constructor() {}
+
 }

+ 1 - 1
myapp/src/app/login/login.page.ts

@@ -39,7 +39,7 @@ export class LoginPage {
     const success = await this.authService.login(this.username, this.password);
     if (success) {
       this.showToast('登录成功');
-      this.router.navigate(['/tabs/tab1']);
+      this.router.navigate(['/tabs/tab4']);
     } else {
       this.showToast('登录失败,请检查用户名和密码');
     }

+ 56 - 1
myapp/src/app/tab1/edit/edit.page.html

@@ -1,4 +1,4 @@
-<ion-header [translucent]="true">
+<!-- <ion-header [translucent]="true">
   <ion-toolbar>
     <ion-buttons slot="start">
       <ion-button (click)="cancel()">取消</ion-button>
@@ -49,4 +49,59 @@
       class="diary-content"
     ></ion-textarea>
   </div>
+</ion-content> -->
+
+<ion-header>
+  <ion-toolbar>
+    <ion-buttons slot="start">
+      <ion-button (click)="dismiss()">取消</ion-button>
+    </ion-buttons>
+    <ion-title>新建日记</ion-title>
+    <ion-buttons slot="end">
+      <ion-button (click)="saveDiary()" [strong]="true">保存</ion-button>
+    </ion-buttons>
+  </ion-toolbar>
+</ion-header>
+
+<ion-content [fullscreen]="true">
+  <form>
+    <ion-list>
+      <!-- 天气选择(可选) -->
+      <ion-item>
+        <ion-label position="stacked">天气</ion-label>
+        <ion-select [(ngModel)]="diary.weather" name="weather" placeholder="选择天气">
+          <ion-select-option value="晴">晴</ion-select-option>
+          <ion-select-option value="多云">多云</ion-select-option>
+          <ion-select-option value="阴">阴</ion-select-option>
+          <ion-select-option value="雨">雨</ion-select-option>
+          <ion-select-option value="雪">雪</ion-select-option>
+          <ion-select-option value="雾">雾</ion-select-option>
+        </ion-select>
+      </ion-item>
+
+      <!-- 心情选择(可选) -->
+      <ion-item>
+        <ion-label position="stacked">心情</ion-label>
+        <ion-select [(ngModel)]="diary.mood" name="mood" placeholder="选择心情">
+          <ion-select-option value="😊">开心</ion-select-option>
+          <ion-select-option value="😌">平静</ion-select-option>
+          <ion-select-option value="🥰">幸福</ion-select-option>
+          <ion-select-option value="😄">兴奋</ion-select-option>
+          <ion-select-option value="😢">难过</ion-select-option>
+          <ion-select-option value="😠">生气</ion-select-option>
+        </ion-select>
+      </ion-item>
+
+      <!-- 日记内容 -->
+      <ion-item>
+        <ion-textarea
+          [(ngModel)]="diary.content"
+          name="content"
+          placeholder="写下你的日记..."
+          autoGrow="true"
+          rows="10"
+        ></ion-textarea>
+      </ion-item>
+    </ion-list>
+  </form>
 </ion-content>

+ 0 - 42
myapp/src/app/tab1/edit/edit.page.scss

@@ -1,42 +0,0 @@
-.edit-container {
-  padding: 16px;
-  
-  .info-row {
-    display: flex;
-    justify-content: space-between;
-    margin-bottom: 16px;
-    
-    .date-info {
-      display: flex;
-      flex-direction: column;
-      
-      .date {
-        font-size: 24px;
-        font-weight: bold;
-      }
-      
-      .weekday, .time {
-        font-size: 14px;
-        color: var(--ion-color-medium);
-      }
-    }
-    
-    .selectors {
-      width: 60%;
-      
-      ion-item {
-        --padding-start: 0;
-        --inner-padding-end: 0;
-        margin-bottom: 8px;
-      }
-    }
-  }
-  
-  .diary-content {
-    border: 1px solid var(--ion-color-light);
-    border-radius: 8px;
-    padding: 12px;
-    min-height: 200px;
-    font-size: 16px;
-  }
-}

+ 42 - 43
myapp/src/app/tab1/edit/edit.page.ts

@@ -1,7 +1,6 @@
-import { Component, OnInit } from '@angular/core';
-import { ModalController, NavParams } from '@ionic/angular';
-import { DiaryService } from 'src/app/services/diary.service';
-import { Diary } from 'src/app/modals/diary.modal';
+import { Component } from '@angular/core';
+import { ModalController } from '@ionic/angular';
+import { CloudObject } from 'src/lib/ncloud';
 
 @Component({
   selector: 'app-edit',
@@ -9,58 +8,58 @@ import { Diary } from 'src/app/modals/diary.modal';
   styleUrls: ['./edit.page.scss'],
   standalone:false,
 })
-export class EditPage implements OnInit {
-  diary: Diary = {
-    id: 0,
-    date: '',
-    weekday: '',
-    time: '',
+export class EditPage {
+  diary: any = {
+    Did: 0,
+    date: this.getCurrentDate(),
+    weekday: this.getCurrentWeekday(),
+    time: this.getCurrentTime(),
     content: '',
     weather: '',
     mood: ''
   };
-  
-  mode: 'create' | 'edit' = 'create';
 
-  constructor(
-    private modalCtrl: ModalController,
-    private navParams: NavParams,
-    private diaryService: DiaryService
-  ) {}
+  constructor(private modalCtrl: ModalController) {}
 
   ngOnInit() {
-    const currentDate = new Date();
+    // 生成随机ID
+    this.diary.Did = Math.floor(Math.random() * 100000);
+  }
+
+  // 获取当前日期
+  private getCurrentDate(): string {
+    return new Date().getDate().toString();
+  }
+
+  // 获取当前星期
+  private getCurrentWeekday(): string {
     const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
-    
-    // Set default values
-    this.diary.date = currentDate.getDate().toString();
-    this.diary.weekday = weekdays[currentDate.getDay()];
-    this.diary.time = `${currentDate.getHours()}:${currentDate.getMinutes().toString().padStart(2, '0')}`;
-    
-    // Check if we're editing an existing diary
-    const diaryToEdit = this.navParams.get('diary');
-    if (diaryToEdit) {
-      this.diary = { ...diaryToEdit };
-      this.mode = 'edit';
-    }
+    return weekdays[new Date().getDay()];
   }
 
-  async save() {
-    if (this.mode === 'create') {
-      // Generate a new ID (in a real app, this would be handled by a backend)
-      const diaries = await this.diaryService.getDiaries();
-      this.diary.id = diaries.length > 0 ? Math.max(...diaries.map((d: { id: any; }) => d.id)) + 1 : 1;
-      
-      await this.diaryService.addDiary(this.diary);
-    } else {
-      await this.diaryService.updateDiary(this.diary);
-    }
+  // 获取当前时间
+  private getCurrentTime(): string {
+    const now = new Date();
+    return `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}`;
+  }
+
+  async saveDiary() {
+    // 创建新的日记对象
+    const newDiary = new CloudObject("Diary");
+    newDiary.set(this.diary);
     
-    this.modalCtrl.dismiss({ saved: true });
-    console.log("保存成功")
+    try {
+      await newDiary.save();
+      // 保存成功,返回并刷新列表
+      this.modalCtrl.dismiss({ saved: true });
+    } catch (error) {
+      console.error('保存日记失败:', error);
+      this.modalCtrl.dismiss({ saved: false });
+    }
   }
 
-  cancel() {
+  // 关闭模态框
+  dismiss() {
     this.modalCtrl.dismiss({ saved: false });
   }
 }

+ 1 - 1
myapp/src/app/tab1/tab1.module.ts

@@ -9,7 +9,7 @@ import { Tab1PageRoutingModule } from './tab1-routing.module';
 
 @NgModule({
   imports: [
-    IonicModule,
+    IonicModule.forRoot(),
     CommonModule,
     FormsModule,
     ExploreContainerComponentModule,

+ 13 - 25
myapp/src/app/tab1/tab1.page.html

@@ -5,18 +5,16 @@
         <ion-button id="menuBtn">
             <ion-icon slot="icon-only" name="menu-outline"></ion-icon>
         </ion-button>
-        </ion-buttons>
-        
-        <div class="header-title">日记本</div>
-        
+        </ion-buttons> 
+        <div class="header-title">日记本</div> 
         <ion-buttons slot="end">
-        <ion-fab-button (click)="goToEditPage('编辑')" size="small">
+        <ion-button (click)="goToEditPage('编辑')">
             <ion-icon name="add"></ion-icon>
-        </ion-fab-button>
-         <ion-button (click)="logout('登出')">
-            <ion-icon slot="icon-only" name="log-out-outline"></ion-icon>
         </ion-button>
-        </ion-buttons>
+        <ion-button (click)="importDiary()">
+        <ion-icon name="cloud-outline"></ion-icon>
+        </ion-button>
+    </ion-buttons>
     </div>
 
 </ion-header>
@@ -25,27 +23,17 @@
     
     <!-- 内容区域 -->
     <div class="content" id="diaryList">
-         @for(diary of diaries;track diary.id){
+         @for(diary of diaryList;track diary.get('Did')){
         <!-- 日记卡片1 -->
         <div class="diary-card" (click)="goMessage(diary)">
             <div class="diary-time">
-                <div class="diary-date">{{diary.date}}</div>
-                <div class="diary-week">{{diary.weekday}}</div>
-                <div class="diary-hour">{{diary.time}}</div>
+                <div class="diary-date">{{diary.get('date')}}</div>
+                <div class="diary-week">{{diary.get('weekday')}}</div>
+                <div class="diary-hour">{{diary.get('time')}}</div>
             </div>
             <div class="diary-content">
-                {{diary.content}}
-            </div>
-            <!-- @if(diary.weather || diary.mood) {
-            <div class="diary-meta">
-                @if(diary.weather) {
-                <span class="weather">{{diary.weather}}</span>
-                }
-                @if(diary.mood) {
-                <span class="mood">{{diary.mood}}</span>
-                }
-            </div>
-            } -->
+                {{diary.get('content')}}
+            </div> 
         </div>
         } @empty {
         <div class="empty-state">

+ 1 - 1
myapp/src/app/tab1/tab1.page.scss

@@ -39,7 +39,7 @@ body {
         gap: 8px;
     }
     
-    ion-fab-button {
+    ion-button {
         --box-shadow: none;
         margin-left: 8px;
     }

+ 149 - 88
myapp/src/app/tab1/tab1.page.ts

@@ -1,7 +1,5 @@
 import { Component, OnInit } from '@angular/core';
 import { NavController } from '@ionic/angular';
-//import { addIcons } from 'ionicons';
-//import { add } from 'ionicons/icons';
 import { AuthService } from '../services/auth.service';
 import { Router } from '@angular/router';
 import { ModalController } from '@ionic/angular';
@@ -9,7 +7,8 @@ import { EditPage } from './edit/edit.page';
 import { DiaryService } from '../services/diary.service';
 import { Diary } from '../modals/diary.modal';
 import { TestMessagePage } from './test-message/test-message.page';
- 
+
+import { CloudObject, CloudQuery } from 'src/lib/ncloud';
 @Component({
   selector: 'app-tab1',
   templateUrl: 'tab1.page.html',
@@ -18,100 +17,34 @@ import { TestMessagePage } from './test-message/test-message.page';
 })
 export class Tab1Page implements OnInit{
   
-  
-  diaries: Diary[] = [];
+  //diaries: Diary[] = [];
   router: any;
   authService: any;
 
   constructor(
     private modalCtrl: ModalController,
-    private diaryService: DiaryService,
+    //private diaryService: DiaryService,
     private navCtrl: NavController,
     //private router: Router
-  ) {}
-
-  async ngOnInit() {
-    await this.loadDiaries();
+  ) {
+    this.loadDiaries();
   }
- 
 
+  diaryList: CloudObject[]=[];
   async loadDiaries() {
-    this.diaries = await this.diaryService.getDiaries();
-    // Sort by date (newest first)
-    this.diaries.sort((a, b) => {
-      return new Date(b.date).getTime() - new Date(a.date).getTime();
-    });
-  }
-
-  async goToEditPage(edit?:string) {
-    const modal = await this.modalCtrl.create({
-      component: EditPage,
-      componentProps: {
-        mode: 'create'
-      }
-    });
-    
-    modal.onDidDismiss().then(async (result) => {
-      if (result.data?.saved) {
-        await this.loadDiaries(); // Refresh the list
-      }
-    });
-    
-    await modal.present();
-  }
-
-  // async viewDiary(diary: Diary) {
-  //   const modal = await this.modalCtrl.create({
-  //     component: EditPage,
-  //     componentProps: {
-  //       diary: diary,
-  //       mode: 'edit'
-  //     }
-  //   });
-    
-  //   modal.onDidDismiss().then(async (result) => {
-  //     if (result.data?.saved) {
-  //       await this.loadDiaries(); // Refresh the list
-  //     }
-  //   });
-    
-  //   await modal.present();
-  // }
+    let query=new CloudQuery("Diary")
+    this.diaryList=await query.find();
 
-  // tab1.page.ts
-  async viewDiary(diary: Diary) {
-    const modal = await this.modalCtrl.create({
-      component: TestMessagePage, // 确保使用正确的详情页面组件
-      componentProps: {
-        message: diary
-      }
-    });
-    
-    modal.onDidDismiss().then(async (result) => {
-      if (result.data?.deleted) {
-        await this.loadDiaries(); // 刷新列表
-      }
-    });
-    
-    await modal.present();
   }
 
-  async logout(login?:string) {
-    await this.authService.logout();
-    this.router.navigate(['/login']);
+  ngOnInit() {
+    this.diaryList=[];
   }
 
-  goMessage(message?:any){
-    console.log(message),
-    this.navCtrl.navigateForward(["tabs","tab1","message"],{
-      queryParams:message
-    })
-    return
-  }
-
-    messageList:any[]=[
+   async importDiary(){
+    const diaryDataset=[
   {
-    "id": 1,
+    "Did": 1,
     "date": "15",
     "weekday": "周三",
     "time": "14:30",
@@ -120,7 +53,7 @@ export class Tab1Page implements OnInit{
     "mood": "😊"
   },
   {
-    "id": 2,
+    "Did": 2,
     "date": "14",
     "weekday": "周二",
     "time": "21:15",
@@ -129,7 +62,7 @@ export class Tab1Page implements OnInit{
     "mood": "😌"
   },
   {
-    "id": 3,
+    "Did": 3,
     "date": "12",
     "weekday": "周日",
     "time": "09:45",
@@ -138,7 +71,7 @@ export class Tab1Page implements OnInit{
     "mood": "🥰"
   },
   {
-    "id": 4,
+    "Did": 4,
     "date": "18",
     "weekday": "周五",
     "time": "18:20",
@@ -147,7 +80,7 @@ export class Tab1Page implements OnInit{
     "mood": "😄"
   },
   {
-    "id": 5,
+    "Did": 5,
     "date": "20",
     "weekday": "周六",
     "time": "15:10",
@@ -156,7 +89,7 @@ export class Tab1Page implements OnInit{
     "mood": "😺"
   },
   {
-    "id": 6,
+    "Did": 6,
     "date": "22",
     "weekday": "周一",
     "time": "08:05",
@@ -165,7 +98,7 @@ export class Tab1Page implements OnInit{
     "mood": "🌼"
   },
   {
-    "id": 7,
+    "Did": 7,
     "date": "25",
     "weekday": "周四",
     "time": "19:40",
@@ -174,7 +107,7 @@ export class Tab1Page implements OnInit{
     "mood": "🍂"
   },
   {
-    "id": 8,
+    "Did": 8,
     "date": "28",
     "weekday": "周日",
     "time": "22:30",
@@ -183,4 +116,132 @@ export class Tab1Page implements OnInit{
     "mood": "📖"
   }
   ]; 
+    const Diary=new CloudObject("Diary");
+    const query=new CloudQuery("Diary");
+
+    for(const diary of diaryDataset){
+      try{
+        const query=new CloudQuery("Diary");
+        //检查是否已存在相同内容
+        query.equalTo("Did",diary.Did);
+        const existing=await query.first();
+
+        if(existing){
+          console.log(`清单${diary.content}"已存在,保存跳过`);
+          continue;
+        }
+        //创建新日记
+        const newThanks=new CloudObject("Diary");
+        newThanks.set(diary);
+        //保存到数据库
+        await newThanks.save();
+        console.log(`日记${diary.content}保存成功`);
+      }catch(error){
+        console.error(`保存日记${diary.content}时出错`,error);
+      }
+    }
+    console.log("所有日记数据处理完成");
+  }
+
+  async goToEditPage(edit?:string) {
+    const modal = await this.modalCtrl.create({
+    component: EditPage,
+    componentProps: {
+      editMode: edit === '编辑'
+    }
+  });
+  
+  // 模态框关闭后的处理
+  modal.onDidDismiss().then((result) => {
+    if (result.data?.saved) {
+      this.loadDiaries(); // 保存成功后刷新日记列表
+    }
+  });
+  
+  await modal.present();
+  }
+ 
+  goMessage(diary: CloudObject){
+    //console.log(diary),
+    this.navCtrl.navigateForward(['tabs', 'tab1', 'message'], {
+    queryParams: { Did: diary.get('Did') }
+  });
+  }
+
+  
+
+  //   messageList:any[]=[
+  // {
+  //   "id": 1,
+  //   "date": "15",
+  //   "weekday": "周三",
+  //   "time": "14:30",
+  //   "content": "今天阳光明媚,去公园散步时看到樱花开了。粉色的花瓣随风飘落,美得像一幅画。坐在长椅上读了一会儿书,感觉心情特别平静。",
+  //   "weather": "晴",
+  //   "mood": "😊"
+  // },
+  // {
+  //   "id": 2,
+  //   "date": "14",
+  //   "weekday": "周二",
+  //   "time": "21:15",
+  //   "content": "项目终于告一段落,加班到很晚但很有成就感。回家的路上买了杯热奶茶犒劳自己,发现常去的那家奶茶店换了新包装,杯子上画着可爱的小兔子。",
+  //   "weather": "多云",
+  //   "mood": "😌"
+  // },
+  // {
+  //   "id": 3,
+  //   "date": "12",
+  //   "weekday": "周日",
+  //   "time": "09:45",
+  //   "content": "周末尝试做了新的菜谱 - 番茄牛腩。虽然炖的时间比预期长,但结果非常美味!下午窝在沙发上看了一部老电影,窗外下着小雨,这种慵懒的周末真是太棒了。",
+  //   "weather": "小雨",
+  //   "mood": "🥰"
+  // },
+  // {
+  //   "id": 4,
+  //   "date": "18",
+  //   "weekday": "周五",
+  //   "time": "18:20",
+  //   "content": "参加了公司的团队建设活动,第一次体验了攀岩项目。虽然爬到一半有些害怕,但在同事的鼓励下成功登顶,突破自我的感觉真好!",
+  //   "weather": "阴",
+  //   "mood": "😄"
+  // },
+  // {
+  //   "id": 5,
+  //   "date": "20",
+  //   "weekday": "周六",
+  //   "time": "15:10",
+  //   "content": "和朋友去了新开的猫咖,有十几只不同品种的猫咪。最喜欢那只胖乎乎的橘猫,它居然在我腿上睡了一下午,治愈了连日的疲惫。",
+  //   "weather": "晴",
+  //   "mood": "😺"
+  // },
+  // {
+  //   "id": 6,
+  //   "date": "22",
+  //   "weekday": "周一",
+  //   "time": "08:05",
+  //   "content": "早起晨跑时发现小区里的桂花开了,空气里都是甜甜的香气。顺手拍了张晨光中的花枝,设为手机壁纸后整天都有好心情。",
+  //   "weather": "雾",
+  //   "mood": "🌼"
+  // },
+  // {
+  //   "id": 7,
+  //   "date": "25",
+  //   "weekday": "周四",
+  //   "time": "19:40",
+  //   "content": "下班路上遇到卖糖炒栗子的小摊,热乎乎的栗子捧在手里,边走边吃仿佛回到学生时代。突然想念大学的林荫道和图书馆了。",
+  //   "weather": "微风",
+  //   "mood": "🍂"
+  // },
+  // {
+  //   "id": 8,
+  //   "date": "28",
+  //   "weekday": "周日",
+  //   "time": "22:30",
+  //   "content": "整理旧物时发现了高中时期的同学录,翻看那些青涩的留言和夸张的贴纸,忍不住笑出声。那些以为忘记的回忆突然都鲜活起来。",
+  //   "weather": "晴",
+  //   "mood": "📖"
+  // }
+  // ]; 
 }

+ 9 - 10
myapp/src/app/tab1/test-message/test-message.page.html

@@ -17,45 +17,44 @@
   <div class="diary-header">
     <div class="date-section">
       <ion-text color="primary">
-        <h1 class="date">{{ message.date }}</h1>
+        <h1 class="date">{{ diary?.get('date') }}</h1>
       </ion-text>
       <div class="week-time">
         <ion-chip color="light">
           <ion-icon name="calendar-outline"></ion-icon>
-          <ion-label>{{ message.weekday }}</ion-label>
+          <ion-label>{{ diary?.get('weekday') }}</ion-label>
         </ion-chip>
         <ion-chip color="light">
           <ion-icon name="time-outline"></ion-icon>
-          <ion-label>{{ message.time }}</ion-label>
+          <ion-label>{{ diary?.get('time') }}</ion-label>
         </ion-chip>
       </div>
     </div>
     
     <div class="meta-section">
-      <ion-chip>
+      <ion-chip *ngIf="diary?.get('weather')">
         <ion-icon name="partly-sunny-outline"></ion-icon>
-        <ion-label>{{ message.weather }}</ion-label>
+        <ion-label>{{ diary?.get('weather') }}</ion-label>
       </ion-chip>
-      <ion-chip>
+      <ion-chip *ngIf="diary?.get('mood')">
         <ion-icon name="happy-outline"></ion-icon>
-        <ion-label>{{ message.mood }}</ion-label>
+        <ion-label>{{ diary?.get('mood') }}</ion-label>
       </ion-chip>
     </div>
   </div>
 
-
   <!-- 日记内容 -->
   <ion-card class="content-card">
     <ion-card-content>
       <div class="content-text">
-        {{ message.content }}
+        {{ diary?.get('content') }}
       </div>
     </ion-card-content>
   </ion-card>
 
   <!-- 底部操作栏 -->
   <ion-fab vertical="bottom" horizontal="end" slot="fixed">
-    <ion-fab-button color="danger" (click)="onDelete(message.id)">
+    <ion-fab-button color="danger" (click)="deleteDiary()">
       <ion-icon name="trash-outline"></ion-icon>
     </ion-fab-button>
   </ion-fab>

+ 15 - 32
myapp/src/app/tab1/test-message/test-message.page.scss

@@ -1,16 +1,13 @@
-/* 日记详情页样式 */
 .diary-header {
-  display: flex;
-  justify-content: space-between;
-  align-items: flex-start;
   margin-bottom: 20px;
   
   .date-section {
+    margin-bottom: 10px;
+    
     .date {
-      font-size: 3rem;
+      font-size: 2.5rem;
       font-weight: bold;
       margin: 0;
-      line-height: 1;
     }
     
     .week-time {
@@ -22,41 +19,27 @@
   
   .meta-section {
     display: flex;
-    flex-direction: column;
     gap: 8px;
-    align-items: flex-end;
-    
-    ion-chip {
-      margin: 0;
-    }
+    margin-top: 10px;
   }
 }
 
 .content-card {
+  margin: 0;
+  box-shadow: none;
   border-radius: 12px;
-  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
   
   ion-card-content {
-    padding: 20px;
-  }
-  
-  .content-text {
-    white-space: pre-line;
-    line-height: 1.6;
-    font-size: 1.1rem;
-    color: var(--ion-color-dark);
-  }
-}
-
-/* 响应式调整 */
-@media (max-width: 576px) {
-  .diary-header {
-    flex-direction: column;
+    padding: 16px;
     
-    .meta-section {
-      flex-direction: row;
-      margin-top: 12px;
-      align-self: flex-start;
+    .content-text {
+      white-space: pre-line;
+      line-height: 1.6;
+      font-size: 1.1rem;
     }
   }
+}
+
+ion-fab {
+  margin-bottom: 20px;
 }

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

@@ -1,31 +1,8 @@
-import { Component, OnInit,Input } from '@angular/core';
-import { ActivatedRoute } from '@angular/router';
-import { SwiperOptions } from 'swiper/types'; // 导入 Swiper 类型
-import { ActionSheetController, Platform,  AlertController } from '@ionic/angular';
-import { Router } from '@angular/router';
-import { Share } from '@capacitor/share';
-import { Browser } from '@capacitor/browser';
-import { Location } from '@angular/common';
-
-import { ModalController } from '@ionic/angular';
-import { DiaryService } from '../../services/diary.service';
-
-interface Diary {
-  id: number;
-  date: string;
-  weekday: string;
-  time: string;
-  content: string;
-  weather: string;
-  mood: string;
-}
-
-interface LocationInfo {
-  name: string;
-  address: string;
-  lat?: number;
-  lng?: number;
-}
+import { Component, OnInit } from '@angular/core';
+import { ActivatedRoute, Router } from '@angular/router';
+import { NavController, ModalController } from '@ionic/angular';
+import { CloudObject, CloudQuery } from 'src/lib/ncloud';
+import { EditPage } from '../edit/edit.page';
 
 @Component({
   selector: 'app-test-message',
@@ -34,237 +11,92 @@ interface LocationInfo {
   standalone:false,
 })
 export class TestMessagePage implements OnInit {
- 
-  message: Diary = {
-    id: 1,
-    date: '15',
-    weekday: '周三',
-    time: '14:30',
-    content: '今天阳光明媚,去公园散步时看到樱花开了。粉色的花瓣随风飘落,美得像一幅画。坐在长椅上读了一会儿书,感觉心情特别平静。',
-    weather: '晴',
-    mood: '😊'
-  }; 
-
-  tags: string[] = ['公园', '樱花', '阅读'];
-  tagColors: { [key: string]: string } = {
-    '公园': 'success',
-    '樱花': 'danger',
-    '阅读': 'tertiary'
-  };
-
-  location: LocationInfo = {
-    name: '中央公园',
-    address: '北京市朝阳区朝阳公园南路1号',
-    lat: 39.9334,
-    lng: 116.4833
-  };
+  //diary: CloudObject | null = null;
+  diary: any = null;  // 改为 any 类型或创建接口
+  diaryId: string = '';
 
-  relatedDiaries: Diary[] = [
-    {
-      id: 2,
-      date: '14',
-      weekday: '周二',
-      time: '21:15',
-      content: '项目终于告一段落,加班到很晚但很有成就感。回家的路上买了杯热奶茶犒劳自己。',
-      weather: '多云',
-      mood: '😌'
-    },
-    {
-      id: 3,
-      date: '12',
-      weekday: '周日',
-      time: '09:45',
-      content: '周末尝试做了新的菜谱 - 番茄牛腩。虽然炖的时间比预期长,但结果非常美味!',
-      weather: '小雨',
-      mood: '🥰'
-    }
-  ];
-
-  slideOpts = {
-    slidesPerView: 1.2,
-    spaceBetween: 16,
-    freeMode: true
-  };
-
-  isDarkMode = false;
-
-  toastCtrl: any;
-  constructor( 
-    
-    private route:ActivatedRoute,
+  constructor(
+    private route: ActivatedRoute,
     private router: Router,
-    private actionSheetCtrl: ActionSheetController,
-    private alertController: AlertController,
-    private platform: Platform,
-    private locationBack: Location,
-
-    private diaryService: DiaryService,
+    private navCtrl: NavController,
     private modalCtrl: ModalController
-  ) { 
-    this.route.queryParams.subscribe(params=>{
-     //console.log(params)
-      //this.message=params
-       
-    //安全地从参数中提取并转换为Diary类型
-    this.message = {
-      id: params['id'] || 0, // 提供默认值
-      date: params['date'] || new Date().toISOString(),
-      weekday: params['weekday'] || '',
-      time: params['time'] || '',
-      content: params['content'] || '',
-      weather: params['weather'] || '',
-      mood: params['mood'] || 'normal'
-      // 添加Diary接口定义的所有必需属性
-    };
-    
-    //console.log('转换后的Diary对象:', this.message);
-    })
-  }
+  ) {}
 
   ngOnInit() {
-    this.checkDarkMode();
-    this.loadDiaryData();
-    //this.message = this.navParams.get('message');
-  }
-
-  // 在组件中
-async onDelete(id: number) {
-  const success = await this.diaryService.deleteDiary(id);
-  if (success) {
-    // 刷新列表
-    this.modalCtrl.dismiss({ deleted: true });
-    //this.loadDiaries();
-  }
-  this.locationBack.back();
-}
-  loadDiaries() {
-    throw new Error('Method not implemented.');
-  }
-
-  loadDiaryData() {
-    const navigation = this.router.getCurrentNavigation();
-    if (navigation?.extras?.state) {
-      this.message = navigation.extras.state['message'];
-    }
-  }
-
-  checkDarkMode() {
-    const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');
-    this.isDarkMode = prefersDark.matches;
-    prefersDark.addListener((mediaQuery) => {
-      this.isDarkMode = mediaQuery.matches;
+    this.route.queryParams.subscribe(params => {
+      this.diaryId = params['Did'];
+      this.loadDiary();
     });
   }
 
-  getWeatherIcon(): string {
-    const weatherIcons: { [key: string]: string } = {
-      '晴': 'sunny-outline',
-      '多云': 'cloudy-outline',
-      '雨': 'rainy-outline',
-      '雪': 'snow-outline',
-      '阴': 'cloud-outline'
-    };
-    return weatherIcons[this.message.weather] || 'partly-sunny-outline';
-  }
-
-  getWeatherColor(): string {
-    const weatherColors: { [key: string]: string } = {
-      '晴': 'warning',
-      '多云': 'medium',
-      '雨': 'primary',
-      '雪': 'light',
-      '阴': 'dark'
-    };
-    return weatherColors[this.message.weather] || 'medium';
+  async loadDiary() {
+    if (!this.diaryId) return;
+    
+    const query = new CloudQuery("Diary");
+    query.equalTo("Did", parseInt(this.diaryId));
+    //this.diary = await query.first();
+
+    const result = await query.first();
+    // 将 CloudObject 转换为普通对象
+    if (result) {
+      this.diary = {
+        get: (key: string) => result.get(key),
+        id: result.id  // 假设 CloudObject 有 id 属性
+      };
+    }
   }
 
-  getMoodColor(): string {
-    const moodColors: { [key: string]: string } = {
-      '😊': 'success',
-      '😌': 'tertiary',
-      '🥰': 'danger',
-      '😄': 'warning',
-      '😺': 'primary'
+  async editDiary() {
+    if (!this.diary) return;
+
+    // 准备要编辑的数据
+    const diaryData = {
+      Did: this.diary.get('Did'),
+      date: this.diary.get('date'),
+      weekday: this.diary.get('weekday'),
+      time: this.diary.get('time'),
+      content: this.diary.get('content'),
+      weather: this.diary.get('weather'),
+      mood: this.diary.get('mood')
     };
-    return moodColors[this.message.mood] || 'medium';
-  }
-
-  // async presentActionSheet() {
-  //   const actionSheet = await this.actionSheetCtrl.create({
-  //     header: '日记操作',
-  //     buttons: [
-  //       {
-  //         text: '编辑日记',
-  //         icon: 'create-outline',
-  //         handler: () => {
-  //           this.editDiary();
-  //         }
-  //       },
-  //       { 
-  //         text: '删除日记',
-  //         icon: 'trash-outline',
-  //         role: 'destructive',
-  //         handler: () => {
-  //           this.presentDeleteConfirm();
-  //         }
-  //       }, 
-  //     ]
-  //   });
-  //   await actionSheet.present();
-  // }
-
-  // async presentDeleteConfirm() {
-  //   const alert = await this.alertController.create({
-  //     header: '确认删除',
-  //     message: '确定要删除这篇日记吗?此操作不可撤销。',
-  //     buttons: [
-  //       {
-  //         text: '取消',
-  //         role: 'cancel'
-  //       },
-  //       {
-  //         text: '删除',
-  //         role: 'destructive',
-  //         handler: () => {
-  //           this.deleteDiary();
-  //         }
-  //       }
-  //     ]
-  //   });
-  //   await alert.present();
-  // }
-
-  editDiary() {
-    this.modalCtrl.dismiss();
-    this.router.navigate(['/edit-diary'], {
-      state: { diary: this.message }
+    
+    const modal = await this.modalCtrl.create({
+      component: EditPage,
+      // componentProps: {
+      //   diary: this.diary.toJSON(),
+      //   editMode: true
+      // }
+      componentProps: {
+        diary: diaryData,
+        editMode: true
+      }
     });
-  }
- 
-  
-  // async deleteDiary() {
-  //   console.log('删除日记:', this.message.id);
     
-  //     await this.diaryService.deleteDiary(this.message.id);
-            
-  // }
-
-  // openMap() {
-  //   if (this.platform.is('capacitor')) {
-  //     // 使用原生地图应用
-  //     Browser.open({
-  //       url: `https://maps.google.com/?q=${this.location.lat},${this.location.lng}`
-  //     });
-  //   } else {
-  //     // 网页版使用Google地图
-  //     window.open(`https://maps.google.com/?q=${this.location.lat},${this.location.lng}`, '_blank');
-  //   }
-  // }
-
-  openRelatedDiary(diary: Diary) {
-    this.router.navigate(['/tabs/tab1/message'], {
-      state: { message: diary }
+    modal.onDidDismiss().then((result) => {
+      if (result.data?.saved) {
+        this.loadDiary(); // 刷新日记详情
+      }
     });
+    
+    await modal.present();
   }
 
-}
+  async deleteDiary() {
+    if (!this.diary || !this.diary.id) return;
+    
+    try {
+      // 创建查询并删除
+      const query = new CloudQuery("Diary");
+      query.equalTo("objectId", this.diary.id);
+      const objectToDelete = await query.first();
+      
+      if (objectToDelete) {
+        // 假设 CloudObject 有 destroy 方法而不是 delete
+        await objectToDelete.destroy(); // 或者使用其他删除方法如 remove()
+        this.navCtrl.navigateBack('/tabs/tab1');
+      }
+    } catch (error) {
+      console.error('删除日记失败:', error);
+    }
+  }
+} 

+ 1 - 8
myapp/src/app/tab2/tab2.page.ts

@@ -30,12 +30,5 @@ export class Tab2Page {
     } 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
-  // }
+  } 
 }

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

@@ -5,8 +5,8 @@
     </ion-buttons>
     <ion-title>感恩清单</ion-title>
     <div class="empty-state">
-      <ion-icon name="cloud-outline"></ion-icon>
-      <ion-button fill="outline" (click)="addNewThanks()">添加记录</ion-button>
+      <!-- <ion-icon name="cloud-outline"></ion-icon> -->
+      <ion-button (click)="addNewThanks()">添加记录</ion-button>
     </div>
   </ion-toolbar>
   

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

@@ -121,6 +121,7 @@ export class ThanksCloudPage implements OnInit {
 
     for(const thanks of thanksDataset){
       try{
+        const query=new CloudQuery("Thankstype");
         //检查是否已存在相同内容
         query.equalTo("content",thanks.content);
         const existing=await query.first();

+ 1 - 1
myapp/src/app/tab4/login/login.page.ts

@@ -39,7 +39,7 @@ export class LoginPage {
     const success = await this.authService.login(this.username, this.password);
     if (success) {
       this.showToast('登录成功');
-      this.router.navigate(['/tabs/tab1']);
+      this.router.navigate(['/tabs/tab4']);
     } else {
       this.showToast('登录失败,请检查用户名和密码');
     }