From cd02a5f0b4b8f4b8cc8e8e2052e142e9add47fed Mon Sep 17 00:00:00 2001 From: DCloud_JSON Date: Wed, 8 May 2024 17:50:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E4=BC=9A=E8=AF=9D=E5=88=87=E6=8D=A2=E7=9A=84?= =?UTF-8?q?=E8=8D=89=E7=A8=BF=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/chat/chat.nvue | 53 ++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/pages/chat/chat.nvue b/pages/chat/chat.nvue index 18fa156..0f18668 100644 --- a/pages/chat/chat.nvue +++ b/pages/chat/chat.nvue @@ -253,7 +253,9 @@ aboutUserKeyword: '', memberListScrollTop: 0, chooseMoreMsg: false, - checkedMsgList: [] + checkedMsgList: [], + // 聊天输入框内容 + chatInputContent: '', }; }, props: { @@ -319,24 +321,6 @@ }) }, //聊天数据 - //当前会话的聊天框文字内容 - chatInputContent: { - get() { - // console.log('this.conversation',this.conversation); - return this.conversation?.chatInputContent || ''; - }, - set(chatInputContent) { - // #ifdef APP-NVUE - if(this.nvueSetChatInputContent){ - clearTimeout(this.nvueSetChatInputContent) - } - this.nvueSetChatInputContent = setTimeout(()=>this.conversation.chatInputContent = chatInputContent,1000) - // #endif - // #ifndef APP-NVUE - this.conversation.chatInputContent = chatInputContent - // #endif - } - }, canSend() { if(typeof this.chatInputContent === 'string'){ return this.chatInputContent.trim() != '' @@ -577,14 +561,14 @@ }, onUnload() { // console.log('onUnload'); - + // 关闭监听消息推送事件 uniIm.offMsg(this.onImMsg); - + // #ifndef H5 uni.offKeyboardHeightChange(this.onKeyboardHeightChange) // #endif - + //页面销毁之前销毁 全局变量 正在聊天的用户的id uniIm.currentConversationId = false // console.log('beforeDestroy'); @@ -660,9 +644,15 @@ async load(param) { this.answerMsg = false // conversation_id = "single_eff0518ad35e16a8a025cc8af03e0388" + if(this.conversation.id){ + // 设置(含清空)上一个会话的chatInputContent 实现多个会话之间的草稿功能 + this.conversation.chatInputContent = this.chatInputContent + } // console.log('conversation_id',conversation_id); this.conversation = await uniIm.conversation.get(param) + // 初始化会话的chatInputContent + this.chatInputContent = this.conversation.chatInputContent // this.conversation.call_list = [] // console.log('this.conversation',this.conversation) @@ -1118,10 +1108,7 @@ msg.body = msg.body.trim(); // 阻止发送空消息 if (!msg.body.length) { - this.$nextTick(() => { - this.chatInputContent = ''; - this.textareaHeight = 26; - }); + this.resetChatInput() return uni.showToast({ title: '不能发送空消息', icon: 'none' @@ -1162,12 +1149,6 @@ }) } } - - this.$nextTick(e => { - this.chatInputContent = ''; - this.textareaHeight = 26; - this.answerMsg = false - }); //如果是回复某一条消息,需要带上相关id if (this.answerMsg !== false) { @@ -1176,6 +1157,8 @@ // 消息列表追加此消息。此时消息状态值为0,表示发送中 let resMsg = this.conversation.msgList.push(msg) + + this.resetChatInput() this.$nextTick(() => { this.showLast() @@ -1197,6 +1180,12 @@ return msg; } }, + resetChatInput() { + this.chatInputContent = '' + this.textareaHeight = 26 + // 关闭引用的消息 + this.answerMsg = false + }, getCallUid(param){ let aboutNicknameList = [] if( this.isWidescreen){ -- GitLab