diff --git a/src/js/utils/emojis.js b/src/js/utils/emojis.js index 4301011..efa183a 100644 --- a/src/js/utils/emojis.js +++ b/src/js/utils/emojis.js @@ -1,174 +1,105 @@ export const emojis = { - '[微笑]': - "[微笑]", - '[撇嘴]': - "[撇嘴]", - '[色]': - "[色]", - '[发呆]': - "[发呆]", - '[得意]': - "[得意]", - '[流泪]': - "[流泪]", - '[害羞]': - "[害羞]", - '[闭嘴]': - "[闭嘴]", - '[睡]': - "[睡]", - '[大哭]': - "[大哭]", - '[尴尬]': - "[尴尬]", - '[发怒]': - "[发怒]", - '[调皮]': - "[调皮]", - '[呲牙]': - "[呲牙]", - '[惊讶]': - "[惊讶]", - '[难过]': - "[难过]", - '[酷]': - "[酷]", - '[冷汗]': - "[冷汗]", - '[抓狂]': - "[抓狂]", - '[吐]': - "[吐]", - '[偷笑]': - "[偷笑]", - '[可爱]': - "[可爱]", - '[白眼]': - "[白眼]", - '[傲慢]': - "[傲慢]", - '[饥饿]': - "[饥饿]", - '[困]': - "[困]", - '[惊恐]': - "[惊恐]", - '[流汗]': - "[流汗]", - '[憨笑]': - "[憨笑]", - '[大兵]': - "[大兵]", - '[奋斗]': - "[奋斗]", - '[咒骂]': - "[咒骂]", - '[疑问]': - "[疑问]", - '[嘘]': - "[嘘]", - '[晕]': - "[晕]", - '[折磨]': - "[折磨]", - '[衰]': - "[衰]", - '[骷髅]': - "[骷髅]", - '[敲打]': - "[敲打]", - '[再见]': - "[再见]", - '[擦汗]': - "[擦汗]", - '[抠鼻]': - "[抠鼻]", - '[鼓掌]': - "[鼓掌]", - '[糗大了]': - "[糗大了]", - '[坏笑]': - "[坏笑]", - '[左哼哼]': - "[左哼哼]", - '[右哼哼]': - "[右哼哼]", - '[哈欠]': - "[哈欠]", - '[鄙视]': - "[鄙视]", - '[委屈]': - "[委屈]", - '[快哭了]': - "[快哭了]", - '[阴险]': - "[阴险]", - '[亲亲]': - "[亲亲]", - '[吓]': - "[吓]", - '[可怜]': - "[可怜]", - '[菜刀]': - "[菜刀]", - '[西瓜]': - "[西瓜]", - '[啤酒]': - "[啤酒]", - '[篮球]': - "[篮球]", - '[咖啡]': - "[咖啡]", - '[饭]': - "[饭]", - '[玫瑰]': - "[玫瑰]", - '[凋谢]': - "[凋谢]", - '[示爱]': - "[示爱]", - '[爱心]': - "[爱心]", - '[心碎]': - "[心碎]", - '[蛋糕]': - "[蛋糕]", - '[炸弹]': - "[炸弹]", - '[刀]': - "[刀]", - '[足球]': - "[足球]", - '[礼物]': - "[礼物]", - '[拥抱]': - "[拥抱]", - '[强]': - "[强]", - '[弱]': - "[弱]", - '[握手]': - "[握手]", - '[胜利]': - "[胜利]", - '[抱拳]': - "[抱拳]", - '[勾引]': - "[勾引]", - '[拳头]': - "[拳头]", - '[差劲]': - "[差劲]", - '[爱你]': - "[爱你]", - '[NO]': - "[NO]", - '[OK]': - "[OK]" + '[微笑]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/0.gif', + '[撇嘴]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/1.gif', + '[色]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/2.gif', + '[发呆]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/3.gif', + '[得意]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/4.gif', + '[流泪]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/5.gif', + '[害羞]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/6.gif', + '[闭嘴]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/7.gif', + '[睡]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/8.gif', + '[大哭]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/9.gif', + '[尴尬]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/10.gif', + '[发怒]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/11.gif', + '[调皮]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/12.gif', + '[呲牙]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/13.gif', + '[惊讶]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/14.gif', + '[难过]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/15.gif', + '[酷]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/16.gif', + '[冷汗]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/17.gif', + '[抓狂]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/18.gif', + '[吐]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/19.gif', + '[偷笑]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/20.gif', + '[可爱]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/21.gif', + '[白眼]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/22.gif', + '[傲慢]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/23.gif', + '[饥饿]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/24.gif', + '[困]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/25.gif', + '[惊恐]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/26.gif', + '[流汗]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/27.gif', + '[憨笑]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/28.gif', + '[大兵]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/29.gif', + '[奋斗]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/30.gif', + '[咒骂]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/31.gif', + '[疑问]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/32.gif', + '[嘘]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/33.gif', + '[晕]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/34.gif', + '[折磨]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/35.gif', + '[衰]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/36.gif', + '[骷髅]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/37.gif', + '[敲打]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/38.gif', + '[再见]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/39.gif', + '[擦汗]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/40.gif', + '[抠鼻]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/41.gif', + '[鼓掌]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/42.gif', + '[糗大了]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/43.gif', + '[坏笑]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/44.gif', + '[左哼哼]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/45.gif', + '[右哼哼]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/46.gif', + '[哈欠]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/47.gif', + '[鄙视]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/48.gif', + '[委屈]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/49.gif', + '[快哭了]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/50.gif', + '[阴险]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/51.gif', + '[亲亲]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/52.gif', + '[吓]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/53.gif', + '[可怜]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/54.gif', + '[菜刀]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/55.gif', + '[西瓜]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/56.gif', + '[啤酒]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/57.gif', + '[篮球]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/58.gif', + '[咖啡]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/60.gif', + '[饭]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/61.gif', + '[玫瑰]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/63.gif', + '[凋谢]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/64.gif', + '[示爱]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/65.gif', + '[爱心]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/66.gif', + '[心碎]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/67.gif', + '[蛋糕]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/68.gif', + '[炸弹]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/70.gif', + '[刀]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/71.gif', + '[足球]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/72.gif', + '[礼物]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/77.gif', + '[拥抱]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/78.gif', + '[强]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/79.gif', + '[弱]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/80.gif', + '[握手]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/81.gif', + '[胜利]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/82.gif', + '[抱拳]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/83.gif', + '[勾引]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/84.gif', + '[拳头]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/85.gif', + '[差劲]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/86.gif', + '[爱你]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/87.gif', + '[NO]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/88.gif', + '[OK]': 'https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/89.gif' } /** - * 把消息内容中的"[xxx]"替换为img标签 + * 组装一个emoji的img元素 + * @param {*} emojiId + * @returns + */ +export const getEmojiHtml = (emojiId) => { + const url = emojis[emojiId] + if (url) { + return `${emojiId}` + } else { + return emojiId + } +} + +/** + * 把消息内容中的"[xxx]"替换为img html元素 * @param {*} content 消息内容 */ export const emojiTrans = (content) => { @@ -179,8 +110,11 @@ export const emojiTrans = (content) => { } new Set(matches).forEach((item) => { - const emoji = emojis[item] - content = emoji ? content.replaceAll(item, emoji) : content + const url = emojis[item] + if (url) { + const emojiHtml = `${item}` + content = content.replaceAll(item, emojiHtml) + } }) return content diff --git a/src/stores/image.js b/src/stores/image.js index 1309257..c68fea3 100644 --- a/src/stores/image.js +++ b/src/stores/image.js @@ -14,8 +14,17 @@ export const imageStore = defineStore('anyim-image', () => { */ const image = ref({}) - const setImage = (obj) => { + /** + * 在同一个session中的image(id)集合 + */ + const imageInSession = ref({}) + + const setImage = (sessionId, obj) => { image.value[obj.objectId] = obj + if (!imageInSession.value[sessionId]) { + imageInSession.value[sessionId] = [] + } + imageInSession.value[sessionId].push(obj.objectId) } const imageTrans = (content, maxWidth = 400, maxHeight = 300) => { @@ -29,9 +38,10 @@ export const imageStore = defineStore('anyim-image', () => { let endIndex = item.indexOf('}') const objectId = item.slice(startIndex + 1, endIndex) const thumbUrl = image.value[objectId]?.thumbUrl + const originUrl = image.value[objectId]?.originUrl if (thumbUrl) { const imageHtml = - `{${objectId}}` content = content.replaceAll(item, imageHtml) } @@ -63,6 +73,7 @@ export const imageStore = defineStore('anyim-image', () => { return { image, + imageInSession, setImage, imageTrans, getImageFromContent diff --git a/src/stores/message.js b/src/stores/message.js index 4b3ae0c..310d717 100644 --- a/src/stores/message.js +++ b/src/stores/message.js @@ -157,7 +157,7 @@ export const messageStore = defineStore('anyim-message', () => { if (imageIds.size > 0) { mtsImageService({ objectIds: [...imageIds].join(',') }).then((res) => { res.data.data.forEach((item) => { - imageStore().setImage(item) // 缓存image数据 + imageStore().setImage(sessionId, item) // 缓存image数据 }) }) } diff --git a/src/views/message/components/EmojiBox.vue b/src/views/message/components/EmojiBox.vue index 167839f..2562cff 100644 --- a/src/views/message/components/EmojiBox.vue +++ b/src/views/message/components/EmojiBox.vue @@ -1,6 +1,6 @@