communicate.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 } 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']
  83. })
  84. onShareAppMessage(() => {
  85. return {
  86. title: '门墩儿 专注顶尖招聘',
  87. path: '/pages/index/position',
  88. imageUrl: 'https://minio.menduner.com/dev/menduner/miniProgram/share-cover.png'
  89. }
  90. })
  91. })
  92. const handleTo = (item) => {
  93. const { userInfoVo, thatName, postNameCn, enterpriseAnotherName, channel_id } = item
  94. const query = {
  95. id: userInfoVo?.userInfoResp?.userId,
  96. name: thatName,
  97. postName: postNameCn,
  98. enterpriseName: enterpriseAnotherName,
  99. enterpriseId: userInfoVo?.userInfoResp?.enterpriseId,
  100. channelId: channel_id,
  101. avatar: userInfoVo?.userInfoResp?.avatar,
  102. sex: userInfoVo?.userInfoResp?.sex,
  103. }
  104. const queryStr = Object.keys(query).reduce((r, v) => {
  105. return r += `${v}=${encodeURIComponent(query[v])}&`
  106. }, '?')
  107. uni.navigateTo({
  108. url: `/pagesA/chart/index${queryStr.slice(0, -1)}`
  109. })
  110. }
  111. async function init () {
  112. try {
  113. const { data } = await getConversationSync({ msg_count: 1 })
  114. if (!data) {
  115. return
  116. }
  117. items.value = data.map(item => {
  118. return {
  119. thatName: item?.userInfoVo ? (item.userInfoVo.userInfoResp?.name ? item.userInfoVo.userInfoResp.name : '游客') : '系统消息',
  120. enterpriseAnotherName: item?.userInfoVo?.userInfoResp?.enterpriseAnotherName ?? '',
  121. postNameCn: item?.userInfoVo?.userInfoResp?.postNameCn ?? '',
  122. ...item
  123. }
  124. })
  125. } catch (error) {
  126. }
  127. }
  128. </script>
  129. <style scoped lang="scss">
  130. .scrollBox {
  131. padding-bottom: 24rpx;
  132. box-sizing: border-box;
  133. }
  134. .box {
  135. background: #FFF;
  136. height: 130rpx;
  137. padding: 20rpx;
  138. box-sizing: border-box;
  139. display: flex;
  140. border-bottom: 2rpx solid #eee;
  141. &-header {
  142. width: 120rpx;
  143. height: 100%;
  144. position: relative;
  145. }
  146. &-content {
  147. flex: 1;
  148. width: 0;
  149. display: flex;
  150. flex-direction: column;
  151. justify-content: space-between;
  152. &-names {
  153. display: flex;
  154. justify-content: space-between;
  155. .name {
  156. flex: 1;
  157. overflow: hidden;
  158. white-space: nowrap;
  159. text-overflow: ellipsis;
  160. .nameSub {
  161. font-size: 0.75em;
  162. color: #999;
  163. }
  164. .line {
  165. display: inline-block;
  166. width: 2rpx;
  167. height: 24rpx;
  168. vertical-align: middle;
  169. background-color: #e0e0e0;
  170. margin: 0 6rpx;
  171. }
  172. }
  173. .time {
  174. color: #999;
  175. font-size: .85em;
  176. }
  177. }
  178. &-text {
  179. color: #999;
  180. font-size: .85em;
  181. overflow: hidden;
  182. white-space: nowrap;
  183. text-overflow: ellipsis;
  184. }
  185. }
  186. }
  187. .height {
  188. height: 100vh;
  189. padding-bottom: 120rpx;
  190. box-sizing: border-box;
  191. }
  192. .enterAvatar{
  193. width: 80rpx;
  194. height: 80rpx;
  195. border-radius: 50%;
  196. margin: 0 auto;
  197. }
  198. </style>