message.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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', (list) => {
  62. this.chatList = list.filter(node => node.conversationId !== 'system');
  63. // this.$store.getters.user.userId
  64. getMessageTest(3).then(res => {
  65. if (res.code == 200) {
  66. this.systemCount = res.data.length;
  67. this.unread();
  68. }
  69. });
  70. })
  71. },
  72. onShow() {
  73. console.log('on show');
  74. if (!uni.getStorageSync('token')) {
  75. this.chatList = [];
  76. this.option = {
  77. tip: '暂未登录',
  78. btnText: '点击登录'
  79. }
  80. } else {
  81. this.option = {
  82. tip: '暂无会话'
  83. }
  84. this.$chat.listenerList();
  85. this.init();
  86. }
  87. },
  88. methods: {
  89. init() {
  90. this.$chat.getConversationList((data) => {
  91. this.chatList = data.data.filter(node => node.conversationId !== 'system');
  92. getMessageTest(3).then(res => {
  93. if (res.code == 200) {
  94. this.systemCount = res.data.length;
  95. this.unread();
  96. }
  97. });
  98. });
  99. },
  100. linkTo(item) {
  101. this.$chat.clearConversationUnread(item.conversationId);
  102. this.$navigateTo('/pages/chat/chat?userId=' + item.conversationId + '&userName=' + item.userInfo.nickname)
  103. },
  104. unread() {
  105. let badge = this.systemCount;
  106. let list = this.chatList;
  107. for (let i = 0; i < list.length; i++) {
  108. badge += list[i].unread
  109. }
  110. if (!badge) {
  111. uni.removeTabBarBadge({
  112. index: 1
  113. })
  114. } else {
  115. uni.setTabBarBadge({
  116. index: 1,
  117. text: String(badge)
  118. })
  119. }
  120. }
  121. }
  122. }
  123. </script>
  124. <style lang="scss">
  125. .message {
  126. .message-system {
  127. background: #fff;
  128. display: flex;
  129. padding: 24rpx 30rpx;
  130. position: relative;
  131. margin-top: 30rpx;
  132. .message-image {
  133. width: 100rpx;
  134. height: 100rpx;
  135. border-radius: 16rpx;
  136. overflow: hidden;
  137. }
  138. .message-content {
  139. flex: 1;
  140. width: 0;
  141. margin-left: 20rpx;
  142. display: flex;
  143. flex-direction: column;
  144. justify-content: center;
  145. }
  146. .message-title {
  147. font-size: 32rpx;
  148. font-weight: 600;
  149. margin-bottom: 10rpx;
  150. }
  151. .message-sub-content {
  152. font-weight: 300;
  153. color: $uni-secondary-color;
  154. }
  155. .message-system-icon {
  156. width: 100rpx;
  157. height: 100rpx;
  158. border-radius: 16rpx;
  159. text-align: center;
  160. line-height: 100rpx;
  161. background: $uni-primary;
  162. }
  163. }
  164. .message-titles {
  165. font-weight: 300;
  166. padding: 30rpx 30rpx 10rpx 30rpx;
  167. }
  168. .message-list {
  169. .message-item {
  170. background: #fff;
  171. display: flex;
  172. padding: 24rpx 30rpx;
  173. position: relative;
  174. &::before {
  175. content: '';
  176. position: absolute;
  177. bottom: 0;
  178. right: 0;
  179. left: 150rpx;
  180. height: 2rpx;
  181. background: $uni-border-1;
  182. }
  183. }
  184. .message-image {
  185. width: 100rpx;
  186. height: 100rpx;
  187. border-radius: 16rpx;
  188. overflow: hidden;
  189. }
  190. .message-content {
  191. flex: 1;
  192. width: 0;
  193. margin-left: 20rpx;
  194. display: flex;
  195. flex-direction: column;
  196. justify-content: center;
  197. }
  198. .message-title {
  199. font-size: 32rpx;
  200. font-weight: 600;
  201. margin-bottom: 10rpx;
  202. }
  203. .message-sub-content {
  204. font-weight: 300;
  205. color: $uni-secondary-color;
  206. }
  207. .message-date {
  208. position: absolute;
  209. top: 34rpx;
  210. right: 30rpx;
  211. font-size: 24rpx;
  212. font-weight: 300;
  213. color: $uni-secondary-color;
  214. }
  215. }
  216. }
  217. </style>