communicate.vue 4.8 KB

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