communicate.vue 4.3 KB

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