message.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="message">
  3. <view class="message-empty" v-if="chatList.length === 0">
  4. <uv-empty icon="https://file-node.oss-cn-shanghai.aliyuncs.com/youji/fa57e25b38c442ebb0ba023cace796bb"
  5. :isImg="true" textSize="14" width="180" :text="option.tip">
  6. <view class="message-button-box">
  7. <uv-button type="primary" :text="option.btnText" size="small" v-if="option.btnText"
  8. @tap="$navigateTo('/pages/login/login')">
  9. </uv-button>
  10. </view>
  11. </uv-empty>
  12. </view>
  13. <view class="message-list" v-else>
  14. <!-- 消息提示 -->
  15. <view class="message-item" v-for="(item,index) in chatList" :key="index" @click="linkTo(item)">
  16. <view class="message-image-box">
  17. <uv-badge type="error" max="99" numberType="overflow" :value="item.unread" :absolute="true"
  18. :offset="[0,0]" :customStyle="{
  19. zIndex:99
  20. }">
  21. </uv-badge>
  22. <image :src="item.userInfo.avatarUrl" class="message-image" mode="aspectFill">
  23. </image>
  24. </view>
  25. <view class="message-content">
  26. <view class="message-title">{{item.userInfo.nickname}}</view>
  27. <view class="message-sub-content">
  28. {{item.lastMessage.type === 'image'?'[图片]':item.lastMessage.body.text}}
  29. </view>
  30. </view>
  31. <view class="message-date">
  32. <uni-dateformat class="visitor-time" :date="item.updatedAt || item.createdAt"
  33. :threshold="[60000,3600000 * 24 * 365]">
  34. </uni-dateformat>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data() {
  43. return {
  44. option: {
  45. tip: '暂无会话'
  46. },
  47. chatList: []
  48. }
  49. },
  50. onReady() {
  51. uni.$on('changeChatList', this.init);
  52. },
  53. onShow() {
  54. if (!uni.getStorageSync('token')) {
  55. this.chatList = [];
  56. this.option = {
  57. tip: '暂未登录',
  58. btnText: '点击登录'
  59. }
  60. } else {
  61. this.option = {
  62. tip: '暂无会话'
  63. }
  64. this.$chat.listenerList();
  65. this.initBadge();
  66. this.init();
  67. }
  68. },
  69. methods: {
  70. init() {
  71. this.$chat.getConversationList(data => {
  72. this.chatList = data.data.filter(node => node.conversationId !== 'system');
  73. });
  74. },
  75. linkTo(item) {
  76. if (item.unread > 0) this.$chat.clearConversationUnread(item.conversationId);
  77. this.$navigateTo('/subPages/chatPage/chat/chat?userId=' + item.conversationId + '&userName=' + item
  78. .userInfo.nickname)
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="scss" scoped>
  84. .message {
  85. padding: 30rpx 0;
  86. .message-button-box {
  87. margin-top: 40rpx;
  88. }
  89. .message-empty {
  90. padding-top: 80rpx;
  91. }
  92. .message-item {
  93. background: #fff;
  94. display: flex;
  95. padding: 24rpx 30rpx;
  96. position: relative;
  97. &::before {
  98. content: '';
  99. position: absolute;
  100. bottom: 0;
  101. right: 0;
  102. left: 150rpx;
  103. height: 2rpx;
  104. background: $uv-border-color;
  105. }
  106. }
  107. .message-image {
  108. width: 100rpx;
  109. height: 100rpx;
  110. border-radius: 16rpx;
  111. overflow: hidden;
  112. position: relative;
  113. }
  114. .message-image-box {
  115. width: 100rpx;
  116. height: 100rpx;
  117. position: relative;
  118. }
  119. .message-content {
  120. flex: 1;
  121. width: 0;
  122. margin-left: 20rpx;
  123. display: flex;
  124. flex-direction: column;
  125. justify-content: center;
  126. }
  127. .message-title {
  128. font-size: 32rpx;
  129. font-weight: 600;
  130. margin-bottom: 10rpx;
  131. }
  132. .message-sub-content {
  133. font-weight: 300;
  134. color: $uv-content-color;
  135. }
  136. .message-date {
  137. position: absolute;
  138. top: 34rpx;
  139. right: 30rpx;
  140. font-size: 24rpx;
  141. font-weight: 300;
  142. color: $uv-content-color;
  143. }
  144. }
  145. </style>