chat-item.vue 3.5 KB

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