From 705f005baa5e89c3ebb50a1b24bba74c59421939 Mon Sep 17 00:00:00 2001 From: xsx <825657193@qq.com> Date: Thu, 27 Mar 2025 00:01:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E8=A1=A8=E6=83=85=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E6=94=B9=E4=B8=BA=E9=85=8D=E7=BD=AE=E5=BD=A2=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- im-uniapp/.env.js | 9 ++++++++- im-uniapp/common/emotion.js | 18 +++++++----------- im-uniapp/pages/chat/chat-box.vue | 4 ++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/im-uniapp/.env.js b/im-uniapp/.env.js index b6b9ff4..f8238f1 100644 --- a/im-uniapp/.env.js +++ b/im-uniapp/.env.js @@ -1,12 +1,19 @@ //设置环境(打包前修改此变量) const ENV = "DEV"; const UNI_APP = {} + +UNI_APP.EMO_URL = "/static/emoji/"; +// #ifdef MP-WEIXIN +// 微信小程序的本地表情包经常莫名失效,建议将表情放到服务器中 +// UNI_APP.EMO_URL = "https://www.boxim.online/emoji/"; +// #endif + if(ENV=="DEV"){ UNI_APP.BASE_URL = "http://127.0.0.1:8888"; UNI_APP.WS_URL = "ws://127.0.0.1:8878/im"; // H5 走本地代理解决跨域问题 // #ifdef H5 - UNI_APP.BASE_URL = "/api"; + UNI_APP.BASE_URL = "/api"; // #endif } if(ENV=="PROD"){ diff --git a/im-uniapp/common/emotion.js b/im-uniapp/common/emotion.js index 8c7674e..f7dfe37 100644 --- a/im-uniapp/common/emotion.js +++ b/im-uniapp/common/emotion.js @@ -1,3 +1,6 @@ +import UNI_APP from '@/.env.js' + + const emoTextList = ['憨笑', '媚眼', '开心', '坏笑', '可怜', '爱心', '笑哭', '拍手', '惊喜', '打气', '大哭', '流泪', '饥饿', '难受', '健身', '示爱', '色色', '眨眼', '暴怒', '惊恐', '思考', '头晕', '大吐', '酷笑', '翻滚', '享受', '鼻涕', '快乐', '雀跃', '微笑', @@ -13,30 +16,23 @@ let containEmoji = (content) => { } let transform = (content, extClass) => { - return content.replace(regex, (emoText) => { + return content.replace(regex, (emoText)=>{ // 将匹配结果替换表情图片 let word = emoText.replace(/\#|\;/gi, ''); let idx = emoTextList.indexOf(word); if (idx == -1) { return emoText; } - let path = textToPath(emoText, true); + let path = textToPath(emoText); let img = ``; return img; }); } -let textToPath = (emoText, isRichText) => { +let textToPath = (emoText) => { let word = emoText.replace(/\#|\;/gi, ''); let idx = emoTextList.indexOf(word); - let path = `/static/emoji/${idx}.gif`; - // #ifdef MP-WEIXIN - // 小程序的表情要去掉最前面"/"(但有的时候又不能去掉,十分奇怪) - if (isRichText) { - path = path.slice(1); - } - // #endif - return path; + return UNI_APP.EMO_URL + idx + ".gif"; } export default { diff --git a/im-uniapp/pages/chat/chat-box.vue b/im-uniapp/pages/chat/chat-box.vue index 682d930..0e69592 100644 --- a/im-uniapp/pages/chat/chat-box.vue +++ b/im-uniapp/pages/chat/chat-box.vue @@ -94,7 +94,7 @@ - @@ -370,7 +370,7 @@ export default { } }, selectEmoji(emoText) { - let path = this.$emo.textToPath(emoText, true) + let path = this.$emo.textToPath(emoText) // 先把键盘禁用了,否则会重新弹出键盘 this.isReadOnly = true; this.isEmpty = false;