text-element.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <message-bubble :isMine=isMine :message=message>
  3. <template v-for="(item, index) in contentList">
  4. <span class="text-box" :key="index" v-if="item.name === 'text'">{{ item.text }}</span>
  5. <img v-else-if="item.name === 'img'" :src="item.src" width="20px" height="20px" :key="index"/>
  6. </template>
  7. </message-bubble>
  8. <!-- <div class="chat-bubble">
  9. <div class="message-content" :class="isMine ? 'message-send' : 'message-received'">
  10. <template v-for="(item, index) in contentList">
  11. <span :key="index" v-if="item.name === 'text'">{{ item.text }}</span>
  12. <img v-else-if="item.name === 'img'" :src="item.src" width="20px" height="20px" :key="index"/>
  13. </template>
  14. </div>
  15. </div> -->
  16. </template>
  17. <script>
  18. import MessageBubble from '../message-bubble'
  19. import { decodeText } from '../../../utils/decodeText'
  20. export default {
  21. name: 'TextElement',
  22. components: {
  23. MessageBubble
  24. },
  25. props: {
  26. payload: {
  27. type: Object,
  28. required: true
  29. },
  30. message: {
  31. type: Object,
  32. required: true
  33. },
  34. isMine: {
  35. type: Boolean
  36. }
  37. },
  38. computed: {
  39. contentList() {
  40. if (this.message.contentType===101){
  41. return decodeText(this.payload)
  42. }
  43. }
  44. }
  45. }
  46. </script>
  47. <style lang="stylus" scoped>
  48. .text-box{
  49. display: inline-block;
  50. width: 100%;
  51. overflow: hidden;
  52. }
  53. // .chat-bubble
  54. // position relative
  55. // .message-content
  56. // font-size 14px
  57. // position relative
  58. // max-width 350px
  59. // word-wrap break-word
  60. // word-break break-all
  61. // padding 10px
  62. // span
  63. // white-space pre-wrap
  64. // margin 0
  65. // text-shadow $regular 0 0 0.05em
  66. // &::before
  67. // position: absolute
  68. // top: 0
  69. // width: 12px
  70. // height: 40px
  71. // content "\e900"
  72. // font-family 'tim' !important
  73. // font-size 24px // 32px 在mac上会模糊 24px正常
  74. // .message-received
  75. // background-color $white
  76. // margin-left 15px
  77. // border-radius 0 4px 4px 4px
  78. // &::before
  79. // left -10px
  80. // transform scaleX(-1)
  81. // color $white
  82. // &.new
  83. // transform: scale(0);
  84. // transform-origin: top left;
  85. // animation: bounce 500ms linear both;
  86. // .message-send
  87. // background-color $light-primary
  88. // margin-right 15px
  89. // border-radius 4px 0 4px 4px
  90. // color $white
  91. // &::before
  92. // right: -10px
  93. // color $light-primary
  94. // &.new
  95. // transform: scale(0);
  96. // transform-origin: top right;
  97. // animation: bounce 500ms linear both;
  98. // @keyframes bounce {
  99. // 0% { transform: matrix3d(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
  100. // 4.7% { transform: matrix3d(0.45, 0, 0, 0, 0, 0.45, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
  101. // 9.41% { transform: matrix3d(0.883, 0, 0, 0, 0, 0.883, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
  102. // 14.11% { transform: matrix3d(1.141, 0, 0, 0, 0, 1.141, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
  103. // 18.72% { transform: matrix3d(1.212, 0, 0, 0, 0, 1.212, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
  104. // 24.32% { transform: matrix3d(1.151, 0, 0, 0, 0, 1.151, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
  105. // 29.93% { transform: matrix3d(1.048, 0, 0, 0, 0, 1.048, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
  106. // 35.54% { transform: matrix3d(0.979, 0, 0, 0, 0, 0.979, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
  107. // 41.04% { transform: matrix3d(0.961, 0, 0, 0, 0, 0.961, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
  108. // 52.15% { transform: matrix3d(0.991, 0, 0, 0, 0, 0.991, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
  109. // 63.26% { transform: matrix3d(1.007, 0, 0, 0, 0, 1.007, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
  110. // 85.49% { transform: matrix3d(0.999, 0, 0, 0, 0, 0.999, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
  111. // 100% { transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
  112. // }
  113. </style>