communicate.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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, !item?.userInfoVo && item.channel_id === 'system' ? true : false)"
  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, !item?.userInfoVo && item.channel_id === 'system' ? true : false)"
  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, channel_type } = 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. channelType: channel_type,
  108. avatar: userInfoVo?.userInfoResp?.avatar,
  109. sex: userInfoVo?.userInfoResp?.sex,
  110. }
  111. const queryStr = Object.keys(query).reduce((r, v) => {
  112. if (!query[v]) {
  113. return r
  114. }
  115. return r += `${v}=${encodeURIComponent(query[v])}&`
  116. }, '?')
  117. uni.navigateTo({
  118. url: `/pagesA/chart/index${queryStr.slice(0, -1)}`
  119. })
  120. }
  121. async function init () {
  122. try {
  123. const { data } = await getConversationSync({ msg_count: 1 })
  124. if (!data) {
  125. return
  126. }
  127. items.value = data.map(item => {
  128. return {
  129. thatName: item?.userInfoVo ? (item.userInfoVo.userInfoResp?.name ? item.userInfoVo.userInfoResp.name : '游客') : '系统消息',
  130. enterpriseAnotherName: item?.userInfoVo?.userInfoResp?.enterpriseAnotherName ?? '',
  131. postNameCn: item?.userInfoVo?.userInfoResp?.postNameCn ?? '',
  132. ...item
  133. }
  134. })
  135. } catch (error) {
  136. }
  137. }
  138. </script>
  139. <style scoped lang="scss">
  140. .scrollBox {
  141. padding-bottom: 24rpx;
  142. box-sizing: border-box;
  143. }
  144. .box {
  145. background: #FFF;
  146. height: 130rpx;
  147. padding: 20rpx;
  148. box-sizing: border-box;
  149. display: flex;
  150. border-bottom: 2rpx solid #eee;
  151. &-header {
  152. width: 120rpx;
  153. height: 100%;
  154. position: relative;
  155. }
  156. &-content {
  157. flex: 1;
  158. width: 0;
  159. display: flex;
  160. flex-direction: column;
  161. justify-content: space-between;
  162. &-names {
  163. display: flex;
  164. justify-content: space-between;
  165. .name {
  166. flex: 1;
  167. overflow: hidden;
  168. white-space: nowrap;
  169. text-overflow: ellipsis;
  170. .nameSub {
  171. font-size: 0.75em;
  172. color: #999;
  173. }
  174. .line {
  175. display: inline-block;
  176. width: 2rpx;
  177. height: 24rpx;
  178. vertical-align: middle;
  179. background-color: #e0e0e0;
  180. margin: 0 6rpx;
  181. }
  182. }
  183. .time {
  184. color: #999;
  185. font-size: .85em;
  186. }
  187. }
  188. &-text {
  189. color: #999;
  190. font-size: .85em;
  191. overflow: hidden;
  192. white-space: nowrap;
  193. text-overflow: ellipsis;
  194. }
  195. }
  196. }
  197. .height {
  198. height: 100vh;
  199. padding-bottom: 120rpx;
  200. box-sizing: border-box;
  201. }
  202. .enterAvatar{
  203. width: 80rpx;
  204. height: 80rpx;
  205. border-radius: 50%;
  206. margin: 0 auto;
  207. }
  208. </style>