You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chat-msg.vue 2.3 KiB

4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <view :class="[type === 'left' ? '' : 'self']" class="cu-item">
  3. <slot v-if="type === 'left'" name="avatar">
  4. <view
  5. v-if="type === 'left' && avatar"
  6. :style="{ backgroundImage: `url(${avatar})`, borderRadius: roundAvatar ? '50%' : '3px' }"
  7. class="cu-avatar radius"
  8. ></view>
  9. <image
  10. v-else-if="type === 'left' && imgAvatar"
  11. :src="imgAvatar"
  12. :style="`border-radius: ${roundAvatar ? '50%' : '3px'};` + imgStyle"
  13. mode="aspectFill"
  14. class="chat-msg-imgAvatar cu-avatar radius"
  15. ></image>
  16. <l-icon
  17. v-else-if="type === 'left' && iconAvatar"
  18. :type="iconAvatar"
  19. :style="`border-radius: ${roundAvatar ? '50%' : '3px'}; ` + iconStyle"
  20. class="chat-msg-iconAvatar flex justify-center align-center"
  21. />
  22. </slot>
  23. <view class="main">
  24. <view
  25. :class="[type === 'left' ? (leftColor ? 'bg-' + leftColor : '') : rightColor ? 'bg-' + rightColor : '']"
  26. class="content shadow"
  27. >
  28. <text style="word-break: break-all;">
  29. <slot>{{ content }}</slot>
  30. </text>
  31. </view>
  32. </view>
  33. <slot v-if="type !== 'left'" name="avatar">
  34. <view
  35. v-if="type !== 'left' && avatar"
  36. :style="{ backgroundImage: `url(${avatar})`, borderRadius: roundAvatar ? '50%' : '3px' }"
  37. class="cu-avatar radius"
  38. ></view>
  39. <image
  40. v-else-if="type !== 'left' && imgAvatar"
  41. :src="imgAvatar"
  42. :style="`border-radius: ${roundAvatar ? '50%' : '3px'};` + imgStyle"
  43. mode="aspectFill"
  44. class="chat-msg-imgAvatar cu-avatar radius"
  45. ></image>
  46. <l-icon
  47. v-else-if="type !== 'left' && iconAvatar"
  48. :type="iconAvatar"
  49. :style="`border-radius: ${roundAvatar ? '50%' : '3px'}; ` + iconStyle"
  50. class="chat-msg-iconAvatar flex justify-center align-center"
  51. />
  52. </slot>
  53. <view class="date">
  54. <slot name="date">{{ date }}</slot>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. export default {
  60. name: 'l-chat-msg',
  61. props: {
  62. content: {},
  63. type: { default: 'left' },
  64. roundAvatar: {},
  65. date: {},
  66. leftColor: {},
  67. rightColor: { default: 'green' },
  68. avatar: {},
  69. iconAvatar: {},
  70. iconStyle: { default: '' },
  71. imgAvatar: {},
  72. imgStyle: { default: '' }
  73. }
  74. }
  75. </script>