content-parser.js 878 B

1
  1. import emotion from"../../../common/chat/emotionList";const emotionUrl={};emotion.forEach((t=>{emotionUrl[t.title]="https:"+t.url})),Component({options:{styleIsolation:"shared"},properties:{content:{type:[String,Object],observer(t,e){t&&t!==e&&"string"==typeof t&&this.setData({contentArr:this.parseEmotion(t)})}}},data:{contentArr:[]},methods:{tapImage(){const t=this.data.content.uploadImgUrl;wx.previewImage({urls:[t],current:t})},parseEmotion(t){let e=t;if("string"!=typeof e||!e)return[];e=e.replace(/&lt;/g,"<").replace(/&gt;/g,">");const o=[];for(;-1!==e.indexOf("[");){const t=e.indexOf("["),n=e.indexOf("]",t+1);if(-1===n)break;o.push({type:"text",content:e.substring(0,t)});const r=e.substring(t+1,n),s={type:"em",content:r};emotionUrl[r]?s.url=emotionUrl[r]:(s.type="text",s.content=`[${r}]`),o.push(s),e=e.substring(n+1)}return o.push({type:"text",content:e}),o}}});