wechatList.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <view class="popupBox ">
  3. <view class="es-bc-white popupBox-content" v-if="userList.length>0">
  4. <view class="u-f es-mt-20 popupBox-content-list" v-for="(item,index) in userList" :key="index"
  5. @tap="loginByUserIdFun(item)">
  6. <view class="es-mr-20">
  7. <image class="es-icon-90 es-br-ban" :src="item.avatar" mode=""></image>
  8. </view>
  9. <view class="y-b" style="flex: 1;">
  10. <view class="es-fs-36 es-fw u-f-ac" style="display: flex; justify-content: space-between;">
  11. <text>{{item.nickName}}</text>
  12. <view class="last-login-tag" v-if="item.userId === lastLoginUserId">上次登录</view>
  13. </view>
  14. <view class="es-fs-30">{{item.userId}}</view>
  15. </view>
  16. </view>
  17. </view>
  18. <view v-else>
  19. <u-empty></u-empty>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import {
  25. loginByUserId
  26. } from '@/api/user'
  27. export default {
  28. data() {
  29. return {
  30. userList: [],
  31. lastLoginUserId: ''
  32. }
  33. },
  34. mounted() {
  35. this.getRegistrationID()
  36. const wechatList = uni.getStorageSync('wechatList')
  37. if (wechatList) {
  38. this.userList = wechatList
  39. // 找出updateTime最大的用户作为上次登录用户
  40. if (this.userList.length > 0) {
  41. // 假设updateTime是可比较的字符串或时间戳
  42. // 如果是字符串,建议统一格式,或者转换为时间戳比较
  43. // 这里先简单直接比较,如果需要更复杂的转换可以在这里处理
  44. let maxTimeItem = this.userList[0];
  45. for (let i = 1; i < this.userList.length; i++) {
  46. const current = this.userList[i];
  47. // 尝试转换为时间戳比较,兼容性更好
  48. const maxTime = new Date(maxTimeItem.updateTime).getTime();
  49. const curTime = new Date(current.updateTime).getTime();
  50. if (!isNaN(curTime) && (isNaN(maxTime) || curTime > maxTime)) {
  51. maxTimeItem = current;
  52. } else if (!isNaN(curTime) && curTime === maxTime) {
  53. // 如果时间相同,可以根据其他逻辑处理,这里暂且保持原样
  54. }
  55. }
  56. if (maxTimeItem && maxTimeItem.updateTime) {
  57. this.lastLoginUserId = maxTimeItem.userId;
  58. }
  59. }
  60. uni.removeStorageSync('wechatList')
  61. }
  62. },
  63. methods: {
  64. getRegistrationID() {
  65. const registrationID = uni.getStorageSync("registrationID");
  66. if (!registrationID) {
  67. uni.getPushClientId({
  68. success: res => {
  69. uni.setStorageSync("registrationID", res.cid);
  70. }
  71. });
  72. }
  73. },
  74. async loginByUserIdFun(e) {
  75. const requestParam = uni.getStorageSync('requestParam')
  76. uni.removeStorageSync('requestParam')
  77. let params = {
  78. ...requestParam,
  79. userId: e.userId,
  80. jpushId: uni.getStorageSync("registrationID")
  81. }
  82. const res = await loginByUserId(params)
  83. if (res.code == 200) {
  84. uni.setStorageSync('AppToken', res.token);
  85. uni.setStorageSync('liveToken', res.liveToken);
  86. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  87. uni.setStorageSync('userData',JSON.stringify(res.user));
  88. uni.$emit('refreshIM');
  89. uni.$emit('showHealthButler');
  90. this.goPage();
  91. } else {
  92. uni.showToast({
  93. title: res.msg,
  94. icon: 'none'
  95. });
  96. }
  97. },
  98. goPage() {
  99. let pages = getCurrentPages();
  100. let url = pages[pages.length - 1];
  101. let openUrl = uni.getStorageSync("openUrl");
  102. if (openUrl) {
  103. uni.navigateTo({
  104. url: openUrl,
  105. success: function(res) {
  106. uni.removeStorageSync("openUrl")
  107. }
  108. })
  109. } else {
  110. this.$updateMsgDot();
  111. this.$setSource();
  112. uni.reLaunch({
  113. url: '/pages_im/pages/conversation/conversationList/index',
  114. animationType: 'none',
  115. animationDuration: 2000
  116. });
  117. return;
  118. if (pages.length == 1) {
  119. uni.reLaunch({
  120. url: '/pages_im/pages/conversation/conversationList/index',
  121. //url: '../course/video/living-app',
  122. animationType: 'none',
  123. animationDuration: 2000
  124. });
  125. } else {
  126. //this.$navBack();
  127. }
  128. }
  129. },
  130. },
  131. }
  132. </script>
  133. <style lang="scss" scoped>
  134. .popupBox {
  135. padding: 48rpx 24rpx;
  136. padding-top: 0rpx;
  137. margin-top: 24rpx;
  138. width: 100vw;
  139. box-sizing: border-box;
  140. flex-direction: column;
  141. .popupBox-content {
  142. padding: 24rpx;
  143. padding-bottom: 0;
  144. border-radius: 16rpx;
  145. .popupBox-content-list {
  146. padding-bottom: 24rpx;
  147. border-bottom: 1rpx solid #F7F8FA;
  148. &:last-child {
  149. border-bottom: none;
  150. }
  151. .last-login-tag {
  152. font-size: 24rpx;
  153. color: #FFFFFF;
  154. background-color: #2583EB;
  155. padding: 2rpx 10rpx;
  156. border-radius: 6rpx;
  157. margin-left: 16rpx;
  158. line-height: 1.5;
  159. }
  160. }
  161. }
  162. }
  163. </style>