wechatList.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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('userInfo', JSON.stringify(res.user));
  86. uni.$emit('refreshIM');
  87. uni.$emit('showHealthButler');
  88. this.goPage();
  89. } else {
  90. uni.showToast({
  91. title: res.msg,
  92. icon: 'none'
  93. });
  94. }
  95. },
  96. goPage() {
  97. let pages = getCurrentPages();
  98. let url = pages[pages.length - 1];
  99. let openUrl = uni.getStorageSync("openUrl");
  100. if (openUrl) {
  101. uni.navigateTo({
  102. url: openUrl,
  103. success: function(res) {
  104. uni.removeStorageSync("openUrl")
  105. }
  106. })
  107. } else {
  108. this.$updateMsgDot();
  109. this.$setSource();
  110. uni.reLaunch({
  111. url: '/pages_im/pages/conversation/conversationList/index',
  112. animationType: 'none',
  113. animationDuration: 2000
  114. });
  115. return;
  116. if (pages.length == 1) {
  117. uni.reLaunch({
  118. url: '/pages_im/pages/conversation/conversationList/index',
  119. //url: '../course/video/living-app',
  120. animationType: 'none',
  121. animationDuration: 2000
  122. });
  123. } else {
  124. //this.$navBack();
  125. }
  126. }
  127. },
  128. },
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .popupBox {
  133. padding: 48rpx 24rpx;
  134. padding-top: 0rpx;
  135. margin-top: 24rpx;
  136. width: 100vw;
  137. box-sizing: border-box;
  138. flex-direction: column;
  139. .popupBox-content {
  140. padding: 24rpx;
  141. padding-bottom: 0;
  142. border-radius: 16rpx;
  143. .popupBox-content-list {
  144. padding-bottom: 24rpx;
  145. border-bottom: 1rpx solid #F7F8FA;
  146. &:last-child {
  147. border-bottom: none;
  148. }
  149. .last-login-tag {
  150. font-size: 24rpx;
  151. color: #FFFFFF;
  152. background-color: #FF5C03;
  153. padding: 2rpx 10rpx;
  154. border-radius: 6rpx;
  155. margin-left: 16rpx;
  156. line-height: 1.5;
  157. }
  158. }
  159. }
  160. }
  161. </style>