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