communicate.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <layout-page>
  3. <view class="height defaultBgc">
  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. <uni-load-more status="noMore" />
  42. </scroll-view>
  43. </view>
  44. </layout-page>
  45. </template>
  46. <script setup>
  47. import { ref, watch } from 'vue'
  48. import layoutPage from '@/layout'
  49. // import { getAccessToken } from '@/utils/request'
  50. // import { showAuthModal } from '@/hooks/useModal'
  51. import { getConversationSync } from '@/api/common'
  52. import { onShow } from '@dcloudio/uni-app'
  53. import { getUserAvatar } from '@/utils/avatar'
  54. import { timesTampChange } from '@/utils/date'
  55. import { userStore } from '@/store/user'
  56. import { useIMStore } from '@/store/im'
  57. const IM = useIMStore()
  58. const useUserStore = userStore()
  59. const items = ref([])
  60. watch([() => useUserStore.refreshToken, () => IM.newMsg], () => {
  61. // 检测实例是否存在
  62. if (!IM.uid?.value) {
  63. return
  64. }
  65. init()
  66. })
  67. watch(() => IM.uid, (val) => {
  68. if (!val) {
  69. return
  70. }
  71. // 监听uid变化
  72. init()
  73. })
  74. onShow(() => {
  75. const currentPage = getCurrentPages()[0]; // 获取当前页面实例
  76. const currentTabBar = currentPage?.getTabBar?.();
  77. // 设置当前tab页的下标index
  78. currentTabBar?.setData({ selected: 1 });
  79. init()
  80. })
  81. const handleTo = (item) => {
  82. const { userInfoVo, thatName, postNameCn, enterpriseAnotherName, channel_id } = item
  83. const query = {
  84. id: userInfoVo?.userInfoResp?.userId,
  85. name: thatName,
  86. postName: postNameCn,
  87. enterpriseName: enterpriseAnotherName,
  88. enterpriseId: userInfoVo?.userInfoResp?.enterpriseId,
  89. channelId: channel_id,
  90. avatar: userInfoVo?.userInfoResp?.avatar,
  91. sex: userInfoVo?.userInfoResp?.sex,
  92. }
  93. const queryStr = Object.keys(query).reduce((r, v) => {
  94. return r += `${v}=${encodeURIComponent(query[v])}&`
  95. }, '?')
  96. uni.navigateTo({
  97. url: `/pagesA/chart/index${queryStr.slice(0, -1)}`
  98. })
  99. }
  100. // if (!getAccessToken()) {
  101. // uni.showToast({
  102. // title: '请先登录',
  103. // icon: 'none'
  104. // })
  105. // showAuthModal()
  106. // return
  107. // }
  108. async function init () {
  109. try {
  110. const { data } = await getConversationSync({ msg_count: 1 })
  111. if (!data) {
  112. return
  113. }
  114. items.value = data.map(item => {
  115. return {
  116. thatName: item?.userInfoVo ? (item.userInfoVo.userInfoResp?.name ? item.userInfoVo.userInfoResp.name : '游客') : '系统消息',
  117. enterpriseAnotherName: item?.userInfoVo?.userInfoResp?.enterpriseAnotherName ?? '',
  118. postNameCn: item?.userInfoVo?.userInfoResp?.postNameCn ?? '',
  119. ...item
  120. }
  121. })
  122. } catch (error) {
  123. }
  124. }
  125. </script>
  126. <style scoped lang="scss">
  127. .scrollBox {
  128. padding-bottom: 24rpx;
  129. box-sizing: border-box;
  130. }
  131. .box {
  132. background: #FFF;
  133. height: 130rpx;
  134. padding: 20rpx;
  135. box-sizing: border-box;
  136. display: flex;
  137. border-bottom: 2rpx solid #eee;
  138. &-header {
  139. width: 120rpx;
  140. height: 100%;
  141. position: relative;
  142. }
  143. &-content {
  144. flex: 1;
  145. width: 0;
  146. display: flex;
  147. flex-direction: column;
  148. justify-content: space-between;
  149. &-names {
  150. display: flex;
  151. justify-content: space-between;
  152. .name {
  153. flex: 1;
  154. overflow: hidden;
  155. white-space: nowrap;
  156. text-overflow: ellipsis;
  157. .nameSub {
  158. font-size: 0.75em;
  159. color: #999;
  160. }
  161. .line {
  162. display: inline-block;
  163. width: 2rpx;
  164. height: 24rpx;
  165. vertical-align: middle;
  166. background-color: #e0e0e0;
  167. margin: 0 6rpx;
  168. }
  169. }
  170. .time {
  171. color: #999;
  172. font-size: .85em;
  173. }
  174. }
  175. &-text {
  176. color: #999;
  177. font-size: .85em;
  178. overflow: hidden;
  179. white-space: nowrap;
  180. text-overflow: ellipsis;
  181. }
  182. }
  183. }
  184. .height {
  185. height: 100vh;
  186. padding-bottom: 120rpx;
  187. box-sizing: border-box;
  188. }
  189. .enterAvatar{
  190. width: 80rpx;
  191. height: 80rpx;
  192. border-radius: 50%;
  193. margin: 0 auto;
  194. }
  195. </style>