diff --git a/src/utils/emoji.js b/src/utils/emoji.js new file mode 100644 index 0000000..aa206cf --- /dev/null +++ b/src/utils/emoji.js @@ -0,0 +1,357 @@ +export const emojiData = [ + //笑脸 + { + type: 'smiley', + name: '笑脸', + list: [ + '😀', + '😁', + '😂', + '🤣', + '😃', + '😄', + '😅', + '😆', + '😉', + '😊', + '😋', + '😎', + '😍', + '😘', + '😗', + '😙', + '😚', + '🙂', + '🤗', + '🤩', + '🤔', + '🤨', + '😐', + '😑', + '😶', + '🙄', + '😏', + '😣', + '😥', + '😮', + '🤐', + '😯', + '😪', + '😫', + '😴', + '😌', + '😛', + '😜', + '😝', + '🤤', + '😒', + '😓', + '😔', + '😕', + '🙃', + '🤑', + '😲', + '🙁', + '😖', + '😞', + '😟', + '😤', + '😢', + '😭', + '😦', + '😧', + '😨', + '😩', + '🤯', + '😬', + '😰', + '😱', + '😳', + '🤪', + '😵', + '😡', + '😠', + '🤬', + '😷', + '🤒', + '🤕', + '🤢', + '🤮', + '🤧', + '😇', + '🤠', + '🤡', + '🤥', + '🤫', + '🤭', + '🧐', + '🤓', + '😈', + '👿', + '👹', + '👺', + '💀', + '👻', + '👽', + '🤖', + '💩', + ], + }, + //手势 + { + type: 'gesture', + name: '手势', + list: [ + '🤲', + '👐', + '🙌', + '👏', + '🤝', + '👍', + '👎', + '👊', + '🤛', + '🤜', + '🤞', + '🤟', + '🤘', + '👌', + '👈', + '👉', + '👆', + '👇', + '🤚', + '🖐', + '🖖', + '👋', + '🤙', + '💪', + // "🖕", + '🙏', + ], + }, + //人物 + { + type: 'people', + name: '人物', + list: [ + '👦', + '👧', + '👨', + '👩', + '👴', + '👵', + '👶', + '👱', + '👮', + '👲', + '👳', + '👷', + '👸', + '💂', + '🎅', + '👰', + '👼', + '💆', + '💇', + '🙍', + '🙎', + '🙅', + '🙆', + '💁', + '🙋', + '🙇', + '🙌', + '🙏', + '👤', + '👥', + '🚶', + '🏃', + '👯', + '💃', + '👫', + '👬', + '👭', + '💏', + '💑', + '👪', + ], + }, + //动物 + { + type: 'animal', + name: '动物', + list: [ + '🙈', + '🙉', + '🙊', + '🐵', + '🐒', + '🐶', + '🐕', + '🐩', + '🐺', + '🐱', + '😺', + '😸', + '😹', + '😻', + '😼', + '😽', + '🙀', + '😿', + '😾', + '🐈', + '🐯', + '🐅', + '🐆', + '🐴', + '🐎', + '🐮', + '🐂', + '🐃', + '🐄', + '🐷', + '🐖', + '🐗', + '🐽', + '🐏', + '🐑', + '🐐', + '🐪', + '🐫', + '🐘', + '🐭', + '🐁', + '🐀', + '🐹', + '🐰', + '🐇', + '🐻', + '🐨', + '🐼', + '🐾', + '🐔', + '🐓', + '🐣', + '🐤', + '🐥', + '🐦', + '🐧', + '🐸', + '🐊', + '🐢', + '🐍', + '🐲', + '🐉', + '🐳', + '🐋', + '🐬', + '🐟', + '🐠', + '🐡', + '🐙', + '🐚', + '🐌', + '🐛', + '🐜', + '🐝', + '🐞', + '🦋', + '🐁', + '🐂', + '🐅', + '🐇', + '🐉', + '🐍', + '🐎', + '🐐', + '🐒', + '🐓', + '🐕', + '🐖', + ], + }, + //其他 + { + type: 'other', + name: '其他', + list: [ + '🌹', + '🍀', + '🍎', + '💰', + '📱', + '🌙', + '🍁', + '🍂', + '🍃', + '🌷', + '💎', + '🔪', + '🔫', + '🏀', + '👄', + '👍', + '🔥', + '💘', + '💓', + '💔', + '💕', + '💖', + '💗', + '💙', + '💚', + '💛', + '💜', + '💝', + '💞', + '💟', + ], + }, +]; +//emoji表情编码 +export function utf16toEntities(str) { + const patt = /[\ud800-\udbff][\udc00-\udfff]/g; // 检测utf16字符正则 + str = str.replace(patt, (char) => { + let H; + let L; + let code; + let s; + + if (char.length === 2) { + H = char.charCodeAt(0); // 取出高位 + L = char.charCodeAt(1); // 取出低位 + code = (H - 0xd800) * 0x400 + 0x10000 + L - 0xdc00; // 转换算法 + s = `&#${code};`; + } else { + s = char; + } + + return s; + }); + + return str; +} +// 表情解码 +export function entitiestoUtf16(strObj) { + const patt = /&#\d+;/g; + const arr = strObj.match(patt) || []; + + let H; + let L; + let code; + + for (let i = 0; i < arr.length; i += 1) { + code = arr[i]; + code = code.replace('&#', '').replace(';', ''); + // 高位 + H = Math.floor((code - 0x10000) / 0x400) + 0xd800; + // 低位 + L = ((code - 0x10000) % 0x400) + 0xdc00; + code = `&#${code};`; + const s = String.fromCharCode(H, L); + strObj = strObj.replace(code, s); + } + return strObj; +} diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index f42d24a..bf1c458 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -4,8 +4,8 @@
近期会话
- -
+ +
  • @@ -18,7 +18,7 @@
    {{ item.content }}
  • -
    +
    @@ -34,10 +34,15 @@
    - +
    - + +
  • + {{ entitiestoUtf16(item) }} +
  • +
    + @@ -59,6 +64,7 @@