message.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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="28" width="360" :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.init();
  66. }
  67. },
  68. methods: {
  69. init() {
  70. this.$chat.getConversationList(data => {
  71. this.chatList = data.data.filter(node => node.conversationId !== 'system');
  72. });
  73. },
  74. linkTo(item) {
  75. if (item.unread > 0) this.$chat.clearConversationUnread(item.conversationId);
  76. this.$navigateTo('/subPages/chatPage/chat/chat?userId=' + item.conversationId + '&userName=' + item
  77. .userInfo.nickname)
  78. }
  79. }
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. .message {
  84. padding: 30rpx 0;
  85. .message-button-box {
  86. margin-top: 40rpx;
  87. }
  88. .message-empty {
  89. padding-top: 80rpx;
  90. }
  91. .message-item {
  92. background: #fff;
  93. display: flex;
  94. padding: 24rpx 30rpx;
  95. position: relative;
  96. &::before {
  97. content: '';
  98. position: absolute;
  99. bottom: 0;
  100. right: 0;
  101. left: 150rpx;
  102. height: 2rpx;
  103. background: $uv-border-color;
  104. }
  105. }
  106. .message-image {
  107. width: 100rpx;
  108. height: 100rpx;
  109. border-radius: 16rpx;
  110. overflow: hidden;
  111. position: relative;
  112. }
  113. .message-image-box {
  114. width: 100rpx;
  115. height: 100rpx;
  116. position: relative;
  117. }
  118. .message-content {
  119. flex: 1;
  120. width: 0;
  121. margin-left: 20rpx;
  122. display: flex;
  123. flex-direction: column;
  124. justify-content: center;
  125. }
  126. .message-title {
  127. font-size: 32rpx;
  128. font-weight: 600;
  129. margin-bottom: 10rpx;
  130. }
  131. .message-sub-content {
  132. font-weight: 300;
  133. color: $uv-content-color;
  134. }
  135. .message-date {
  136. position: absolute;
  137. top: 34rpx;
  138. right: 30rpx;
  139. font-size: 24rpx;
  140. font-weight: 300;
  141. color: $uv-content-color;
  142. }
  143. }
  144. </style>