微信emoji表情web显示

时间:2024-03-06 15:49:22

main.js注册过滤器

import {oldarr,newarr} from \'@/util/emojilist.js\'
Vue.filter("emojiText",function(str){
  // 操作新emoji
  let currentarr = newarr;
  var regx = new RegExp(/\[(.+?)\]/g);
  var firstarr = str.split(regx);
  if(firstarr){
    console.log(111);
    console.log(firstarr);
    str = \'\';
    for(var l = 0; l < firstarr.length; l++){
      for(var m = 0; m < newarr.length; m++){
        if(firstarr[l].indexOf(newarr[m].text)!=-1){
          // i--;
          firstarr[l] = firstarr[l].replace(newarr[m].text,newarr[m].icon)
          break;
        }
      }
    }

    for(var n = 0; n < firstarr.length; n++){
      str+=firstarr[n];
    }
  }
  
  // 操作旧版emoji
  let basearr = oldarr;
  var strs = str.split(\'/:\');
  if(strs.length>1){
    str = \'\';
    for(var i = 0; i < strs.length; i++){
      for(var j = 0; j < basearr.length; j++){
        if(strs[i].indexOf(basearr[j].text)!=-1){
          strs[i] = strs[i].replace(basearr[j].text,basearr[j].icon)
          break;
        }
      }
    }
    for(var k = 0; k < strs.length; k++){
      str+=strs[k];
    }
  }
  return str;
})
emojilist.js存放微信emoji列表
export let oldarr =  [
    {
      icon: "