|
@@ -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'], {
|