chat-item.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view class="chat-item" :class="active?'active':''">
  3. <!--rich-text中的表情包会屏蔽事件,所以这里用一个遮罩层捕获点击事件 -->
  4. <view class="mask" @tap="showChatBox()"></view>
  5. <view class="left">
  6. <head-image :url="chat.headImage" :name="chat.showName" :size="90"></head-image>
  7. </view>
  8. <view class="chat-right">
  9. <view class="chat-name">
  10. <view class="chat-tag" v-if="chat.type=='GROUP'">
  11. <uni-tag disabled text="群" size="mini" type="primary"></uni-tag>
  12. </view>
  13. <view class="chat-name-text">
  14. {{chat.showName}}
  15. </view>
  16. <view class="chat-time">{{$date.toTimeText(chat.lastSendTime,true)}}</view>
  17. </view>
  18. <view class="chat-content">
  19. <view class="chat-at-text">{{atText}}</view>
  20. <view class="chat-send-name" v-if="isShowSendName">{{chat.sendNickName+':&nbsp;'}}</view>
  21. <rich-text class="chat-content-text" :nodes="$emo.transform(chat.lastContent)"></rich-text>
  22. <uni-badge v-if="chat.unreadCount>0" size="small" :max-num="99" :text="chat.unreadCount" />
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. name: "chatItem",
  30. data() {
  31. return {}
  32. },
  33. props: {
  34. chat: {
  35. type: Object
  36. },
  37. index: {
  38. type: Number
  39. },
  40. active: {
  41. type: Boolean,
  42. default: false
  43. }
  44. },
  45. methods: {
  46. showChatBox() {
  47. uni.navigateTo({
  48. url: "/pages/chat/chat-box?chatIdx=" + this.index
  49. })
  50. }
  51. },
  52. computed: {
  53. isShowSendName() {
  54. if (!this.chat.sendNickName) {
  55. return false;
  56. }
  57. let size = this.chat.messages.length;
  58. if (size == 0) {
  59. return false;
  60. }
  61. // 只有群聊的普通消息需要显示名称
  62. let lastMsg = this.chat.messages[size - 1];
  63. return this.$msgType.isNormal(lastMsg.type)
  64. },
  65. atText() {
  66. if (this.chat.atMe) {
  67. return "[有人@我]"
  68. } else if (this.chat.atAll) {
  69. return "[@全体成员]"
  70. }
  71. return "";
  72. }
  73. }
  74. }
  75. </script>
  76. <style scoped lang="scss">
  77. .chat-item {
  78. height: 100rpx;
  79. display: flex;
  80. margin-bottom: 2rpx;
  81. position: relative;
  82. padding: 10rpx 20rpx;
  83. align-items: center;
  84. background-color: white;
  85. white-space: nowrap;
  86. &:hover {
  87. background-color: #f5f6ff;
  88. }
  89. &.active {
  90. background-color: #f5f6ff;
  91. }
  92. .mask {
  93. position: absolute;
  94. width: 100%;
  95. height: 100%;
  96. z-index: 99;
  97. }
  98. .left {
  99. position: relative;
  100. display: flex;
  101. justify-content: center;
  102. align-items: center;
  103. width: 100rpx;
  104. height: 100rpx;
  105. }
  106. .chat-right {
  107. flex: 1;
  108. display: flex;
  109. flex-direction: column;
  110. padding-left: 20rpx;
  111. text-align: left;
  112. overflow: hidden;
  113. .chat-name {
  114. display: flex;
  115. line-height: 44rpx;
  116. height: 44rpx;
  117. .chat-tag {
  118. display: flex;
  119. align-items: center;
  120. margin-right: 5rpx;
  121. }
  122. .chat-name-text {
  123. flex: 1;
  124. font-size: 30rpx;
  125. font-weight: 600;
  126. white-space: nowrap;
  127. overflow: hidden;
  128. }
  129. .chat-time {
  130. font-size: 26rpx;
  131. text-align: right;
  132. color: #888888;
  133. white-space: nowrap;
  134. overflow: hidden;
  135. }
  136. }
  137. .chat-content {
  138. display: flex;
  139. line-height: 60rpx;
  140. height: 60rpx;
  141. .chat-at-text {
  142. color: #c70b0b;
  143. font-size: 24rpx;
  144. }
  145. .chat-send-name {
  146. font-size: 26rpx;
  147. }
  148. .chat-content-text {
  149. flex: 1;
  150. font-size: 28rpx;
  151. white-space: nowrap;
  152. overflow: hidden;
  153. text-overflow: ellipsis;
  154. }
  155. }
  156. }
  157. }
  158. </style>