communicate.vue 6.0 KB

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