diff --git a/im-uniapp/pages/chat/chat-box.vue b/im-uniapp/pages/chat/chat-box.vue index d7fe853..d5d90eb 100644 --- a/im-uniapp/pages/chat/chat-box.vue +++ b/im-uniapp/pages/chat/chat-box.vue @@ -289,7 +289,7 @@ export default { let receiptText = this.isReceipt ? "【回执消息】" : ""; let atText = this.createAtText(); let msgInfo = { - content: receiptText + sendText + atText, + content: receiptText + this.html2Escape(sendText) + atText, atUserIds: this.atUserIds, receipt: this.isReceipt, type: 0 @@ -688,6 +688,16 @@ export default { let px = info.windowWidth * rpx / 750; return Math.floor(rpx); }, + html2Escape(strHtml) { + return strHtml.replace(/[<>&"]/g, function(c) { + return { + '<': '<', + '>': '>', + '&': '&', + '"': '"' + } [c]; + }); + }, sendMessageRequest(msgInfo) { return new Promise((resolve, reject) => { // 请求入队列,防止请求"后发先至",导致消息错序