|
@@ -1,9 +1,9 @@
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
import { ActivatedRoute, ParamMap } from '@angular/router';
|
|
|
-import { IonButton, IonContent, IonFooter, IonIcon, IonTextarea } from '@ionic/angular/standalone';
|
|
|
+import { AlertController, IonAlert, IonButton, IonButtons, IonContent, IonFooter, IonHeader, IonIcon, IonTextarea, IonTitle, IonToolbar } from '@ionic/angular/standalone';
|
|
|
import { addIcons } from 'ionicons';
|
|
|
-import { bookmarkOutline, chatbubbleEllipsesOutline, ellipsisHorizontal, happyOutline, heartOutline, shareSocialOutline } from 'ionicons/icons';
|
|
|
+import { bookmarkOutline, chatbubbleEllipsesOutline, ellipsisHorizontal, happyOutline, heartOutline, shareSocialOutline, trashOutline } from 'ionicons/icons';
|
|
|
import { CustomHeaderComponent } from '../custom-header/custom-header.component';
|
|
|
import { CloudQuery, CloudUser } from 'src/lib/ncloud';
|
|
|
import { map, switchMap } from 'rxjs/operators';
|
|
@@ -11,7 +11,9 @@ import { CloudObject } from 'src/lib/ncloud';
|
|
|
import { FormsModule } from '@angular/forms';
|
|
|
import { IonModal } from '@ionic/angular/standalone';
|
|
|
|
|
|
-addIcons({ ellipsisHorizontal, bookmarkOutline, heartOutline, shareSocialOutline, happyOutline, chatbubbleEllipsesOutline })
|
|
|
+
|
|
|
+
|
|
|
+addIcons({ ellipsisHorizontal, bookmarkOutline, heartOutline, shareSocialOutline, happyOutline, chatbubbleEllipsesOutline,trashOutline })
|
|
|
|
|
|
|
|
|
@Component({
|
|
@@ -19,7 +21,9 @@ addIcons({ ellipsisHorizontal, bookmarkOutline, heartOutline, shareSocialOutline
|
|
|
templateUrl: './post-detail.component.html',
|
|
|
styleUrls: ['./post-detail.component.scss'],
|
|
|
standalone: true,
|
|
|
- imports: [IonContent, IonIcon, IonButton, CommonModule, CustomHeaderComponent, IonTextarea, IonFooter, FormsModule, IonModal]
|
|
|
+ imports: [IonContent, IonIcon, IonButton, CommonModule, CustomHeaderComponent, IonTextarea, IonFooter, FormsModule, IonModal,
|
|
|
+ IonHeader,IonToolbar,IonTitle,IonButtons,IonAlert
|
|
|
+ ]
|
|
|
})
|
|
|
export class PostDetailComponent implements OnInit {
|
|
|
postId: string | any;
|
|
@@ -28,7 +32,9 @@ export class PostDetailComponent implements OnInit {
|
|
|
isfooter: boolean = true; // 控制底部栏的样式
|
|
|
comments: CloudObject[] = []; // 存储评论的数组
|
|
|
isFollowed: boolean = false; // 初始状态为未关注
|
|
|
- constructor(private route: ActivatedRoute) { }
|
|
|
+ isMoreModalOpen: boolean = false; // 控制更多模态框的打开状态
|
|
|
+ isdelete: boolean = false; // 控制删除按钮的显示
|
|
|
+ constructor(private route: ActivatedRoute, private alertController: AlertController) { }
|
|
|
/**
|
|
|
* @从路由参数中获取帖子ID,并初始化帖子详情页面。
|
|
|
*/
|
|
@@ -88,6 +94,7 @@ console.log('关注记录已保存:');
|
|
|
query.equalTo("objectId", this.postId);
|
|
|
let result = await query.find();
|
|
|
this.post = result[0];
|
|
|
+ //console.log(this.post.get('UserID').objectId);
|
|
|
// 判断用户有没有点赞过该帖子
|
|
|
const Query = new CloudQuery('postLikesRecord'); // 创建查询对象
|
|
|
Query.equalTo('UserID', new CloudUser().toPointer()); // 根据用户ID查询
|
|
@@ -325,7 +332,63 @@ async updateCommentLikeCount(Id:any, count:number,Table:any){
|
|
|
this.newComment += emoji; // 将选中的表情添加到输入框
|
|
|
this.closeEmojiPicker(); // 关闭模态框
|
|
|
}
|
|
|
+ goBack() {
|
|
|
+ window.history.back();
|
|
|
+ }
|
|
|
|
|
|
+ // 打开更多模态框
|
|
|
+openMoreModal() {
|
|
|
+ this.isMoreModalOpen = true;
|
|
|
+ const User=new CloudUser().toPointer(); // 获取当前用户指针
|
|
|
+ const UserID=User.objectId; // 获取当前用户ID
|
|
|
+ if(UserID==this.post.get('UserID').objectId){
|
|
|
+ this.isdelete=true; // 显示删除按钮
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 关闭更多模态框
|
|
|
+closeMoreModal() {
|
|
|
+ this.isMoreModalOpen = false;
|
|
|
+}
|
|
|
+
|
|
|
+// 确认删除操作
|
|
|
+async confirmDelete() {
|
|
|
+ const alert = await this.alertController.create({
|
|
|
+ header: '是否确认删除该动态',
|
|
|
+ message: '删除后将不可恢复,请谨慎操作。',
|
|
|
+ cssClass: 'custom-alert', // 添加自定义类
|
|
|
+ buttons: [
|
|
|
+ {
|
|
|
+ text: '暂不',
|
|
|
+ role: 'cancel',
|
|
|
+ handler: () => {
|
|
|
+ console.log('用户选择暂不');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: '确认',
|
|
|
+ handler: () => {
|
|
|
+ this.deletePost(); // 调用删除函数
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ });
|
|
|
+ await alert.present();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// 删除帖子函数
|
|
|
+async deletePost() {
|
|
|
+ const query = new CloudQuery('post')
|
|
|
+ query.equalTo('objectId', this.postId); // 查询帖子ID
|
|
|
+ const post = await query.first(); // 获取帖子对象
|
|
|
+ if (post) {
|
|
|
+ await post.destroy(); // 删除帖子
|
|
|
+ this.closeMoreModal(); // 关闭模态框
|
|
|
+ window.history.back(); // 返回上一页
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
|
|
|
}
|