chat-item.vue 3.1 KB

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