message.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <view class="message">
  3. <view class="message-system" @click="$navigateTo('/pages/messageSystem/messageSystem')">
  4. <uni-badge class="uni-badge-left-margin" :text="systemCount" absolute="rightTop" size="small">
  5. <view class="message-system-icon">
  6. <uni-icons type="email-filled" size="30" color="#fff"></uni-icons>
  7. </view>
  8. </uni-badge>
  9. <view class="message-content">
  10. <view class="message-title">系统通知</view>
  11. <view class="message-sub-content">
  12. {{systemCount === 0 ?'暂无消息通知' : `您有${systemCount}条未读消息,请点击查看~`}}
  13. </view>
  14. </view>
  15. </view>
  16. <view class="message-titles">即时会话</view>
  17. <mescroll-empty :option="option" v-if="chatList.length === 0" @emptyclick="$navigateTo('/pages/login/login')">
  18. </mescroll-empty>
  19. <view class="message-list" v-else>
  20. <!-- 消息提示 -->
  21. <view class="message-item" v-for="(item,index) in chatList" :key="index" @click="linkTo(item)">
  22. <uni-badge class="uni-badge-left-margin" :text="item.unread" absolute="rightTop" size="small">
  23. <image :src="item.userInfo.avatarUrl" class="message-image" mode="aspectFill">
  24. </image>
  25. </uni-badge>
  26. <view class="message-content">
  27. <view class="message-title">{{item.userInfo.nickname}}</view>
  28. <view class="message-sub-content">
  29. {{item.lastMessage.type === 'image'?'[图片]':item.lastMessage.body.text}}
  30. </view>
  31. </view>
  32. <view class="message-date">
  33. <uni-dateformat class="visitor-time" :date="item.updatedAt || item.createdAt"
  34. :threshold="[60000,3600000 * 24 * 365]">
  35. </uni-dateformat>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. YeIMUniSDK,
  44. YeIMUniSDKDefines
  45. } from '@/uni_modules/wzJun1-YeIM-Uni-SDK/js_sdk/yeim-uni-sdk.min.js'
  46. import {
  47. getMessageTest
  48. } from '@/request/api/message.js'
  49. export default {
  50. data() {
  51. return {
  52. chatList: [],
  53. option: {
  54. tip: '暂无会话'
  55. },
  56. systemCount: 0,
  57. systemDate: ''
  58. }
  59. },
  60. onLoad() {
  61. uni.$on('changeChatList', this.countNumber);
  62. },
  63. onShow() {
  64. if (!uni.getStorageSync('token')) {
  65. this.chatList = [];
  66. this.option = {
  67. tip: '暂未登录',
  68. btnText: '点击登录'
  69. }
  70. } else {
  71. this.option = {
  72. tip: '暂无会话'
  73. }
  74. this.$chat.listenerList();
  75. this.init();
  76. }
  77. },
  78. methods: {
  79. init() {
  80. this.$chat.getConversationList(data => {
  81. this.countNumber(data.data);
  82. });
  83. },
  84. countNumber(data) {
  85. this.chatList = data.filter(node => node.conversationId !== 'system');
  86. getMessageTest(this.$store.getters.user.userId).then(res => {
  87. if (res.code == 200) {
  88. let num = 0;
  89. for (var i = 0; i < res.data.length; i++) {
  90. num += res.data[i].count
  91. }
  92. this.systemCount = num;
  93. this.unread();
  94. }
  95. });
  96. },
  97. linkTo(item) {
  98. this.$chat.clearConversationUnread(item.conversationId);
  99. this.$navigateTo('/pages/chat/chat?userId=' + item.conversationId + '&userName=' + item.userInfo.nickname)
  100. },
  101. unread() {
  102. let badge = this.systemCount;
  103. let list = this.chatList;
  104. for (let i = 0; i < list.length; i++) {
  105. badge += list[i].unread
  106. }
  107. if (!badge) {
  108. uni.removeTabBarBadge({
  109. index: 1
  110. })
  111. } else {
  112. uni.setTabBarBadge({
  113. index: 1,
  114. text: String(badge)
  115. })
  116. }
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss">
  122. .message {
  123. .message-system {
  124. background: #fff;
  125. display: flex;
  126. padding: 24rpx 30rpx;
  127. position: relative;
  128. margin-top: 30rpx;
  129. .message-image {
  130. width: 100rpx;
  131. height: 100rpx;
  132. border-radius: 16rpx;
  133. overflow: hidden;
  134. }
  135. .message-content {
  136. flex: 1;
  137. width: 0;
  138. margin-left: 20rpx;
  139. display: flex;
  140. flex-direction: column;
  141. justify-content: center;
  142. }
  143. .message-title {
  144. font-size: 32rpx;
  145. font-weight: 600;
  146. margin-bottom: 10rpx;
  147. }
  148. .message-sub-content {
  149. font-weight: 300;
  150. color: $uni-secondary-color;
  151. }
  152. .message-system-icon {
  153. width: 100rpx;
  154. height: 100rpx;
  155. border-radius: 16rpx;
  156. text-align: center;
  157. line-height: 100rpx;
  158. background: $uni-primary;
  159. }
  160. }
  161. .message-titles {
  162. font-weight: 300;
  163. padding: 30rpx 30rpx 10rpx 30rpx;
  164. }
  165. .message-list {
  166. .message-item {
  167. background: #fff;
  168. display: flex;
  169. padding: 24rpx 30rpx;
  170. position: relative;
  171. &::before {
  172. content: '';
  173. position: absolute;
  174. bottom: 0;
  175. right: 0;
  176. left: 150rpx;
  177. height: 2rpx;
  178. background: $uni-border-1;
  179. }
  180. }
  181. .message-image {
  182. width: 100rpx;
  183. height: 100rpx;
  184. border-radius: 16rpx;
  185. overflow: hidden;
  186. }
  187. .message-content {
  188. flex: 1;
  189. width: 0;
  190. margin-left: 20rpx;
  191. display: flex;
  192. flex-direction: column;
  193. justify-content: center;
  194. }
  195. .message-title {
  196. font-size: 32rpx;
  197. font-weight: 600;
  198. margin-bottom: 10rpx;
  199. }
  200. .message-sub-content {
  201. font-weight: 300;
  202. color: $uni-secondary-color;
  203. }
  204. .message-date {
  205. position: absolute;
  206. top: 34rpx;
  207. right: 30rpx;
  208. font-size: 24rpx;
  209. font-weight: 300;
  210. color: $uni-secondary-color;
  211. }
  212. }
  213. }
  214. </style>