chat-item.vue 3.5 KB

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