Browse Source

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

Merge pull request !133 from blue/v_3.0.0
master
blue 1 year ago
committed by Gitee
parent
commit
0fdb02b659
No known key found for this signature in database GPG Key ID: 173E9B9CA92EEF8F
  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) => {
return content.replace(/\#[\u4E00-\u9FA5]{1,3}\;/gi, (emoText)=>{
return content.replace(regex, (emoText)=>{
// 将匹配结果替换表情图片
let word = emoText.replace(/\#|\;/gi, '');
let idx = emoTextList.indexOf(word);
@ -21,21 +26,14 @@ let transform = (content, extClass) => {
});
}
let textToPath = (emoText) => {
let word = emoText.replace(/\#|\;/gi, '');
let idx = emoTextList.indexOf(word);
let baseUrl = "/"
// #ifdef H5
baseUrl = window.location.pathname;
// #endif
return `${baseUrl}static/emoji/${idx}.gif`;
return `/static/emoji/${idx}.gif`;
}
export default {
containEmoji,
emoTextList,
transform,
textToPath

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

@ -17,8 +17,11 @@
<view class="chat-msg-bottom">
<view v-if="msgInfo.type == $enums.MESSAGE_TYPE.TEXT">
<long-press-menu :items="menuItems" @select="onSelectMenu">
<up-parse class="chat-msg-text" :showImgMenu="false" :content="nodesText"></up-parse>
<!-- <rich-text class="chat-msg-text" :nodes="nodesText"></rich-text> -->
<!-- rich-text支持显示表情但是不支持点击a标签 -->
<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>
</view>
<view class="chat-msg-image" v-if="msgInfo.type == $enums.MESSAGE_TYPE.IMAGE">

Loading…
Cancel
Save