chat-item.vue 3.7 KB

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