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 @@
-
+
{{ item.title +':' }}
{{ item.content }}
diff --git a/src/image/add-chat-edit.svg b/src/image/add-chat-edit.svg
new file mode 100644
index 0000000..4c53af0
--- /dev/null
+++ b/src/image/add-chat-edit.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/image/add-chat-ok.svg b/src/image/add-chat-ok.svg
new file mode 100644
index 0000000..639e3b8
--- /dev/null
+++ b/src/image/add-chat-ok.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/image/add-chat-select.svg b/src/image/add-chat-select.svg
new file mode 100644
index 0000000..ba676c1
--- /dev/null
+++ b/src/image/add-chat-select.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/pages/add-chat/add-chat.js b/src/pages/add-chat/add-chat.js
index 4c192c1..e496577 100644
--- a/src/pages/add-chat/add-chat.js
+++ b/src/pages/add-chat/add-chat.js
@@ -35,7 +35,7 @@ Component({
// 待选择的匿名,每个元素{icon, name}
anameRange: app.globalData.anames,
// 当前选择的匿名的 index
- currentAnameIndex: 0,
+ currentAnameIndex: 1,
anameShow: false,
buttons: [
{ text: "取消", type: "default" },
@@ -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: {
@@ -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) {
diff --git a/src/pages/add-chat/add-chat.less b/src/pages/add-chat/add-chat.less
index 7ecbfe1..a6ddcec 100644
--- a/src/pages/add-chat/add-chat.less
+++ b/src/pages/add-chat/add-chat.less
@@ -59,15 +59,26 @@
}
}
.chat-content-wrap {
- padding: 24rpx;
+ padding: 40rpx 32rpx 40rpx 38rpx;
box-sizing: border-box;
- height: 94%;
+ position: relative;
+ .image {
+ position: absolute;
+ width: 42rpx;
+ height: 42rpx;
+ top: 92rpx;
+ left: 74rpx;
+ z-index: 1;
+ }
.chat-content {
- height: 80%;
+ width: 680rpx;
+ height: 572rpx;
line-height: 40rpx;
- font-size: 28rpx;
- width: 80%;
- margin: 40rpx auto;
+ font-size: 28rpx;
+ box-shadow: 0 0 12rpx 0 rgba(172, 171, 171, .4);
+ background-color: white;
+ box-sizing: border-box;
+ padding: 64rpx 98rpx 64rpx 98rpx;
}
.textarea {
font-size: 24rpx;
@@ -75,39 +86,48 @@
height: 40rpx;
line-height: 40rpx;
}
- }
- .char-count {
- position: absolute;
- left: 562rpx;
- top: 1036rpx;
- width: 156rpx;
- height: 34rpx;
- line-height: 34rpx;
- border-radius: 8rpx;
- color: rgba(16, 16, 16, 1);
- font-size: 28rpx;
- text-align: center;
- border: 2rpx solid rgba(187, 187, 187, 1);
+ .char-count {
+ position: absolute;
+ left: 613rpx;
+ top: 559rpx;
+ width: 92rpx;
+ height: 40rpx;
+ line-height: 40rpx;
+ border-radius: 8rpx;
+ color: #101010;
+ font-size: 24rpx;
+ text-align: center;
+ border: 2rpx solid #bbbbbb;
+ }
}
.bottom-options-wrap {
position: relative;
- display: flex;
justify-content: space-around;
align-items: center;
- height: 76rpx;
- line-height: 76rpx;
+ height: 286rpx;
.option {
- height: 100%;
+ border-bottom: white 2rpx solid;
+ background-color: rgba(170, 170, 170, .1);
+ height: 94rpx;
display: flex;
align-items: center;
+ padding-left: 72rpx;
.icon {
width: 48rpx;
height: 48rpx;
}
.content {
- height: 100%;
+ margin-left: 16rpx;
+ height: 94rpx;
+ line-height: 94rpx;
font-size: 28rpx;
}
+ .image {
+ width: 48rpx;
+ height: 48rpx;
+ position: absolute;
+ right: 80rpx;
+ }
}
}
}
\ No newline at end of file
diff --git a/src/pages/add-chat/add-chat.wxml b/src/pages/add-chat/add-chat.wxml
index bee5e47..9da198a 100644
--- a/src/pages/add-chat/add-chat.wxml
+++ b/src/pages/add-chat/add-chat.wxml
@@ -5,14 +5,14 @@
-
+
-
@@ -22,27 +22,29 @@
-
+
+
+
+ {{ charInputLength }} / {{ maxLength }}
-
- {{ charInputLength }} / {{ maxLength }}
-
+
添加今日回顾单
+ ✔
- {{ anameRange[currentAnameIndex].name }}
+ {{ anameRange[currentAnameIndex].name }}
+
- {{ shareRange[currentShareIndex].content }}
+ {{ shareRange[currentShareIndex].content }}
+
@@ -48,4 +49,11 @@
-
\ No newline at end of file
+
+
+
+
+ 是否删除该评论?
+
\ No newline at end of file
diff --git a/src/pages/share/share.js b/src/pages/share/share.js
index f25a334..a4cf917 100644
--- a/src/pages/share/share.js
+++ b/src/pages/share/share.js
@@ -160,41 +160,6 @@ Component({
},
// 下拉刷新,加载数据,这里暂时为全部时间段的
async pullDownLoad() {
- // let chsats = [
- // {
- // picid: 1,
- // owner: app.globalData.owner,
- // data: {
- // reviewAbridge: {
- // safeAreaBottom: this.data.safeAreaBottom,
- // componentHeightMin: 100,
- // componentWidthMax: this.data.windowWidth,
- // starsNum: 4,
- // tasks: [{content: "哈"},],
- // },
- // pic: {
- // picId: 1,
- // headIcon: "/src/image/head-icon-yellow.svg",
- // name: "黄黄",
- // date: "2020-12-21T12:12:12Z",
- // content: "说说",
- // shareRange: 0
- // },
- // },
- // time: "2020-12-21T12:12:12.111222Z",
- // article: [
- // {
- // pic_id: 1,
- // url: "url/1/",
- // content: "some",
- // time: "2020-12-21T12:12:12.111222Z",
- // pic: "url/1/",
- // from_user: "url/" + app.globalData.owner + '/',
- // to_user: "url/" + app.globalData.owner + '/',
- // },
- // ],
- // },
- // ];
this.setData({
pullDownRefresh: true,
});
@@ -207,9 +172,9 @@ Component({
let chatsRemindSqlPr = store.getDataFromSqlByUrl(app.globalData.url + 'notice/notice/', {owner, token});
let dataSql = await Promise.all([chatsSqlPr, gallerysSqlPr, chatsRemindSqlPr])
let chats = util.formatChatsFromSqlToLocal(dataSql[0]);
- chats.forEach(item => {
- item.id = util.getUniqueId();
- });
+ // chats.forEach(item => {
+ // item.id = util.getUniqueId();
+ // });
console.log(chats)
let gallerys = dataSql[1].map(item => {
return {
@@ -240,6 +205,24 @@ Component({
wx.setStorageSync('gallerys', JSON.stringify(gallerys));
wx.setStorageSync('chatsRemind', JSON.stringify(chatsRemind));
},
+ // 删除评论 dialog
+ handleDeleteDialogShow(e) {
+ let {deleteShow, chatId, commentId} = e.detail;
+ this.setData({
+ deleteShow,
+ deleteChatId: chatId,
+ deleteCommentId: commentId,
+ })
+ },
+ // 删除评论 dialog buttons
+ handleDeleteDialog(e) {
+ let {deleteChatId, deleteCommentId} = this.data;
+ if(e.detail.index)
+ this.handleDeleteComment({chatId: deleteChatId, commentId: deleteCommentId});
+ this.setData({
+ deleteShow: false
+ })
+ },
// 点击回到顶部
handleReturnTop() {
this.setData({
diff --git a/src/pages/share/share.less b/src/pages/share/share.less
index af278ee..34b5d68 100644
--- a/src/pages/share/share.less
+++ b/src/pages/share/share.less
@@ -58,7 +58,7 @@
.share-message-remind {
position: absolute;
right: 24rpx;
- top: 350rpx;
+ top: 330rpx;
padding: 20rpx;
z-index: 1;
.remind-image {
diff --git a/src/pages/share/share.wxml b/src/pages/share/share.wxml
index 28e76b5..fa2709e 100644
--- a/src/pages/share/share.wxml
+++ b/src/pages/share/share.wxml
@@ -65,6 +65,7 @@
@@ -106,3 +107,10 @@
catch:touchend="{{ touchmove.handleTouchEnd }}" bindtouchstart="{{ touchmove.handleTouchStart }}"
>
+
+
+
+ 是否删除该评论?
+
\ No newline at end of file
diff --git a/src/pages/share/share.wxss b/src/pages/share/share.wxss
index 6fbc5f2..e9c0f0e 100644
--- a/src/pages/share/share.wxss
+++ b/src/pages/share/share.wxss
@@ -56,7 +56,7 @@
.share-wrap .share-message-remind {
position: absolute;
right: 24rpx;
- top: 350rpx;
+ top: 330rpx;
padding: 20rpx;
z-index: 1;
}
diff --git a/src/store/store.js b/src/store/store.js
index c69580e..fef01b1 100644
--- a/src/store/store.js
+++ b/src/store/store.js
@@ -133,6 +133,7 @@ const saveChatsToSql = async function(chatsLocal, {owner, token}) {
for (let tmpChat of chatsPost) {
if (tmpChat.owner === chatSql.owner && tmpChat.id === chatSql.data.pic.picId) {
tmpChat.urlSql = app.globalData.url + 'community/blog/' + chatSql.picid + '/';
+ tmpChat.id = chatSql.picid;
break;
}
}