communicate.vue 5.3 KB

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