Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
-新增评论删除功能
  • Loading branch information
QlQlqiqi committed Oct 17, 2021
1 parent e2caee1 commit 8ada32c
Show file tree
Hide file tree
Showing 18 changed files with 304 additions and 150 deletions.
103 changes: 86 additions & 17 deletions src/behavior/share-chat-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,42 +203,56 @@ module.exports = Behavior({
},
// 发送评论
async handleEnsureComment(e) {
// 本应该后续检查是否 post 成功,这里预留一个
// 先改变本地,然后异步同步到后端
// 这里同步不会 get ,只是 post
wx.showLoading({
title: '正在发送...',
mask: true
})
let { comment: commentLocal, chatId } = e.detail;
let chats = this.data.chats, chat;
console.log(commentLocal, chatId)
let chats = this.data.chats, chat, idx;
console.log(chats, commentLocal, chatId)
for(let i = 0; i < chats.length; i++) {
chat = chats[i];
if(chat.id === chatId) {
chat.comments.push(commentLocal);
let key = `chats[${i}].comments`;
this.setData({
[key]: chat.comments
})
// 这块是为了 message-remind 页面
if(typeof this._changeChatsRemind === 'function')
this._changeChatsRemind(chat);
idx = i;
break;
}
}
console.log(idx)
// 下面是 post
let commentSql = {
let commentPost = {
comment_uid: util.getUniqueId(),
pic: chat.urlSql,
content: commentLocal.content,
from_user: app.globalData.url + 'login/user/' + commentLocal.fromUser + '/',
to_user: app.globalData.url + 'login/user/' + commentLocal.toUser + '/'
};
let {owner, token} = await util.getTokenAndOwner(app.globalData.url + 'login/login/');
util.myRequest({
await util.myRequest({
url: app.globalData.url + 'community/comment/',
header: {Authorization: "Token " + token},
method: 'POST',
data: commentSql
data: commentPost
})
.then(res => console.log(res))
let tmp = chat.urlSql.split('\/');
let commentsSql = await store.getDataFromSqlByUrl(
app.globalData.url + 'community/comment/?pic=' + JSON.stringify(+tmp[tmp.length - 2]),
{token}
);
commentsSql.forEach(item => {
if(item.comment_uid === commentPost.comment_uid)
commentLocal.urlSql = item.url;
})
chat.comments.push(commentLocal);
let key = `chats[${idx}].comments`;
this.setData({
[key]: chat.comments
})
// 这块是为了 message-remind 页面
if(typeof this._changeChatsRemind === 'function')
this._changeChatsRemind(chat);

wx.setStorageSync('chats', JSON.stringify(chats));

// 消息提醒
// 回复别人,接收者为他
if(commentLocal.fromUser !== commentLocal.toUser) {
Expand Down Expand Up @@ -274,6 +288,61 @@ module.exports = Behavior({
}
})
}
wx.hideLoading({
success: () => {
wx.showToast({
title: "已完成",
duration: 800,
});
},
});
},
// 删除评论
async handleDeleteComment({chatId, commentId}) {
wx.showLoading({
title: '正在删除...',
mask: true
})
let chat = null, comment = null, chats = this.data.chats;
for(let i = 0; i < chats.length; i++) {
chat = chats[i];
if(chat.id === chatId) {
for(let j = 0; j < chat.comments.length; j++) {
comment = chat.comments[j];
console.log(comment)
if(comment.id === commentId) {
chat.comments.splice(j, 1);
let key = `chats[${i}].comments`;
this.setData({
[key]: chat.comments,
})
break;
}
}
break;
}
}
// 这块是为了 message-remind 页面
if(typeof this._changeChatsRemind === 'function')
this._changeChatsRemind(chat);

wx.setStorageSync('chats', JSON.stringify(chats));
let {owner, token} = await util.getTokenAndOwner(app.globalData.url + 'login/login/');
console.log(comment)
await util.myRequest({
url: comment.urlSql,
header: {Authorization: 'Token ' + token},
method: 'DELETE'
})
.then(res => console.log(res))
wx.hideLoading({
success: () => {
wx.showToast({
title: "已完成",
duration: 800,
});
},
});
}
}
})
37 changes: 25 additions & 12 deletions src/components/share-message/share-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ Component({
componentWidthMax: Number
},

/**
* 组件的初始数据
*/
data: {
chatShow: false,
optionsShow: false,
commentValue: '',
// -1 代表洞主
replyIndex: -1,
commentFocus: false,
},

computed: {
date(data) {
return util.dateInToOut(data.chat.pic.date);
Expand Down Expand Up @@ -66,18 +78,6 @@ Component({
},
},

/**
* 组件的初始数据
*/
data: {
chatShow: false,
optionsShow: false,
commentValue: '',
// -1 代表洞主
replyIndex: -1,
commentFocus: false,
},

/**
* 组件的方法列表
*/
Expand Down Expand Up @@ -156,6 +156,19 @@ Component({
replyIndex: -1
})
},
// 弹窗是否删除自己评论
handleDeleteCommentShow(e) {
// 只可以删除自己的
let chatFilter = this.data.chatFilter;
let index = e.currentTarget.dataset.index;
if(chatFilter.comments[index].fromUser !== app.globalData.owner)
return;
this.triggerEvent('handleDeleteDialogShow', {
deleteShow: true,
chatId: chatFilter.id,
commentId: chatFilter.comments[index].id,
})
},
// 输入评论
handleInputComment(e) {
this.setData({
Expand Down
3 changes: 2 additions & 1 deletion src/components/share-message/share-message.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"component": true,
"usingComponents": {
"review-abridge": "/src/components/review-abridge/review-abridge"
"review-abridge": "/src/components/review-abridge/review-abridge",
"mp-dialog": "weui-miniprogram/dialog/dialog"
}
}
9 changes: 6 additions & 3 deletions src/components/share-message/share-message.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<view class="share-message-content">
<view class="content">{{ chat.pic.content }}</view>
<view wx:if="{{ chat.reviewAbridge.show }}" class="reivew-abridge">
<review-abridge wx:if="{{ chat.reviewAbridge.show }}" componentWidthMax="{{ componentWidthMax || windowWidth }}" componentHeightMin="{{ 140 }}"
starsNum="{{ chat.reviewAbridge.starsNum }}" tasks="{{ chat.reviewAbridge.tasks }}" safeAreaBottom="{{ bottomLineHeight }}"
<review-abridge wx:if="{{ chat.reviewAbridge.show }}" componentWidthMax="{{ componentWidthMax || windowWidth }}"
componentHeightMin="{{ 140 }}" starsNum="{{ chat.reviewAbridge.starsNum }}" tasks="{{ chat.reviewAbridge.tasks }}"
safeAreaBottom="{{ bottomLineHeight }}"
></review-abridge>
</view>
</view>
Expand Down Expand Up @@ -39,7 +40,9 @@
<!-- 评论区 -->
<view wx:if="{{ chatShow }}" class="share-message-chats-wrap">
<view class="chats-content-wrap">
<view wx:for="{{ chatFilter.comments }}" wx:key="index" data-index="{{ index }}" class="share-message-chat" bindtap="handleReplyWho">
<view wx:for="{{ chatFilter.comments }}" wx:key="index" data-index="{{ index }}" class="share-message-chat"
bindtap="handleReplyWho" bindlongpress="handleDeleteCommentShow"
>
<text class="chat-title">{{ item.title +':' }}</text>
<text class="chat-content">{{ item.content }}</text>
</view>
Expand Down
1 change: 1 addition & 0 deletions src/image/add-chat-edit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/image/add-chat-ok.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/image/add-chat-select.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 29 additions & 25 deletions src/pages/add-chat/add-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Component({
// 待选择的匿名,每个元素{icon, name}
anameRange: app.globalData.anames,
// 当前选择的匿名的 index
currentAnameIndex: 0,
currentAnameIndex: 1,
anameShow: false,
buttons: [
{ text: "取消", type: "default" },
Expand Down Expand Up @@ -183,7 +183,7 @@ Component({
let {owner, token} = await util.getTokenAndOwner(app.globalData.url + 'login/login/');
let {anames} = app.globalData;
let chat = {
id: util.getUniqueId(),
// id: util.getUniqueId(),
owner,
reviewAbridge: this.data.review,
pic: {
Expand Down Expand Up @@ -251,30 +251,34 @@ Component({
},
// 触发“添加今日回顾清单”
handleAddReviewAbridge(e) {
// 如果已经添加了,显示不能重复添加
if (this.data.reviewShow) {
let { windowHeight, navHeight, ratio } = this.data;
this.setData({
repeatTipShow: true,
repeatTipTop:
windowHeight -
navHeight -
this.data.optionsBottom -
(76 + 88 + 200) / ratio,
});
// 3000ms 后消失,如果期间再次点击,则重新计算时间
if (this._repeatTipTimeId) clearTimeout(this._repeatTipTimeId);
this._repeatTipTimeId = setTimeout(() => {
this.setData({
repeatTipShow: false,
});
delete this._repeatTipTimeId;
}, 3000);
return;
}
this.setData({
reviewShow: true,
});
reviewShow: !this.data.reviewShow
})
// 如果已经添加了,显示不能重复添加(这是旧的)
// 如果已经添加,取消添加
// if (this.data.reviewShow) {
// let { windowHeight, navHeight, ratio } = this.data;
// this.setData({
// repeatTipShow: true,
// repeatTipTop:
// windowHeight -
// navHeight -
// this.data.optionsBottom -
// (76 + 88 + 700) / ratio,
// });
// // 3000ms 后消失,如果期间再次点击,则重新计算时间
// if (this._repeatTipTimeId) clearTimeout(this._repeatTipTimeId);
// this._repeatTipTimeId = setTimeout(() => {
// this.setData({
// repeatTipShow: false,
// });
// delete this._repeatTipTimeId;
// }, 3000);
// return;
// }
// this.setData({
// reviewShow: true,
// });
},
// 关闭缩略图
handleCloseReviewAbridge(e) {
Expand Down
Loading

0 comments on commit 8ada32c

Please sign in to comment.