communicate.vue 4.8 KB

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