communicate.vue 5.6 KB

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