Browse Source

修复表情打包后可能不显示的bug

master
xsx 1 year ago
parent
commit
cc2d501d24
  1. 18
      im-uniapp/common/emotion.js
  2. 7
      im-uniapp/components/chat-message-item/chat-message-item.vue

18
im-uniapp/common/emotion.js

@ -6,9 +6,14 @@ const emoTextList = ['憨笑', '媚眼', '开心', '坏笑', '可怜', '爱心',
"摇头", "偷瞄", "庆祝", "疾跑", "打滚", "惊吓", "起跳" "摇头", "偷瞄", "庆祝", "疾跑", "打滚", "惊吓", "起跳"
]; ];
const regex = /\#[\u4E00-\u9FA5]{1,3}\;/gi;
let containEmoji = (content) => {
return regex.test(content)
}
let transform = (content, extClass) => { let transform = (content, extClass) => {
return content.replace(/\#[\u4E00-\u9FA5]{1,3}\;/gi, (emoText)=>{ return content.replace(regex, (emoText)=>{
// 将匹配结果替换表情图片 // 将匹配结果替换表情图片
let word = emoText.replace(/\#|\;/gi, ''); let word = emoText.replace(/\#|\;/gi, '');
let idx = emoTextList.indexOf(word); let idx = emoTextList.indexOf(word);
@ -21,21 +26,14 @@ let transform = (content, extClass) => {
}); });
} }
let textToPath = (emoText) => { let textToPath = (emoText) => {
let word = emoText.replace(/\#|\;/gi, ''); let word = emoText.replace(/\#|\;/gi, '');
let idx = emoTextList.indexOf(word); let idx = emoTextList.indexOf(word);
let baseUrl = "/" return `/static/emoji/${idx}.gif`;
// #ifdef H5
baseUrl = window.location.pathname;
// #endif
return `${baseUrl}static/emoji/${idx}.gif`;
} }
export default { export default {
containEmoji,
emoTextList, emoTextList,
transform, transform,
textToPath textToPath

7
im-uniapp/components/chat-message-item/chat-message-item.vue

@ -17,8 +17,11 @@
<view class="chat-msg-bottom"> <view class="chat-msg-bottom">
<view v-if="msgInfo.type == $enums.MESSAGE_TYPE.TEXT"> <view v-if="msgInfo.type == $enums.MESSAGE_TYPE.TEXT">
<long-press-menu :items="menuItems" @select="onSelectMenu"> <long-press-menu :items="menuItems" @select="onSelectMenu">
<up-parse class="chat-msg-text" :showImgMenu="false" :content="nodesText"></up-parse> <!-- rich-text支持显示表情但是不支持点击a标签 -->
<!-- <rich-text class="chat-msg-text" :nodes="nodesText"></rich-text> --> <rich-text v-if="$emo.containEmoji(msgInfo.content)" class="chat-msg-text"
:nodes="nodesText"></rich-text>
<!-- up-parse支持点击a标签,但安卓打包后表情无法显示,原因未知 -->
<up-parse v-else class="chat-msg-text" :showImgMenu="false" :content="nodesText"></up-parse>
</long-press-menu> </long-press-menu>
</view> </view>
<view class="chat-msg-image" v-if="msgInfo.type == $enums.MESSAGE_TYPE.IMAGE"> <view class="chat-msg-image" v-if="msgInfo.type == $enums.MESSAGE_TYPE.IMAGE">

Loading…
Cancel
Save