communicate.vue 5.7 KB

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