communicate.vue 4.1 KB

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