communicate.vue 5.3 KB

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