communicate.vue 5.8 KB

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