chat-item.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 v-if="chat.unreadCount>0" class="unread-text">{{chat.unreadCount}}</view>
  8. </view>
  9. <view class="chat-right">
  10. <view class="chat-name">
  11. <view class="chat-tag" v-if="chat.type=='GROUP'">
  12. <uni-tag circle text="群" size="mini" type="primary"></uni-tag>
  13. </view>
  14. <view class="chat-name-text">
  15. {{chat.showName}}
  16. </view>
  17. <view class="chat-time">{{$date.toTimeText(chat.lastSendTime,true)}}</view>
  18. </view>
  19. <view class="chat-content">
  20. <view class="chat-at-text">{{atText}}</view>
  21. <view class="chat-send-name" v-show="chat.sendNickName">{{chat.sendNickName+':&nbsp;'}}</view>
  22. <rich-text class="chat-content-text" :nodes="$emo.transform(chat.lastContent)"></rich-text>
  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. atText() {
  54. if (this.chat.atMe) {
  55. return "[有人@我]"
  56. } else if (this.chat.atAll) {
  57. return "[@全体成员]"
  58. }
  59. return "";
  60. }
  61. }
  62. }
  63. </script>
  64. <style scoped lang="scss">
  65. .chat-item {
  66. height: 100rpx;
  67. display: flex;
  68. margin-bottom: 2rpx;
  69. position: relative;
  70. padding: 10rpx 20rpx;
  71. align-items: center;
  72. background-color: white;
  73. white-space: nowrap;
  74. &:hover {
  75. background-color: #f5f6ff;
  76. }
  77. &.active {
  78. background-color: #f5f6ff;
  79. }
  80. .mask {
  81. position: absolute;
  82. width: 100%;
  83. height: 100%;
  84. }
  85. .left {
  86. position: relative;
  87. display: flex;
  88. justify-content: center;
  89. align-items: center;
  90. width: 100rpx;
  91. height: 100rpx;
  92. .unread-text {
  93. position: absolute;
  94. background-color: red;
  95. right: -12rpx;
  96. top: -12rpx;
  97. color: white;
  98. border-radius: 16rpx;
  99. padding: 4rpx 12rpx;
  100. font-size: 20rpx;
  101. text-align: center;
  102. white-space: nowrap;
  103. }
  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: 3rpx;
  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>