Browse Source

微信表情路径改为配置形式

master
xsx 1 year ago
parent
commit
705f005baa
  1. 7
      im-uniapp/.env.js
  2. 16
      im-uniapp/common/emotion.js
  3. 4
      im-uniapp/pages/chat/chat-box.vue

7
im-uniapp/.env.js

@ -1,6 +1,13 @@
//设置环境(打包前修改此变量)
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";

16
im-uniapp/common/emotion.js

@ -1,3 +1,6 @@
import UNI_APP from '@/.env.js'
const emoTextList = ['憨笑', '媚眼', '开心', '坏笑', '可怜', '爱心', '笑哭', '拍手', '惊喜', '打气',
'大哭', '流泪', '饥饿', '难受', '健身', '示爱', '色色', '眨眼', '暴怒', '惊恐',
'思考', '头晕', '大吐', '酷笑', '翻滚', '享受', '鼻涕', '快乐', '雀跃', '微笑',
@ -20,23 +23,16 @@ let transform = (content, extClass) => {
if (idx == -1) {
return emoText;
}
let path = textToPath(emoText, true);
let path = textToPath(emoText);
let img = `<img src="${path}" class="${extClass}"/>`;
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 {

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

@ -94,7 +94,7 @@
<scroll-view v-if="chatTabBox === 'emo'" class="chat-emotion" scroll-y="true"
:style="{height: keyboardHeight+'px'}">
<view class="emotion-item-list">
<image class="emotion-item emoji-large" :title="emoText" :src="$emo.textToPath(emoText,false)"
<image class="emotion-item emoji-large" :title="emoText" :src="$emo.textToPath(emoText)"
v-for="(emoText, i) in $emo.emoTextList" :key="i" @click="selectEmoji(emoText)" mode="aspectFit"
lazy-load="true"></image>
</view>
@ -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;

Loading…
Cancel
Save