From 8ada32c52f09230e88badc7d08a8f732154b5655 Mon Sep 17 00:00:00 2001 From: QlQl <2458371920@qq.com> Date: Sun, 17 Oct 2021 15:27:30 +0800 Subject: [PATCH] =?UTF-8?q?2.0.0=20-=E6=96=B0=E5=A2=9E=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/behavior/share-chat-behavior.js | 103 +++++++++++++++--- src/components/share-message/share-message.js | 37 +++++-- .../share-message/share-message.json | 3 +- .../share-message/share-message.wxml | 9 +- src/image/add-chat-edit.svg | 1 + src/image/add-chat-ok.svg | 1 + src/image/add-chat-select.svg | 1 + src/pages/add-chat/add-chat.js | 54 ++++----- src/pages/add-chat/add-chat.less | 68 ++++++++---- src/pages/add-chat/add-chat.wxml | 23 ++-- src/pages/add-chat/add-chat.wxss | 54 ++++++--- src/pages/message-remind/message-remind.js | 18 +++ src/pages/message-remind/message-remind.wxml | 10 +- src/pages/share/share.js | 59 ++++------ src/pages/share/share.less | 2 +- src/pages/share/share.wxml | 8 ++ src/pages/share/share.wxss | 2 +- src/store/store.js | 1 + 18 files changed, 304 insertions(+), 150 deletions(-) create mode 100644 src/image/add-chat-edit.svg create mode 100644 src/image/add-chat-ok.svg create mode 100644 src/image/add-chat-select.svg diff --git a/src/behavior/share-chat-behavior.js b/src/behavior/share-chat-behavior.js index 2bfe2a7..393ceb1 100644 --- a/src/behavior/share-chat-behavior.js +++ b/src/behavior/share-chat-behavior.js @@ -203,28 +203,23 @@ 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, @@ -232,13 +227,32 @@ module.exports = Behavior({ 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) { @@ -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, + }); + }, + }); + } } }) \ No newline at end of file diff --git a/src/components/share-message/share-message.js b/src/components/share-message/share-message.js index 6c22933..27fd3dd 100644 --- a/src/components/share-message/share-message.js +++ b/src/components/share-message/share-message.js @@ -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); @@ -66,18 +78,6 @@ Component({ }, }, - /** - * 组件的初始数据 - */ - data: { - chatShow: false, - optionsShow: false, - commentValue: '', - // -1 代表洞主 - replyIndex: -1, - commentFocus: false, - }, - /** * 组件的方法列表 */ @@ -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({ diff --git a/src/components/share-message/share-message.json b/src/components/share-message/share-message.json index 4f02332..0133843 100644 --- a/src/components/share-message/share-message.json +++ b/src/components/share-message/share-message.json @@ -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" } } \ No newline at end of file diff --git a/src/components/share-message/share-message.wxml b/src/components/share-message/share-message.wxml index 9d09e7f..1a1bf6e 100644 --- a/src/components/share-message/share-message.wxml +++ b/src/components/share-message/share-message.wxml @@ -9,8 +9,9 @@ {{ chat.pic.content }} - @@ -39,7 +40,9 @@ -