message.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <view class="message">
  3. <pinapp-empty-page title="暂无消息" v-if="chatList.length === 0"></pinapp-empty-page>
  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. import pinappEmptyPage from "@/components/pinapp-empty-page/pinapp-empty-page.vue"
  31. export default {
  32. data() {
  33. return {
  34. chatList: []
  35. }
  36. },
  37. onLoad() {
  38. this.$chat.getConversationList(res => {
  39. if (res.code == 200) {
  40. this.chatList = res.data;
  41. }
  42. })
  43. },
  44. onShow() {
  45. uni.$on('changeChatList', (res) => {
  46. this.chatList = res;
  47. })
  48. },
  49. components: {
  50. pinappEmptyPage
  51. },
  52. methods: {
  53. linkTo(item) {
  54. this.$chat.clearConversationUnread(item.conversationId);
  55. this.$navigateTo('/pages/chat/chat?userId=' + item.conversationId + '&userName=' + item.userInfo.nickname)
  56. }
  57. }
  58. }
  59. </script>
  60. <style lang="scss">
  61. .message {
  62. .message-list {
  63. margin-top: 20rpx;
  64. .message-item {
  65. background: #fff;
  66. display: flex;
  67. padding: 24rpx 30rpx;
  68. position: relative;
  69. &::before {
  70. content: '';
  71. position: absolute;
  72. bottom: 0;
  73. right: 0;
  74. left: 150rpx;
  75. height: 2rpx;
  76. background: $uni-border-1;
  77. }
  78. }
  79. .message-image {
  80. width: 100rpx;
  81. height: 100rpx;
  82. border-radius: 16rpx;
  83. overflow: hidden;
  84. }
  85. .message-content {
  86. flex: 1;
  87. width: 0;
  88. margin-left: 20rpx;
  89. display: flex;
  90. flex-direction: column;
  91. justify-content: center;
  92. }
  93. .message-title {
  94. font-size: 32rpx;
  95. font-weight: 600;
  96. margin-bottom: 10rpx;
  97. }
  98. .message-sub-content {
  99. font-weight: 300;
  100. color: $uni-secondary-color;
  101. }
  102. .message-date {
  103. position: absolute;
  104. top: 34rpx;
  105. right: 30rpx;
  106. font-size: 24rpx;
  107. font-weight: 300;
  108. color: $uni-secondary-color;
  109. }
  110. }
  111. }
  112. </style>