communicate.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view>
  3. <Navbar title="最近联系人" />
  4. <layout-page>
  5. <view :style="{'padding-top': navbarHeight + 'px'}">
  6. <view class="commonBackground"></view>
  7. <view class="height defaultBgc">
  8. <scroll-view class="scrollBox" scroll-y="true" >
  9. <view class="box" v-for="item in items" :key="item.id" @tap="handleTo(item)">
  10. <view class="box-header">
  11. <template v-if="item.unread === '0'">
  12. <image
  13. class="enterAvatar"
  14. :src="getUserAvatar(item?.userInfoVo?.userInfoResp?.avatar, item?.userInfoVo?.userInfoResp?.sex, !item?.userInfoVo && item.channel_id === 'system' ? true : false)"
  15. ></image>
  16. </template>
  17. <template v-else>
  18. <uni-badge class="uni-badge-left-margin" :text="item.unread" absolute="rightTop" size="small">
  19. <image
  20. class="enterAvatar"
  21. :src="getUserAvatar(item?.userInfoVo?.userInfoResp?.avatar, item?.userInfoVo?.userInfoResp?.sex, !item?.userInfoVo && item.channel_id === 'system' ? true : false)"
  22. ></image>
  23. </uni-badge>
  24. </template>
  25. </view>
  26. <view class="box-content">
  27. <view class="box-content-names">
  28. <view class="name MiSans-Thin default-text-color">
  29. {{ item.thatName }}
  30. </view>
  31. <view class="color-999 font-size-12 MiSans-Normal">{{ timesTampChange(+item.timestamp.padEnd(13, '0')) }}</view>
  32. </view>
  33. <view class="color-999 font-size-13 MiSans-Normal ellipsis" style="max-width: 100%;">
  34. {{ formatName(item.enterpriseAnotherName) }}
  35. </view>
  36. </view>
  37. </view>
  38. <image
  39. v-if=" items.length===0 "
  40. src="https://minio.citupro.com/dev/static/nodata.png"
  41. mode="widthFix"
  42. style="width: 100%;">
  43. </image>
  44. <uni-load-more status="noMore" />
  45. </scroll-view>
  46. </view>
  47. </view>
  48. </layout-page>
  49. </view>
  50. </template>
  51. <script setup>
  52. import { ref, watch } from 'vue'
  53. import layoutPage from '@/layout'
  54. import { getConversationSync } from '@/api/common'
  55. import { onShow, onLoad, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
  56. import { getUserAvatar } from '@/utils/avatar'
  57. import { timesTampChange } from '@/utils/date'
  58. import { userStore } from '@/store/user'
  59. import { useIMStore } from '@/store/im'
  60. import { formatName } from '@/utils/getText'
  61. import Navbar from '@/components/Navbar'
  62. const navbarHeight = ref(uni.getStorageSync('navbarHeight'))
  63. const IM = useIMStore()
  64. const useUserStore = userStore()
  65. const items = ref([])
  66. watch([() => useUserStore.refreshToken, () => IM.newMsg], () => {
  67. // 检测实例是否存在
  68. if (!IM.uid?.value) {
  69. return
  70. }
  71. init()
  72. })
  73. watch(() => IM.uid, (val) => {
  74. if (!val) {
  75. return
  76. }
  77. // 监听uid变化
  78. init()
  79. })
  80. onShow(() => {
  81. const currentPage = getCurrentPages()[0]; // 获取当前页面实例
  82. const currentTabBar = currentPage?.getTabBar?.();
  83. // 设置当前tab页的下标index
  84. currentTabBar?.setData({ selected: 1 });
  85. init()
  86. })
  87. onLoad(() => {
  88. wx.showShareMenu({
  89. withShareTicket: true,
  90. menus: ['shareAppMessage', 'shareTimeline']
  91. })
  92. onShareAppMessage(() => {
  93. return {
  94. title: '门墩儿 专注顶尖招聘',
  95. path: '/pages/index/position',
  96. imageUrl: '../../static/img/share-poster.jpg'
  97. }
  98. })
  99. onShareTimeline(() => {
  100. return {
  101. title: '门墩儿 专注顶尖招聘',
  102. path: '/pages/index/position',
  103. imageUrl: '../../static/img/share-poster.jpg'
  104. }
  105. })
  106. })
  107. const handleTo = (item) => {
  108. const { userInfoVo, thatName, postNameCn, enterpriseAnotherName, channel_id, channel_type } = item
  109. const query = {
  110. id: userInfoVo?.userInfoResp?.userId,
  111. name: thatName,
  112. postName: postNameCn,
  113. enterpriseName: formatName(enterpriseAnotherName),
  114. enterpriseId: userInfoVo?.userInfoResp?.enterpriseId,
  115. channelID: channel_id,
  116. channelType: channel_type,
  117. avatar: userInfoVo?.userInfoResp?.avatar,
  118. sex: userInfoVo?.userInfoResp?.sex,
  119. }
  120. const queryStr = Object.keys(query).reduce((r, v) => {
  121. if (!query[v]) {
  122. return r
  123. }
  124. return r += `${v}=${encodeURIComponent(query[v])}&`
  125. }, '?')
  126. uni.navigateTo({
  127. url: `/pagesA/chart/index${queryStr.slice(0, -1)}`
  128. })
  129. }
  130. async function init () {
  131. try {
  132. const { data } = await getConversationSync({ msg_count: 1 })
  133. if (!data) {
  134. return
  135. }
  136. items.value = data.map(item => {
  137. return {
  138. thatName: item?.userInfoVo ? (item.userInfoVo.userInfoResp?.name ? item.userInfoVo.userInfoResp.name : '游客') : '系统消息',
  139. enterpriseAnotherName: item?.userInfoVo?.userInfoResp?.enterpriseAnotherName || item?.userInfoVo?.userInfoResp?.enterpriseName,
  140. postNameCn: item?.userInfoVo?.userInfoResp?.postNameCn ?? '',
  141. ...item
  142. }
  143. })
  144. } catch (error) {
  145. }
  146. }
  147. </script>
  148. <style scoped lang="scss">
  149. .scrollBox {
  150. padding-bottom: 24rpx;
  151. box-sizing: border-box;
  152. }
  153. .box {
  154. height: 130rpx;
  155. padding: 20rpx;
  156. box-sizing: border-box;
  157. display: flex;
  158. border-bottom: 2rpx solid #eee;
  159. &-header {
  160. width: 120rpx;
  161. height: 100%;
  162. position: relative;
  163. }
  164. &-content {
  165. flex: 1;
  166. width: 0;
  167. display: flex;
  168. flex-direction: column;
  169. justify-content: space-between;
  170. &-names {
  171. display: flex;
  172. justify-content: space-between;
  173. .name {
  174. flex: 1;
  175. overflow: hidden;
  176. white-space: nowrap;
  177. text-overflow: ellipsis;
  178. .nameSub {
  179. font-size: 0.75em;
  180. color: #999;
  181. }
  182. .line {
  183. display: inline-block;
  184. width: 2rpx;
  185. height: 24rpx;
  186. vertical-align: middle;
  187. background-color: #e0e0e0;
  188. margin: 0 6rpx;
  189. }
  190. }
  191. .time {
  192. color: #999;
  193. font-size: .85em;
  194. }
  195. }
  196. &-text {
  197. color: #999;
  198. font-size: .85em;
  199. overflow: hidden;
  200. white-space: nowrap;
  201. text-overflow: ellipsis;
  202. }
  203. }
  204. }
  205. .height {
  206. height: 100vh;
  207. padding-bottom: 120rpx;
  208. box-sizing: border-box;
  209. }
  210. .enterAvatar{
  211. width: 80rpx;
  212. height: 80rpx;
  213. border-radius: 50%;
  214. margin: 0 auto;
  215. }
  216. </style>