communicate.vue 4.7 KB

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