communicate.vue 4.3 KB

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