chat-item.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. }
  97. .left {
  98. position: relative;
  99. display: flex;
  100. justify-content: center;
  101. align-items: center;
  102. width: 100rpx;
  103. height: 100rpx;
  104. }
  105. .chat-right {
  106. flex: 1;
  107. display: flex;
  108. flex-direction: column;
  109. padding-left: 20rpx;
  110. text-align: left;
  111. overflow: hidden;
  112. .chat-name {
  113. display: flex;
  114. line-height: 44rpx;
  115. height: 44rpx;
  116. .chat-tag {
  117. display: flex;
  118. align-items: center;
  119. margin-right: 5rpx;
  120. }
  121. .chat-name-text {
  122. flex: 1;
  123. font-size: 30rpx;
  124. font-weight: 600;
  125. white-space: nowrap;
  126. overflow: hidden;
  127. }
  128. .chat-time {
  129. font-size: 26rpx;
  130. text-align: right;
  131. color: #888888;
  132. white-space: nowrap;
  133. overflow: hidden;
  134. }
  135. }
  136. .chat-content {
  137. display: flex;
  138. line-height: 60rpx;
  139. height: 60rpx;
  140. .chat-at-text {
  141. color: #c70b0b;
  142. font-size: 24rpx;
  143. }
  144. .chat-send-name {
  145. font-size: 26rpx;
  146. }
  147. .chat-content-text {
  148. flex: 1;
  149. font-size: 28rpx;
  150. white-space: nowrap;
  151. overflow: hidden;
  152. text-overflow: ellipsis;
  153. }
  154. }
  155. }
  156. }
  157. </style>