|
@@ -37,7 +37,9 @@ Component({
|
|
|
poptype: '',
|
|
|
userobject: '',
|
|
|
//评论
|
|
|
- commenttext:"评论"
|
|
|
+ commenttext: "评论",
|
|
|
+ focusedCommentId: null,
|
|
|
+ isCommentFocused: false
|
|
|
},
|
|
|
lifetimes: {
|
|
|
|
|
@@ -52,8 +54,10 @@ Component({
|
|
|
this.getComment()
|
|
|
},
|
|
|
|
|
|
+
|
|
|
},
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 组件的方法列表
|
|
|
*/
|
|
@@ -231,7 +235,7 @@ Component({
|
|
|
this.setData({
|
|
|
show: true,
|
|
|
poptype: 'one', //直接回复
|
|
|
- commenttext:'评论'
|
|
|
+ commenttext: '评论'
|
|
|
});
|
|
|
this.showgood()
|
|
|
},
|
|
@@ -301,12 +305,12 @@ Component({
|
|
|
}
|
|
|
//回复别人评论
|
|
|
if (this.data.poptype == 'two') {
|
|
|
- console.log('id',this.data.userobject);
|
|
|
+ console.log('id', this.data.userobject);
|
|
|
this.rebackmoment()
|
|
|
}
|
|
|
|
|
|
},
|
|
|
- //获取评论
|
|
|
+ // 获取评论
|
|
|
async getComment() {
|
|
|
let Momentquery = new Parse.Query('AIMomentComment');
|
|
|
Momentquery.equalTo('company', company);
|
|
@@ -315,24 +319,30 @@ Component({
|
|
|
Momentquery.notEqualTo('isDeleted', true);
|
|
|
Momentquery.include('user');
|
|
|
Momentquery.include('comment.user');
|
|
|
-
|
|
|
+
|
|
|
// 按照创建时间升序排列(从旧到新)
|
|
|
Momentquery.ascending('createdAt'); // 或者使用 Momentquery.descending('createdAt') 以降序排列
|
|
|
-
|
|
|
+
|
|
|
let r = await Momentquery.find();
|
|
|
- let commentList = r.map(item => item.toJSON());
|
|
|
+ let commentList = r.map(item => {
|
|
|
+ let comment = item.toJSON();
|
|
|
+ // 初始化 showdeletid 属性为 false
|
|
|
+ comment.showdeletid = false;
|
|
|
+ return comment;
|
|
|
+ });
|
|
|
console.log('评论', commentList);
|
|
|
this.setData({
|
|
|
commentList
|
|
|
});
|
|
|
},
|
|
|
- //点击评论
|
|
|
- async showpop(e) {
|
|
|
- const objectId = e.currentTarget.dataset.id
|
|
|
+
|
|
|
+ // 点击评论
|
|
|
+ async showpop(e) {
|
|
|
+ const objectId = e.currentTarget.dataset.id;
|
|
|
let AIMomentCommentquery = new Parse.Query('AIMomentComment');
|
|
|
AIMomentCommentquery.equalTo('company', company);
|
|
|
AIMomentCommentquery.equalTo('objectId', objectId);
|
|
|
- AIMomentCommentquery.notEqualTo('isDeleted', true)
|
|
|
+ AIMomentCommentquery.notEqualTo('isDeleted', true);
|
|
|
AIMomentCommentquery.include('user');
|
|
|
let r = await AIMomentCommentquery.find();
|
|
|
let commentList = r.map(item => item.toJSON());
|
|
@@ -341,27 +351,62 @@ Component({
|
|
|
let userquery = new Parse.Query('_User');
|
|
|
userquery.equalTo('company', company);
|
|
|
userquery.equalTo('objectId', currentUser.id);
|
|
|
- userquery.notEqualTo('isDeleted', true)
|
|
|
+ userquery.notEqualTo('isDeleted', true);
|
|
|
let R = await userquery.find();
|
|
|
let user = R.map(item => item.toJSON());
|
|
|
|
|
|
- if(user[0].objectId!=commentList[0].user.objectId){
|
|
|
+ // 检查是否点击了自己的评论
|
|
|
+ if (user[0].objectId != commentList[0].user.objectId) {
|
|
|
this.setData({
|
|
|
show: true,
|
|
|
poptype: 'two',
|
|
|
- userobject:objectId,
|
|
|
- commenttext:`回复${commentList[0].user.nickname}`
|
|
|
+ userobject: objectId,
|
|
|
+ commenttext: `回复${commentList[0].user.nickname}`
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 点击了自己的评论,设置对应评论的 showdeletid 为 true
|
|
|
+ const updatedCommentList = this.data.commentList.map(comment => {
|
|
|
+ if (comment.objectId === objectId) {
|
|
|
+ return {
|
|
|
+ ...comment,
|
|
|
+ showdeletid: true // 更新当前评论项
|
|
|
+ };
|
|
|
+
|
|
|
+ }
|
|
|
+ return comment; // 保持其他评论项不变
|
|
|
+
|
|
|
+ });
|
|
|
+ this.setData({
|
|
|
+ commentList: updatedCommentList // 更新 commentList 的状态
|
|
|
});
|
|
|
- }else{
|
|
|
console.log('点击了自己');
|
|
|
}
|
|
|
+ console.log(this.data.commentList);
|
|
|
+ },
|
|
|
|
|
|
+ // 点击其他地方重置所有评论的 showdeletid
|
|
|
+ onTapOutside() {
|
|
|
+ if (!this.data.isCommentFocused) { // 只有在没有评论聚焦时才重置
|
|
|
+ const updatedCommentList = this.data.commentList.map(comment => ({
|
|
|
+ ...comment,
|
|
|
+ showdeletid: false // 重置所有评论的 showdeletid
|
|
|
+ }));
|
|
|
|
|
|
+ this.setData({
|
|
|
+ commentList: updatedCommentList,
|
|
|
+ focusedCommentId: null // 清除聚焦状态
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 添加页面的触摸事件
|
|
|
+ onTouchStart() {
|
|
|
+ this.onTapOutside(); // 页面触摸时重置评论状态
|
|
|
},
|
|
|
+
|
|
|
//回复评论
|
|
|
async rebackmoment() {
|
|
|
//所属评论
|
|
|
-
|
|
|
+
|
|
|
let AIMomentCommentquery = new Parse.Query('AIMomentComment');
|
|
|
AIMomentCommentquery.equalTo('company', company);
|
|
|
AIMomentCommentquery.equalTo('objectId', this.data.userobject);
|