From d013ab1e3cc7ae1975faab5a9dd7f72059f2557f Mon Sep 17 00:00:00 2001 From: kuaifan Date: Wed, 20 Jul 2022 12:21:17 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=8F=91=E9=80=81?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=87=BA=E7=8E=B0=E7=A9=BA=E7=99=BD=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/manage/components/DialogWrapper.vue | 66 ++++++++++--------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index 66de4a86d..0ec3f81b9 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -875,11 +875,12 @@ export default { */ sendMsg(text) { let msgText; + let emptied = false; if (typeof text === "string" && text) { msgText = text; } else { msgText = this.msgText; - this.msgText = ''; + emptied = true; } if (msgText == '') { this.inputFocus(); @@ -928,37 +929,38 @@ export default { text: typeLoad ? '' : msgText, }, } - setTimeout(_ => { - this.tempMsgs.push(tempMsg) - this.msgType = '' - this.replyActiveId = 0 - this.onActive() - this.$nextTick(this.onToBottom) - // - this.$store.dispatch("call", { - url: 'dialog/msg/sendtext', - data: { - dialog_id: tempMsg.dialog_id, - reply_id: tempMsg.reply_id, - text: msgText, - }, - method: 'post', - complete: _ => this.tempMsgs = this.tempMsgs.filter(({id}) => id != tempId) - }).then(({data}) => { - this.sendSuccess(data) - }).catch(({msg}) => { - $A.modalConfirm({ - icon: 'error', - title: '发送失败', - content: msg, - cancelText: '取消', - okText: '再次编辑', - onOk: () => { - this.msgText = msgText - } - }) - }); - }, 10) + this.tempMsgs.push(tempMsg) + this.msgType = '' + this.replyActiveId = 0 + this.onActive() + this.$nextTick(this.onToBottom) + // + this.$store.dispatch("call", { + url: 'dialog/msg/sendtext', + data: { + dialog_id: tempMsg.dialog_id, + reply_id: tempMsg.reply_id, + text: msgText, + }, + method: 'post', + complete: _ => this.tempMsgs = this.tempMsgs.filter(({id}) => id != tempId) + }).then(({data}) => { + this.sendSuccess(data) + }).catch(({msg}) => { + $A.modalConfirm({ + icon: 'error', + title: '发送失败', + content: msg, + cancelText: '取消', + okText: '再次编辑', + onOk: () => { + this.msgText = msgText + } + }) + }); + } + if (emptied) { + requestAnimationFrame(_ => this.msgText = '') } },