Browse Source

!136 修复小程序表情不显示的bug

Merge pull request !136 from blue/v_3.0.0
master
blue 1 year ago
committed by Gitee
parent
commit
b4ad05ef53
No known key found for this signature in database GPG Key ID: 173E9B9CA92EEF8F
  1. 15
      im-uniapp/common/emotion.js
  2. 6
      im-uniapp/manifest.json
  3. 13
      im-uniapp/pages/chat/chat-box.vue
  4. BIN
      im-uniapp/static/logo/logo.png

15
im-uniapp/common/emotion.js

@ -13,23 +13,30 @@ let containEmoji = (content) => {
} }
let transform = (content, extClass) => { let transform = (content, extClass) => {
return content.replace(regex, (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);
if (idx == -1) { if (idx == -1) {
return emoText; return emoText;
} }
let path = textToPath(emoText); let path = textToPath(emoText, true);
let img = `<img src="${path}" class="${extClass}"/>`; let img = `<img src="${path}" class="${extClass}"/>`;
return img; return img;
}); });
} }
let textToPath = (emoText) => { let textToPath = (emoText, isRichText) => {
let word = emoText.replace(/\#|\;/gi, ''); let word = emoText.replace(/\#|\;/gi, '');
let idx = emoTextList.indexOf(word); let idx = emoTextList.indexOf(word);
return `/static/emoji/${idx}.gif`; let path = `/static/emoji/${idx}.gif`;
// #ifdef MP-WEIXIN
// 小程序的表情要去掉最前面"/"(但有的时候又不能去掉,十分奇怪)
if (isRichText) {
path = path.slice(1);
}
// #endif
return path;
} }
export default { export default {

6
im-uniapp/manifest.json

@ -106,9 +106,11 @@
"appid" : "wxda94f40bfad0262c", "appid" : "wxda94f40bfad0262c",
"libVersion" : "latest", "libVersion" : "latest",
"setting" : { "setting" : {
"urlCheck" : false "urlCheck" : false,
"minified" : true
}, },
"usingComponents" : true "usingComponents" : true,
"lazyCodeLoading" : "requiredComponents"
}, },
"mp-alipay" : { "mp-alipay" : {
"usingComponents" : true "usingComponents" : true

13
im-uniapp/pages/chat/chat-box.vue

@ -32,7 +32,8 @@
<chat-record v-if="showRecord" class="chat-record" @send="onSendRecord"></chat-record> <chat-record v-if="showRecord" class="chat-record" @send="onSendRecord"></chat-record>
<view v-else class="send-text"> <view v-else class="send-text">
<editor id="editor" class="send-text-area" :placeholder="isReceipt ? '[回执消息]' : ''" <editor id="editor" class="send-text-area" :placeholder="isReceipt ? '[回执消息]' : ''"
:read-only="isReadOnly" @focus="onEditorFocus" @blur="onEditorBlur" @ready="onEditorReady" @input="onTextInput"> :read-only="isReadOnly" @focus="onEditorFocus" @blur="onEditorBlur" @ready="onEditorReady"
@input="onTextInput">
</editor> </editor>
</view> </view>
<view v-if="chat && chat.type == 'GROUP'" class="iconfont icon-at" @click="openAtBox()"></view> <view v-if="chat && chat.type == 'GROUP'" class="iconfont icon-at" @click="openAtBox()"></view>
@ -93,7 +94,7 @@
<scroll-view v-if="chatTabBox === 'emo'" class="chat-emotion" scroll-y="true" <scroll-view v-if="chatTabBox === 'emo'" class="chat-emotion" scroll-y="true"
:style="{height: keyboardHeight+'px'}"> :style="{height: keyboardHeight+'px'}">
<view class="emotion-item-list"> <view class="emotion-item-list">
<image class="emotion-item emoji-large" :title="emoText" :src="$emo.textToPath(emoText)" <image class="emotion-item emoji-large" :title="emoText" :src="$emo.textToPath(emoText,false)"
v-for="(emoText, i) in $emo.emoTextList" :key="i" @click="selectEmoji(emoText)" mode="aspectFit" v-for="(emoText, i) in $emo.emoTextList" :key="i" @click="selectEmoji(emoText)" mode="aspectFit"
lazy-load="true"></image> lazy-load="true"></image>
</view> </view>
@ -369,7 +370,7 @@ export default {
} }
}, },
selectEmoji(emoText) { selectEmoji(emoText) {
let path = this.$emo.textToPath(emoText) let path = this.$emo.textToPath(emoText, true)
// //
this.isReadOnly = true; this.isReadOnly = true;
this.isEmpty = false; this.isEmpty = false;
@ -588,7 +589,7 @@ export default {
this.isEmpty = e.detail.html == '<p><br></p>' this.isEmpty = e.detail.html == '<p><br></p>'
}, },
onEditorReady() { onEditorReady() {
this.$nextTick(()=>{ this.$nextTick(() => {
const query = uni.createSelectorQuery().in(this); const query = uni.createSelectorQuery().in(this);
query.select('#editor').context((res) => { query.select('#editor').context((res) => {
this.editorCtx = res.context this.editorCtx = res.context
@ -741,7 +742,7 @@ export default {
}, },
listenKeyBoard() { listenKeyBoard() {
// #ifdef H5 // #ifdef H5
if (navigator.platform == "Win32" || navigator.platform == "MacIntel" ) { if (navigator.platform == "Win32" || navigator.platform == "MacIntel") {
// //
console.log("navigator.platform:", navigator.platform) console.log("navigator.platform:", navigator.platform)
return; return;
@ -751,7 +752,7 @@ export default {
window.addEventListener('focusin', this.focusInListener); window.addEventListener('focusin', this.focusInListener);
window.addEventListener('focusout', this.focusOutListener); window.addEventListener('focusout', this.focusOutListener);
// ios13 // ios13
if(window.visualViewport){ if (window.visualViewport) {
window.visualViewport.addEventListener('resize', this.resizeListener); window.visualViewport.addEventListener('resize', this.resizeListener);
} }
} else { } else {

BIN
im-uniapp/static/logo/logo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 KiB

Loading…
Cancel
Save