message.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="message">
  3. <mescroll-empty :option="option" v-if="chatList.length === 0" @emptyclick="$navigateTo('/pages/login/login')"
  4. :key="reloadMecroll">
  5. </mescroll-empty>
  6. <view class="message-list" v-else>
  7. <!-- 消息提示 -->
  8. <view class="message-item" v-for="(item,index) in chatList" :key="index" @click="linkTo(item)">
  9. <uni-badge class="uni-badge-left-margin" :text="item.unread" absolute="rightTop" size="small">
  10. <image :src="item.userInfo.avatarUrl" class="message-image" mode="aspectFill">
  11. </image>
  12. </uni-badge>
  13. <view class="message-content">
  14. <view class="message-title">{{item.userInfo.nickname}}</view>
  15. <view class="message-sub-content">
  16. {{item.lastMessage.type === 'image'?'[图片]':item.lastMessage.body.text}}
  17. </view>
  18. </view>
  19. <view class="message-date">
  20. <uni-dateformat class="visitor-time" :date="item.updatedAt" :threshold="[60000,3600000 * 24 * 365]">
  21. </uni-dateformat>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. YeIMUniSDK,
  30. YeIMUniSDKDefines
  31. } from '@/uni_modules/wzJun1-YeIM-Uni-SDK/js_sdk/yeim-uni-sdk.min.js'
  32. export default {
  33. data() {
  34. return {
  35. chatList: [],
  36. option: {
  37. tip: '暂无消息'
  38. },
  39. reloadMecroll: false
  40. }
  41. },
  42. onLoad() {
  43. if (uni.getStorageSync('token')) {
  44. this.$chat.getConversationList(res => {
  45. if (res.code == 200) {
  46. this.chatList = res.data;
  47. }
  48. })
  49. }
  50. },
  51. onShow() {
  52. if (!uni.getStorageSync('token')) {
  53. this.chatList = [];
  54. this.option = {
  55. tip: '暂未登录',
  56. btnText: '点击登录'
  57. }
  58. } else {
  59. this.option = {
  60. tip: '暂无消息'
  61. }
  62. uni.$on('changeChatList', (res) => {
  63. this.chatList = res;
  64. })
  65. }
  66. this.reloadMecroll = !this.reloadMecroll;
  67. },
  68. methods: {
  69. linkTo(item) {
  70. this.$chat.clearConversationUnread(item.conversationId);
  71. this.$navigateTo('/pages/chat/chat?userId=' + item.conversationId + '&userName=' + item.userInfo.nickname)
  72. }
  73. }
  74. }
  75. </script>
  76. <style lang="scss">
  77. .message {
  78. .message-list {
  79. margin-top: 20rpx;
  80. .message-item {
  81. background: #fff;
  82. display: flex;
  83. padding: 24rpx 30rpx;
  84. position: relative;
  85. &::before {
  86. content: '';
  87. position: absolute;
  88. bottom: 0;
  89. right: 0;
  90. left: 150rpx;
  91. height: 2rpx;
  92. background: $uni-border-1;
  93. }
  94. }
  95. .message-image {
  96. width: 100rpx;
  97. height: 100rpx;
  98. border-radius: 16rpx;
  99. overflow: hidden;
  100. }
  101. .message-content {
  102. flex: 1;
  103. width: 0;
  104. margin-left: 20rpx;
  105. display: flex;
  106. flex-direction: column;
  107. justify-content: center;
  108. }
  109. .message-title {
  110. font-size: 32rpx;
  111. font-weight: 600;
  112. margin-bottom: 10rpx;
  113. }
  114. .message-sub-content {
  115. font-weight: 300;
  116. color: $uni-secondary-color;
  117. }
  118. .message-date {
  119. position: absolute;
  120. top: 34rpx;
  121. right: 30rpx;
  122. font-size: 24rpx;
  123. font-weight: 300;
  124. color: $uni-secondary-color;
  125. }
  126. }
  127. }
  128. </style>