Browse Source

修复消息重复发送的bug

master
xie.bx 3 years ago
parent
commit
b7cde37995
  1. 13
      im-ui/src/components/chat/ChatBox.vue

13
im-ui/src/components/chat/ChatBox.vue

@ -40,7 +40,7 @@
</div> </div>
<div title="聊天记录" class="el-icon-chat-dot-round" @click="showHistoryBox()"></div> <div title="聊天记录" class="el-icon-chat-dot-round" @click="showHistoryBox()"></div>
</div> </div>
<textarea v-model="sendText" ref="sendBox" class="send-text-area" @keydown.enter="sendTextMessage()"></textarea> <textarea v-model="sendText" ref="sendBox" class="send-text-area" :disabled="lockMessage" @keydown.enter="sendTextMessage()"></textarea>
<div class="im-chat-send"> <div class="im-chat-send">
<el-button type="primary" @click="sendTextMessage()">发送</el-button> <el-button type="primary" @click="sendTextMessage()">发送</el-button>
</div> </div>
@ -94,7 +94,8 @@
x: 0, x: 0,
y: 0 y: 0
}, },
showHistory: false // showHistory: false, //
lockMessage: false //
} }
}, },
methods: { methods: {
@ -269,6 +270,7 @@
} }
// id // id
this.setTargetId(msgInfo, this.chat.targetId); this.setTargetId(msgInfo, this.chat.targetId);
this.lockMessage = true;
this.$http({ this.$http({
url: this.messageAction, url: this.messageAction,
method: 'post', method: 'post',
@ -281,11 +283,14 @@
msgInfo.sendId = this.$store.state.userStore.userInfo.id; msgInfo.sendId = this.$store.state.userStore.userInfo.id;
msgInfo.selfSend = true; msgInfo.selfSend = true;
this.$store.commit("insertMessage", msgInfo); this.$store.commit("insertMessage", msgInfo);
}).finally(() => {
//
this.lockMessage = false;
// //
this.$refs.sendBox.focus(); this.$nextTick(() => this.$refs.sendBox.focus());
// //
this.scrollToBottom(); this.scrollToBottom();
}) });
const e = window.event || arguments[0]; const e = window.event || arguments[0];
if (e.key === 'Enter' || e.code === 'Enter' || e.keyCode === 13) { if (e.key === 'Enter' || e.code === 'Enter' || e.keyCode === 13) {
e.returnValue = false; e.returnValue = false;

Loading…
Cancel
Save