m-text.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. props: {
  17. isMy: {
  18. type: [Boolean, Number],
  19. default: false
  20. },
  21. value: {
  22. type: Object,
  23. default: {}
  24. }
  25. },
  26. data() {
  27. return {};
  28. },
  29. created() {},
  30. computed: {
  31. //渲染文本消息,如果包含表情,替换为图片
  32. //todo:本不需要该方法,可以在标签里完成,但小程序有兼容性问题,被迫这样实现
  33. renderTextMessage() {
  34. let { text = '' } = this.value.payload;
  35. text = text.replace(/\n/g, '');
  36. if (!text) return '<span>' + '[未知内容]' + '</span>';
  37. return '<span>' + decoder.decode(text) + '</span>';
  38. }
  39. },
  40. methods: {}
  41. };
  42. </script>
  43. <style scoped lang="scss">
  44. .quote-box {
  45. box-sizing: border-box;
  46. padding: 12rpx 16rpx;
  47. border-radius: 10rpx;
  48. margin-top: 6rpx;
  49. background-color: #e1e1e1;
  50. color: #6b6b6b;
  51. }
  52. .quote-name {
  53. }
  54. .quote-content {
  55. }
  56. </style>