0225304 3 gün önce
ebeveyn
işleme
ff07052f4c

+ 48 - 0
myapp/package-lock.json

@@ -24,6 +24,7 @@
         "@capacitor/share": "^7.0.1",
         "@capacitor/status-bar": "7.0.1",
         "@ionic/angular": "^8.5.7",
+        "@ionic/storage-angular": "^4.0.0",
         "fmode-ng": "^0.0.83",
         "ionicons": "^7.0.0",
         "parse": "^5.3.0",
@@ -4478,6 +4479,29 @@
         "tslib": "^2.1.0"
       }
     },
+    "node_modules/@ionic/storage": {
+      "version": "4.0.0",
+      "resolved": "https://registry.npmmirror.com/@ionic/storage/-/storage-4.0.0.tgz",
+      "integrity": "sha512-3N21P19Xk6cICLnSXZ3ilRqbSXAGSFeIF3HNqz+1kARcm0UFT/vwmZreaXtFyq437vvEWOfJ2enlj3JHLKS0FA==",
+      "license": "MIT",
+      "dependencies": {
+        "localforage": "^1.9.0"
+      }
+    },
+    "node_modules/@ionic/storage-angular": {
+      "version": "4.0.0",
+      "resolved": "https://registry.npmmirror.com/@ionic/storage-angular/-/storage-angular-4.0.0.tgz",
+      "integrity": "sha512-FeSmCMCm1bMRfu5TFSqLtjdfEo/dLLUhLIrPmbhSYomVZdV/dNn4mBZv9SabyxSqn4bF31hw40y+4buhG+durQ==",
+      "license": "MIT",
+      "dependencies": {
+        "@ionic/storage": "^4.0.0",
+        "tslib": "^2.3.0"
+      },
+      "peerDependencies": {
+        "@angular/core": "*",
+        "rxjs": "*"
+      }
+    },
     "node_modules/@ionic/utils-array": {
       "version": "2.1.6",
       "resolved": "https://registry.npmmirror.com/@ionic/utils-array/-/utils-array-2.1.6.tgz",
@@ -11821,6 +11845,12 @@
         "node": ">=0.10.0"
       }
     },
+    "node_modules/immediate": {
+      "version": "3.0.6",
+      "resolved": "https://registry.npmmirror.com/immediate/-/immediate-3.0.6.tgz",
+      "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==",
+      "license": "MIT"
+    },
     "node_modules/immutable": {
       "version": "5.1.2",
       "resolved": "https://registry.npmmirror.com/immutable/-/immutable-5.1.2.tgz",
@@ -13396,6 +13426,15 @@
         }
       }
     },
+    "node_modules/lie": {
+      "version": "3.1.1",
+      "resolved": "https://registry.npmmirror.com/lie/-/lie-3.1.1.tgz",
+      "integrity": "sha512-RiNhHysUjhrDQntfYSfY4MU24coXXdEOgw9WGcKHNeEwffDYbF//u87M1EWaMGzuFoSbqW0C9C6lEEhDOAswfw==",
+      "license": "MIT",
+      "dependencies": {
+        "immediate": "~3.0.5"
+      }
+    },
     "node_modules/lines-and-columns": {
       "version": "1.2.4",
       "resolved": "https://registry.npmmirror.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz",
@@ -13578,6 +13617,15 @@
         "node": ">= 12.13.0"
       }
     },
+    "node_modules/localforage": {
+      "version": "1.10.0",
+      "resolved": "https://registry.npmmirror.com/localforage/-/localforage-1.10.0.tgz",
+      "integrity": "sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==",
+      "license": "Apache-2.0",
+      "dependencies": {
+        "lie": "3.1.1"
+      }
+    },
     "node_modules/locate-path": {
       "version": "6.0.0",
       "resolved": "https://registry.npmmirror.com/locate-path/-/locate-path-6.0.0.tgz",

+ 1 - 0
myapp/package.json

@@ -29,6 +29,7 @@
     "@capacitor/share": "^7.0.1",
     "@capacitor/status-bar": "7.0.1",
     "@ionic/angular": "^8.5.7",
+    "@ionic/storage-angular": "^4.0.0",
     "fmode-ng": "^0.0.83",
     "ionicons": "^7.0.0",
     "parse": "^5.3.0",

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

@@ -11,6 +11,7 @@ import { HttpClientModule } from '@angular/common/http';
 import { Diagnostic } from '@awesome-cordova-plugins/diagnostic/ngx';
 // 设置Parse服务属性
 import Parse from "parse";
+import { AlertController } from '@ionic/angular';
 import { BrowserModule } from '@angular/platform-browser';
 Parse.initialize("ncloudmaster");
 Parse.serverURL = "https://server.fmode.cn/parse";
@@ -22,7 +23,7 @@ localStorage.setItem("NOVA_APIG_SERVER", 'aHR0cHMlM0ElMkYlMkZzZXJ2ZXIuZm1vZGUuY2
    providers: [{ 
    provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
    Diagnostic,
-    
+    AlertController
  ],
    bootstrap: [AppComponent],
 })

+ 106 - 5
myapp/src/app/services/diary.service.ts

@@ -1,13 +1,18 @@
 import { Injectable } from '@angular/core';
 import { Diary } from '../modals/diary.modal';
+import { AlertController } from '@ionic/angular'; // 添加这行
 
 @Injectable({
   providedIn: 'root'
 })
 export class DiaryService {
   private storageKey = 'diaries';
+    modalCtrl: any;
+  
+    //alertCtrl: any;
+    //storage: any;
 
-  constructor() {}
+  constructor(private alertCtrl: AlertController) {}
 
   async getDiaries(): Promise<Diary[]> {
     const data = localStorage.getItem(this.storageKey);
@@ -29,9 +34,105 @@ export class DiaryService {
     }
   }
 
-  async deleteDiary(id: number): Promise<void> {
-    const diaries = await this.getDiaries();
-    const updatedDiaries = diaries.filter(d => d.id !== id);
-    localStorage.setItem(this.storageKey, JSON.stringify(updatedDiaries));
+//   async deleteDiary(id: number): Promise<void> {
+//     const diaries = await this.getDiaries();
+//     const updatedDiaries = diaries.filter(d => d.id !== id);
+//     //await this.storage.set('diaries', updatedDiaries);
+//     localStorage.setItem(this.storageKey, JSON.stringify(updatedDiaries));
+//   }
+
+//   async deleteDiary(id: number): Promise<boolean> {
+//     return new Promise<boolean>(async (resolve) => {
+//       const alert = await this.alertCtrl.create({
+//         header: '确认删除',
+//         message: '确定要删除这篇日记吗?',
+//         buttons: [
+//           {
+//             text: '取消',
+//             role: 'cancel',
+//             handler: () => resolve(false)
+//           },
+//           {
+//             text: '删除',
+//             handler: async () => {
+//               const diaries = await this.getDiaries();
+//               const updatedDiaries = diaries.filter(d => d.id !== id);
+//               localStorage.setItem(this.storageKey, JSON.stringify(updatedDiaries));
+//               resolve(true);
+//             }
+//           }
+//         ]
+//       });
+      
+//       await alert.present();
+//     });
+//   }
+
+//   async deleteDiary(id: number): Promise<boolean> {
+//   const alert = await this.alertCtrl.create({
+//     header: '确认删除',
+//     message: '确定要删除这篇日记吗?',
+//     buttons: [
+//       {
+//         text: '取消',
+//         role: 'cancel',
+//         handler: () => {
+//           return false;
+//         }
+//       },
+//       {
+//         text: '删除',
+//         handler: () => {
+//           this.confirmDelete(id);
+//           return true;
+//         }
+//       }
+//     ]
+//   });
+  
+//   await alert.present();
+//   return true;
+// }
+
+// private async confirmDelete(id: number) {
+//   const diaries = await this.getDiaries();
+//   const updatedDiaries = diaries.filter(d => d.id !== id);
+//   localStorage.setItem(this.storageKey, JSON.stringify(updatedDiaries));
+// }
+
+async deleteDiary(id: number): Promise<boolean> {
+    return new Promise<boolean>(async (resolve) => {
+      const alert = await this.alertCtrl.create({
+        header: '确认删除',
+        message: '确定要删除这篇日记吗?',
+        buttons: [
+          {
+            text: '取消',
+            role: 'cancel',
+            handler: () => resolve(false)
+          },
+          {
+            text: '删除',
+            handler: async () => {
+              const diaries = await this.getDiaries();
+              const updatedDiaries = diaries.filter(d => d.id !== id);
+              localStorage.setItem(this.storageKey, JSON.stringify(updatedDiaries));
+              resolve(true);
+              // 关闭当前页面并返回tab1
+            //this.modalCtrl.dismiss({ deleted: true });
+            }
+          }
+        ]
+      });
+      
+      await alert.present();
+    });
   }
+//    async onDelete(id: number) {
+//     const success = await this.diaryService.deleteDiary(id);
+//     if (success) {
+//       // 刷新列表
+//       this.loadDiaries();
+//     }
+//  }
 }

+ 25 - 5
myapp/src/app/tab1/tab1.page.ts

@@ -8,6 +8,7 @@ import { ModalController } from '@ionic/angular';
 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';
  
 @Component({
   selector: 'app-tab1',
@@ -33,6 +34,7 @@ export class Tab1Page implements OnInit{
     await this.loadDiaries();
   }
  
+
   async loadDiaries() {
     this.diaries = await this.diaryService.getDiaries();
     // Sort by date (newest first)
@@ -58,18 +60,36 @@ export class Tab1Page implements OnInit{
     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();
+  // }
+
+  // tab1.page.ts
   async viewDiary(diary: Diary) {
     const modal = await this.modalCtrl.create({
-      component: EditPage,
+      component: TestMessagePage, // 确保使用正确的详情页面组件
       componentProps: {
-        diary: diary,
-        mode: 'edit'
+        message: diary
       }
     });
     
     modal.onDidDismiss().then(async (result) => {
-      if (result.data?.saved) {
-        await this.loadDiaries(); // Refresh the list
+      if (result.data?.deleted) {
+        await this.loadDiaries(); // 刷新列表
       }
     });
     

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

@@ -43,6 +43,7 @@
     </div>
   </div>
 
+
   <!-- 日记内容 -->
   <ion-card class="content-card">
     <ion-card-content>
@@ -54,7 +55,7 @@
 
   <!-- 底部操作栏 -->
   <ion-fab vertical="bottom" horizontal="end" slot="fixed">
-    <ion-fab-button color="danger" (click)="deleteDiary()">
+    <ion-fab-button color="danger" (click)="onDelete(message.id)">
       <ion-icon name="trash-outline"></ion-icon>
     </ion-fab-button>
   </ion-fab>

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

@@ -7,8 +7,9 @@ import { Share } from '@capacitor/share';
 import { Browser } from '@capacitor/browser';
 import { Location } from '@angular/common';
 
-//import { ModalController, NavParams } from '@ionic/angular';
-//import { DiaryService } from '../../services/diary.service';
+import { ModalController } from '@ionic/angular';
+import { DiaryService } from '../../services/diary.service';
+
 interface Diary {
   id: number;
   date: string;
@@ -97,9 +98,8 @@ export class TestMessagePage implements OnInit {
     private platform: Platform,
     private locationBack: Location,
 
-    //private navParams: NavParams,
-    //private diaryService: DiaryService,
-    //private modalCtrl: ModalController
+    private diaryService: DiaryService,
+    private modalCtrl: ModalController
   ) { 
     this.route.queryParams.subscribe(params=>{
      //console.log(params)
@@ -124,6 +124,21 @@ export class TestMessagePage implements OnInit {
   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() {
@@ -174,99 +189,77 @@ export class TestMessagePage implements OnInit {
     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: 'share-social-outline',
-          handler: () => {
-            this.shareDiary();
-          }
-        },
-        {
-          text: '删除日记',
-          icon: 'trash-outline',
-          role: 'destructive',
-          handler: () => {
-            this.presentDeleteConfirm();
-          }
-        },
-        {
-          text: '取消',
-          icon: 'close',
-          role: 'cancel'
-        }
-      ]
-    });
-    await actionSheet.present();
-  }
+  // 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();
-  }
+  // 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 }
     });
   }
+ 
+  
+  // async deleteDiary() {
+  //   console.log('删除日记:', this.message.id);
+    
+  //     await this.diaryService.deleteDiary(this.message.id);
+            
+  // }
 
-  async shareDiary() {
-    try {
-      await Share.share({
-        title: `我的日记 - ${this.message.date}日`,
-        text: `${this.message.date}日 ${this.message.weekday} ${this.message.time}\n${this.message.content}`,
-        url: 'https://my-diary-app.com/share/' + this.message.id,
-        dialogTitle: '分享日记'
-      });
-    } catch (error) {
-      console.error('分享失败:', error);
-    }
-  }
-
-  deleteDiary() {
-    console.log('删除日记:', this.message.id);
-    // 这里添加实际的删除逻辑
-    this.locationBack.back();
-  }
-
-  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');
-    }
-  }
+  // 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'], {