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.
 
 
 
 
 
 

102 lines
3.0 KiB

  1. <template>
  2. <view :class="[type === 'left' ? '' : 'self', className]" :style="style" 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. <text
  17. v-else-if="type === 'left' && iconAvatar"
  18. :class="'cuIcon-' + iconAvatar"
  19. :style="`border-radius: ${roundAvatar ? '50%' : '3px'}; ` + iconStyle"
  20. class="chat-msg-iconAvatar flex justify-center align-center"
  21. ></text>
  22. <!-- 支付宝小程序,使用 l-icon 报错 -->
  23. <!--
  24. <l-icon
  25. v-else-if="type === 'left' && iconAvatar"
  26. :type="iconAvatar"
  27. :style="`border-radius: ${roundAvatar ? '50%' : '3px'}; ` + iconStyle"
  28. class="chat-msg-iconAvatar flex justify-center align-center"
  29. />
  30. -->
  31. </slot>
  32. <view class="main">
  33. <view
  34. :class="[type === 'left' ? (leftColor ? 'bg-' + leftColor : '') : rightColor ? 'bg-' + rightColor : '']"
  35. class="content shadow"
  36. >
  37. <text style="word-break: break-all;">
  38. <slot></slot>
  39. {{ content }}
  40. </text>
  41. </view>
  42. </view>
  43. <slot v-if="type !== 'left'" name="avatar">
  44. <view
  45. v-if="type !== 'left' && avatar"
  46. :style="{ backgroundImage: `url(${avatar})`, borderRadius: roundAvatar ? '50%' : '3px' }"
  47. class="cu-avatar radius"
  48. ></view>
  49. <image
  50. v-else-if="type !== 'left' && imgAvatar"
  51. :src="imgAvatar"
  52. :style="`border-radius: ${roundAvatar ? '50%' : '3px'};` + imgStyle"
  53. mode="aspectFill"
  54. class="chat-msg-imgAvatar cu-avatar radius"
  55. ></image>
  56. <text
  57. v-else-if="type !== 'left' && iconAvatar"
  58. :class="'cuIcon-' + iconAvatar"
  59. :style="`border-radius: ${roundAvatar ? '50%' : '3px'}; ` + iconStyle"
  60. class="chat-msg-iconAvatar flex justify-center align-center"
  61. ></text>
  62. <!-- 支付宝小程序,使用 l-icon 报错 -->
  63. <!--
  64. <l-icon
  65. v-else-if="type !== 'left' && iconAvatar"
  66. :type="iconAvatar"
  67. :style="`border-radius: ${roundAvatar ? '50%' : '3px'}; ` + iconStyle"
  68. class="chat-msg-iconAvatar flex justify-center align-center"
  69. />
  70. -->
  71. </slot>
  72. <view class="date">
  73. <slot name="date">{{ date }}</slot>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. export default {
  79. name: 'l-chat-msg',
  80. props: {
  81. content: { default: '' },
  82. type: { default: 'left' },
  83. roundAvatar: {},
  84. date: {},
  85. leftColor: {},
  86. rightColor: { default: 'green' },
  87. avatar: {},
  88. iconAvatar: {},
  89. iconStyle: { default: '' },
  90. imgAvatar: {},
  91. imgStyle: { default: '' }
  92. }
  93. }
  94. </script>