message-bubble.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <view class="message-bubble" :class="[message.flow === 'in' ? '' : 'reverse']">
  3. <image class="avatar" :src="message?.avatar || 'https://web.sdk.qcloud.com/component/TUIKit/assets/avatar_21.png'"
  4. alt=""></image>
  5. <view class="message-area">
  6. <label class="name" v-if="message.flow === 'in'">{{ message.nick }}</label>
  7. <div :class="['content content-' + message.flow]">
  8. <slot />
  9. </div>
  10. </view>
  11. <view class="message-label fail" v-if="message.status === 'fail'">!</view>
  12. <view class="message-label" :class="[!message.isPeerRead && 'unRead']"
  13. v-if="message.conversationType === 'C2C' && message.flow == 'out' && message.status !== 'fail'">
  14. <span v-if="!message.isPeerRead">未读</span>
  15. <span v-else>已读</span>
  16. </view>
  17. </view>
  18. </template>
  19. <script lang="ts">
  20. import { defineComponent, watchEffect, reactive, toRefs, computed } from 'vue';
  21. const messageBubble = defineComponent({
  22. props: {
  23. data: {
  24. type: Object,
  25. default: () => {
  26. return {};
  27. }
  28. },
  29. },
  30. setup(props: any, ctx: any) {
  31. const data = reactive({
  32. message: {},
  33. show: false,
  34. });
  35. watchEffect(() => {
  36. data.message = props.data;
  37. });
  38. const toggleDialog = () => {
  39. data.show = !data.show;
  40. };
  41. return {
  42. ...toRefs(data),
  43. toggleDialog,
  44. };
  45. }
  46. });
  47. export default messageBubble;
  48. </script>
  49. <style lang="scss" scoped>
  50. .reverse {
  51. flex-direction: row-reverse;
  52. justify-content: flex-start;
  53. }
  54. .avatar {
  55. width: 36px;
  56. height: 36px;
  57. border-radius: 5px;
  58. }
  59. .message-bubble {
  60. width: 100%;
  61. display: flex;
  62. padding: 8px;
  63. box-sizing: border-box;
  64. }
  65. .message-area {
  66. max-width: 74%;
  67. display: flex;
  68. flex-direction: column;
  69. padding: 0 8px;
  70. word-break: break-all;
  71. .name {
  72. font-weight: 400;
  73. font-size: 12px;
  74. color: #999999;
  75. letter-spacing: 0;
  76. }
  77. .content {
  78. // padding: 12px;
  79. font-weight: 400;
  80. font-size: 14px;
  81. color: #000000;
  82. letter-spacing: 0;
  83. position: relative;
  84. font-family: PingFangSC-Regular;
  85. &-in {
  86. // background: #FBFBFB;
  87. border-radius: 0px 10px 10px 10px;
  88. }
  89. &-out {
  90. // background: #DCEAFD;
  91. border-radius: 10px 0px 10px 10px;
  92. }
  93. }
  94. }
  95. .message-label {
  96. align-self: flex-end;
  97. font-family: PingFangSC-Regular;
  98. font-weight: 400;
  99. font-size: 12px;
  100. color: #B6B8BA;
  101. }
  102. .fail {
  103. width: 15px;
  104. height: 15px;
  105. border-radius: 15px;
  106. background: red;
  107. color: #FFFFFF;
  108. display: flex;
  109. justify-content: center;
  110. align-items: center;
  111. }
  112. .unRead {
  113. color: #679CE1;
  114. }
  115. </style>