m-text.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <view>
  3. <view class="quote-names">
  4. <text v-html="renderTextMessage(value.content)"></text>
  5. </view>
  6. </view>
  7. </template>
  8. <script>
  9. import { EmojiDecoder, emojiMap } from '@/utils/EmojiDecoder.js';
  10. const emojiUrl = 'https://imgcache.qq.com/open/qcloud/tim/assets/emoji/';
  11. const decoder = new EmojiDecoder(emojiUrl, emojiMap);
  12. export default {
  13. name: 'mText',
  14. props: {
  15. value: {
  16. type: Object,
  17. default: {}
  18. }
  19. },
  20. data() {
  21. return {};
  22. },
  23. // computed: {
  24. // //渲染文本消息,如果包含表情,替换为图片
  25. // //todo:本不需要该方法,可以在标签里完成,但小程序有兼容性问题,被迫这样实现
  26. // renderTextMessage() {
  27. // let text = this.value.content;
  28. // text = text.replace(/\n/g, '');
  29. // if (!text) return '<span>' + '[未知内容]' + '</span>';
  30. // return '<span>' + decoder.decode(text) + '</span>';
  31. // }
  32. // },
  33. methods: {
  34. renderTextMessage(text) {
  35. console.log('text',text)
  36. // let text = this.value.content;
  37. text = text.replace(/\n/g, '');
  38. if (!text) return '<span>' + '[未知内容]' + '</span>';
  39. return '<span>' + decoder.decode(text) + '</span>';
  40. }
  41. }
  42. };
  43. </script>
  44. <style scoped lang="scss">
  45. .quote-box {
  46. box-sizing: border-box;
  47. padding: 12rpx 16rpx;
  48. border-radius: 10rpx;
  49. margin-top: 6rpx;
  50. background-color: #e1e1e1;
  51. color: #6b6b6b;
  52. }
  53. .quote-name {
  54. }
  55. .quote-content {
  56. }
  57. </style>