m-text.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <view class="quote-box">
  3. <view class="quote-name">
  4. <text>
  5. {{ value.senderData.name }}:
  6. <text v-html="renderTextMessage"></text>
  7. </text>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import { EmojiDecoder, emojiMap } from '@/utils/EmojiDecoder.js';
  13. const emojiUrl = 'https://imgcache.qq.com/open/qcloud/tim/assets/emoji/';
  14. const decoder = new EmojiDecoder(emojiUrl, emojiMap);
  15. export default {
  16. name: 'mSubText',
  17. props: {
  18. isMy: {
  19. type: [Boolean, Number],
  20. default: false
  21. },
  22. value: {
  23. type: Object,
  24. default: {}
  25. }
  26. },
  27. data() {
  28. return {};
  29. },
  30. created() {},
  31. computed: {
  32. //渲染文本消息,如果包含表情,替换为图片
  33. //todo:本不需要该方法,可以在标签里完成,但小程序有兼容性问题,被迫这样实现
  34. renderTextMessage() {
  35. let { text = '' } = this.value.payload;
  36. text = text.replace(/\n/g, '');
  37. if (!text) return '<span>' + '[未知内容]' + '</span>';
  38. return '<span>' + decoder.decode(text) + '</span>';
  39. }
  40. },
  41. methods: {}
  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>