message.vue 2.6 KB

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