index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view class="">
  3. <view v-if="msgList.length" class="margin-topW">
  4. <view class="flex padding-tb radius padding-lr-sm bg" @click="goMsg" v-for="(item,index) in msgList"
  5. :key='index'>
  6. <view>
  7. <image style="width: 80rpx;height: 80rpx;border-radius: 80rpx;"
  8. src="../../static/images/msg/msg.png"></image>
  9. </view>
  10. <view class="flex-sub margin-left-sm">
  11. <view class="flex justify-between">
  12. <view class="text-white">{{item.title?item.title: '系统消息'}}</view>
  13. <view v-if="messageCount>0"
  14. style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
  15. {{messageCount}}</view>
  16. </view>
  17. <view>
  18. <view class="text-grey">{{item.content}}</view>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <view v-if="chatList.length" class="margin-top-sm content ">
  24. <view class="radius padding-lr-sm bg" style="margin-top: 4rpx;" @click="goIM(item)"
  25. v-for="(item,index) in chatList" :key='index'>
  26. <view class="flex padding-tb " v-if="userId == item.userId">
  27. <view>
  28. <u-image shape="circle" width='80rpx' height="80rpx" :src="item.byAvatar"></u-image>
  29. </view>
  30. <view class="flex-sub margin-left-sm">
  31. <view class="flex justify-between">
  32. <view class="text-white">{{item.byUserName}}</view>
  33. <view class="text-grey">{{item.messageTime}}</view>
  34. </view>
  35. <view class="flex justify-between">
  36. <view class="text-grey">{{ item.messageType == 1? item.content : '[图片]'}}</view>
  37. <view v-if="item.contentCount"
  38. style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
  39. {{item.contentCount}}</view>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="flex padding-tb" v-else>
  44. <view>
  45. <u-image shape="circle" width='80rpx' height="80rpx" :src="item.avatar"></u-image>
  46. </view>
  47. <view class="flex-sub margin-left-sm">
  48. <view class="flex justify-between">
  49. <view class="text-white">{{item.userName}}</view>
  50. <view class="text-grey">{{item.updateTime}}</view>
  51. </view>
  52. <view class="flex justify-between">
  53. <view class="text-grey">{{ item.messageType == 1? item.content : '[图片]'}}</view>
  54. <view v-if="item.contentCount"
  55. style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
  56. {{item.contentCount}}</view>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. <empty v-if="!chatList.length && !msgList.length" content='暂无消息'></empty>
  63. </view>
  64. </template>
  65. <script>
  66. import empty from '../../components/empty.vue'
  67. export default {
  68. components: {
  69. empty
  70. },
  71. data() {
  72. return {
  73. page: 1,
  74. limit: 100,
  75. chatList: [],
  76. userId: '',
  77. msgList: [],
  78. time: '',
  79. messageCount: 0
  80. }
  81. },
  82. onLoad() {
  83. this.getChatList()
  84. },
  85. onShow() {
  86. let that = this
  87. that.userId = uni.getStorageSync('userId')
  88. if (that.userId) {
  89. that.time = setInterval(function() {
  90. that.getChatList()
  91. that.getMsgList()
  92. that.$nextTick(function() {
  93. that.messageCount = uni.getStorageSync('messageCount')
  94. })
  95. }, 1000)
  96. } else {
  97. that.chatList = []
  98. that.msgList = []
  99. }
  100. },
  101. onHide() {
  102. clearInterval(this.time)
  103. },
  104. methods: {
  105. getChatList() {
  106. this.$Request.get("/app/chat/selectChatConversationPage", {
  107. page: this.page,
  108. limit: this.limit
  109. }).then(res => {
  110. if (res.code == 0) {
  111. this.chatList = res.data.list
  112. }
  113. });
  114. },
  115. getMsgList() {
  116. this.$Request.get("/app/message/selectMessageByUserIdLimit1").then(res => {
  117. if (res.code == 0) {
  118. this.msgList = res.data.list
  119. }
  120. });
  121. },
  122. goIM(e) {
  123. let userId = this.$queue.getData('userId');
  124. if (e.userId == userId) {
  125. userId = e.byUserId
  126. } else {
  127. userId = e.userId
  128. }
  129. uni.navigateTo({
  130. url: '/pages/msg/im?chatConversationId=' + e.chatConversationId + '&byUserId=' + userId
  131. })
  132. },
  133. goMsg() {
  134. uni.navigateTo({
  135. url: '/pages/msg/message'
  136. })
  137. }
  138. }
  139. }
  140. </script>
  141. <style>
  142. page {
  143. background-color: #F7F7F7;
  144. }
  145. .bg {
  146. background: #FFFFFF;
  147. }
  148. </style>