communicate.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <layout-page class="ss-m-x-15">
  3. <view class="box" v-for="item in items" :key="item.id" @tap="handleTo(item)">
  4. <view class="box-header">
  5. <template v-if="item.unread === '0'">
  6. <image
  7. class="enterAvatar"
  8. :src="getUserAvatar(item?.userInfoVo?.userInfoResp?.avatar, item?.userInfoVo?.userInfoResp?.sex)"
  9. ></image>
  10. </template>
  11. <template v-else>
  12. <uni-badge class="uni-badge-left-margin" :text="item.unread" absolute="rightTop" size="small">
  13. <image
  14. class="enterAvatar"
  15. :src="getUserAvatar(item?.userInfoVo?.userInfoResp?.avatar, item?.userInfoVo?.userInfoResp?.sex)"
  16. ></image>
  17. </uni-badge>
  18. </template>
  19. </view>
  20. <view class="box-content">
  21. <view class="box-content-names">
  22. <view class="name">
  23. {{ item.thatName }}
  24. <text class="nameSub">{{ item.enterpriseAnotherName }}</text>
  25. <span class="line" v-if="item.postNameCn && item.enterpriseAnotherName"></span>
  26. <text class="nameSub">{{ item.postNameCn }}</text>
  27. </view>
  28. <!-- <view class="time">{{ item.updateTime }}</view> -->
  29. </view>
  30. <view class="box-content-text">{{ timesTampChange(+item.timestamp.padEnd(13, '0')) }}</view>
  31. </view>
  32. </view>
  33. <image
  34. v-if=" items.length===0 "
  35. src="https://minio.citupro.com/dev/static/nodata.png"
  36. mode="widthFix"
  37. style="width: 100vw;height: 100vh;">
  38. </image>
  39. </layout-page>
  40. </template>
  41. <script setup>
  42. import { ref, watch } from 'vue'
  43. import layoutPage from '@/layout'
  44. import { getAccessToken } from '@/utils/request'
  45. import { showAuthModal } from '@/hooks/useModal'
  46. import { getConversationSync } from '@/api/common'
  47. import { onShow } from '@dcloudio/uni-app'
  48. import { getUserAvatar } from '@/utils/avatar'
  49. import { timesTampChange } from '@/utils/date'
  50. import { userStore } from '@/store/user'
  51. import { useIMStore } from '@/store/im'
  52. const IM = useIMStore()
  53. const useUserStore = userStore()
  54. const items = ref([])
  55. watch([() => useUserStore.refreshToken, () => IM.newMsg], () => {
  56. console.log('变了')
  57. init()
  58. })
  59. onShow(() => {
  60. const currentPage = getCurrentPages()[0]; // 获取当前页面实例
  61. const currentTabBar = currentPage?.getTabBar?.();
  62. // 设置当前tab页的下标index
  63. currentTabBar?.setData({ selected: 1 });
  64. init()
  65. })
  66. const handleTo = ({ userInfoVo, thatName, postNameCn, enterpriseAnotherName, channel_id }) => {
  67. const query = {
  68. id: userInfoVo?.userInfoResp?.userId,
  69. name: thatName,
  70. postName: postNameCn,
  71. enterpriseName: enterpriseAnotherName,
  72. enterpriseId: userInfoVo?.userInfoResp?.enterpriseId,
  73. channelId: channel_id,
  74. avatar: userInfoVo?.userInfoResp?.avatar,
  75. sex: userInfoVo?.userInfoResp?.sex,
  76. }
  77. const queryStr = Object.keys(query).reduce((r, v) => {
  78. return r += `${v}=${encodeURIComponent(query[v])}&`
  79. }, '?')
  80. uni.navigateTo({
  81. url: `/pagesA/chart/index${queryStr.slice(0, -1)}`
  82. })
  83. }
  84. // if (!getAccessToken()) {
  85. // uni.showToast({
  86. // title: '请先登录',
  87. // icon: 'none'
  88. // })
  89. // showAuthModal()
  90. // return
  91. // }
  92. async function init () {
  93. try {
  94. const { data } = await getConversationSync({ msg_count: 1 })
  95. if (!data) {
  96. return
  97. }
  98. items.value = data.map(item => {
  99. return {
  100. thatName: item?.userInfoVo ? (item.userInfoVo.userInfoResp?.name ? item.userInfoVo.userInfoResp.name : '游客') : '系统消息',
  101. enterpriseAnotherName: item?.userInfoVo?.userInfoResp?.enterpriseAnotherName ?? '',
  102. postNameCn: item?.userInfoVo?.userInfoResp?.postNameCn ?? '',
  103. ...item
  104. }
  105. })
  106. } catch (error) {
  107. }
  108. }
  109. </script>
  110. <style scoped lang="scss">
  111. .box {
  112. height: 130rpx;
  113. padding: 20rpx;
  114. box-sizing: border-box;
  115. display: flex;
  116. border-bottom: 2rpx solid #eee;
  117. &-header {
  118. width: 120rpx;
  119. height: 100%;
  120. position: relative;
  121. }
  122. &-content {
  123. flex: 1;
  124. width: 0;
  125. display: flex;
  126. flex-direction: column;
  127. justify-content: space-between;
  128. &-names {
  129. display: flex;
  130. justify-content: space-between;
  131. .name {
  132. flex: 1;
  133. overflow: hidden;
  134. white-space: nowrap;
  135. text-overflow: ellipsis;
  136. .nameSub {
  137. font-size: 0.75em;
  138. color: #999;
  139. }
  140. .line {
  141. display: inline-block;
  142. width: 2rpx;
  143. height: 24rpx;
  144. vertical-align: middle;
  145. background-color: #e0e0e0;
  146. margin: 0 6rpx;
  147. }
  148. }
  149. .time {
  150. color: #999;
  151. font-size: .85em;
  152. }
  153. }
  154. &-text {
  155. color: #999;
  156. font-size: .85em;
  157. overflow: hidden;
  158. white-space: nowrap;
  159. text-overflow: ellipsis;
  160. }
  161. }
  162. }
  163. .enterAvatar{
  164. width: 80rpx;
  165. height: 80rpx;
  166. border-radius: 50%;
  167. margin: 0 auto;
  168. }
  169. </style>