communicate.vue 5.2 KB

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