chat-item.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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-name-text">{{chat.showName}}</view>
  12. <view class="chat-time">{{$date.toTimeText(chat.lastSendTime,true)}}</view>
  13. </view>
  14. <view class="chat-content">
  15. <view class="chat-at-text">{{atText}}</view>
  16. <view class="chat-send-name" v-show="chat.sendNickName">{{chat.sendNickName+':&nbsp;'}}</view>
  17. <rich-text class="chat-content-text" :nodes="$emo.transform(chat.lastContent)"></rich-text>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. name: "chatItem",
  25. data() {
  26. return {}
  27. },
  28. props: {
  29. chat: {
  30. type: Object
  31. },
  32. index: {
  33. type: Number
  34. },
  35. active: {
  36. type: Boolean,
  37. default: false
  38. }
  39. },
  40. methods: {
  41. showChatBox() {
  42. uni.navigateTo({
  43. url: "/pages/chat/chat-box?chatIdx=" + this.index
  44. })
  45. }
  46. },
  47. computed: {
  48. atText() {
  49. if (this.chat.atMe) {
  50. return "[有人@我]"
  51. } else if (this.chat.atAll) {
  52. return "[@全体成员]"
  53. }
  54. return "";
  55. }
  56. }
  57. }
  58. </script>
  59. <style scoped lang="scss">
  60. .chat-item {
  61. height: 100rpx;
  62. display: flex;
  63. margin-bottom: 2rpx;
  64. position: relative;
  65. padding: 10rpx;
  66. padding-left: 20rpx;
  67. align-items: center;
  68. background-color: white;
  69. white-space: nowrap;
  70. &:hover {
  71. background-color: #eeeeee;
  72. }
  73. &.active {
  74. background-color: #eeeeee;
  75. }
  76. .mask {
  77. position: absolute;
  78. width: 100%;
  79. height: 100%;
  80. }
  81. .left {
  82. position: relative;
  83. display: flex;
  84. justify-content: center;
  85. align-items: center;
  86. width: 100rpx;
  87. height: 100rpx;
  88. .unread-text {
  89. position: absolute;
  90. background-color: red;
  91. right: -12rpx;
  92. top: -12rpx;
  93. color: white;
  94. border-radius: 16rpx;
  95. padding: 4rpx 12rpx;
  96. font-size: 20rpx;
  97. text-align: center;
  98. white-space: nowrap;
  99. }
  100. }
  101. .chat-right {
  102. flex: 1;
  103. display: flex;
  104. flex-direction: column;
  105. padding-left: 20rpx;
  106. text-align: left;
  107. overflow: hidden;
  108. .chat-name {
  109. display: flex;
  110. line-height: 44rpx;
  111. height: 44rpx;
  112. .chat-name-text {
  113. flex: 1;
  114. font-size: 30rpx;
  115. font-weight: 600;
  116. white-space: nowrap;
  117. overflow: hidden;
  118. }
  119. .chat-time {
  120. font-size: 26rpx;
  121. text-align: right;
  122. color: #888888;
  123. white-space: nowrap;
  124. overflow: hidden;
  125. }
  126. }
  127. .chat-content {
  128. display: flex;
  129. line-height: 60rpx;
  130. height: 60rpx;
  131. .chat-at-text {
  132. color: #c70b0b;
  133. font-size: 24rpx;
  134. }
  135. .chat-send-name {
  136. font-size: 26rpx;
  137. }
  138. .chat-content-text {
  139. flex: 1;
  140. font-size: 28rpx;
  141. white-space: nowrap;
  142. overflow: hidden;
  143. text-overflow: ellipsis;
  144. }
  145. }
  146. }
  147. }
  148. </style>