visited-by-me.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <view class="like-page">
  3. <!-- 数据加载状态 -->
  4. <view class="loading-container" v-if="loading">
  5. <uni-loading type="circle" color="#E91E63"></uni-loading>
  6. <text class="loading-text">加载中...</text>
  7. </view>
  8. <!-- 空数据状态 -->
  9. <view class="empty-container" v-else-if="browseHistory.length === 0">
  10. <text class="empty-icon">👀</text>
  11. <text class="empty-text">暂无浏览记录</text>
  12. <view class="empty-action">
  13. <button class="action-btn" @click="goRecommend">去推荐看看</button>
  14. </view>
  15. </view>
  16. <!-- 浏览记录列表 -->
  17. <scroll-view
  18. class="history-list"
  19. scroll-y="true"
  20. @scrolltolower="loadMore"
  21. lower-threshold="50"
  22. >
  23. <view class="history-item" v-for="item in browseHistory" :key="item.userId" @click="goUserDetail(item.userId)">
  24. <image class="user-avatar" :src="item.avatar" mode="aspectFill"></image>
  25. <view class="user-info">
  26. <view class="user-basic">
  27. <text class="user-nickname">{{ item.nickname }}</text>
  28. <text class="user-age">{{ item.age }}岁</text>
  29. </view>
  30. <view class="user-details">
  31. <text class="detail-item" v-if="item.height">{{ item.height }}cm</text>
  32. <text class="detail-item" v-if="item.weight">{{ item.weight }}kg</text>
  33. <text class="detail-item" v-if="item.educationText">{{ item.educationText }}</text>
  34. <text class="detail-item" v-if="item.salaryText">{{ item.salaryText }}</text>
  35. </view>
  36. <view class="browse-time">
  37. <text class="time-text">{{ formatTime(item.viewTime) }}</text>
  38. </view>
  39. </view>
  40. <view class="browse-status">
  41. <text class="browse-icon">👁️</text>
  42. </view>
  43. </view>
  44. <!-- 加载更多提示 -->
  45. <view class="load-more" v-if="hasMore && !loading">
  46. <text class="load-more-text">上拉加载更多</text>
  47. </view>
  48. <view class="load-more" v-if="!hasMore && browseHistory.length > 0">
  49. <text class="load-more-text">没有更多数据了</text>
  50. </view>
  51. </scroll-view>
  52. </view>
  53. </template>
  54. <script>
  55. import api from '@/utils/api.js'
  56. export default {
  57. data() {
  58. return {
  59. browseHistory: [],
  60. loading: true,
  61. pageNum: 1,
  62. pageSize: 20,
  63. hasMore: true
  64. }
  65. },
  66. onLoad() {
  67. this.loadBrowseHistory()
  68. },
  69. // 下拉刷新
  70. onPullDownRefresh() {
  71. this.loadBrowseHistory(true)
  72. },
  73. methods: {
  74. // 加载浏览记录
  75. async loadBrowseHistory(isRefresh = false) {
  76. try {
  77. this.loading = true
  78. // 从本地存储获取当前用户ID
  79. const userInfo = uni.getStorageSync('userInfo')
  80. if (!userInfo || !userInfo.userId) {
  81. uni.showToast({
  82. title: '请先登录',
  83. icon: 'none'
  84. })
  85. return
  86. }
  87. // 如果是刷新,则重置页码
  88. if (isRefresh) {
  89. this.pageNum = 1
  90. this.hasMore = true
  91. }
  92. // 如果没有更多数据,则直接返回
  93. if (!this.hasMore) {
  94. return
  95. }
  96. // 调用API获取浏览记录
  97. const response = await api.user.getBrowseHistory(userInfo.userId, this.pageNum, this.pageSize)
  98. // 处理返回数据
  99. if (isRefresh) {
  100. // 刷新:替换原有数据
  101. this.browseHistory = response.records || []
  102. } else {
  103. // 加载更多:追加数据
  104. this.browseHistory = this.browseHistory.concat(response.records || [])
  105. }
  106. // 判断是否还有更多数据
  107. this.hasMore = this.browseHistory.length < response.total
  108. // 如果还有更多数据,则页码加1
  109. if (this.hasMore) {
  110. this.pageNum++
  111. }
  112. } catch (error) {
  113. console.error('加载浏览记录失败:', error)
  114. uni.showToast({
  115. title: '加载失败,请重试',
  116. icon: 'none'
  117. })
  118. } finally {
  119. this.loading = false
  120. // 停止下拉刷新
  121. if (isRefresh) {
  122. uni.stopPullDownRefresh()
  123. }
  124. }
  125. },
  126. // 格式化时间
  127. formatTime(time) {
  128. if (!time) return ''
  129. const now = new Date()
  130. const viewTime = new Date(time)
  131. const diff = now - viewTime
  132. const minutes = Math.floor(diff / (1000 * 60))
  133. const hours = Math.floor(diff / (1000 * 60 * 60))
  134. const days = Math.floor(diff / (1000 * 60 * 60 * 24))
  135. if (minutes < 60) {
  136. return `${minutes}分钟前`
  137. } else if (hours < 24) {
  138. return `${hours}小时前`
  139. } else if (days < 30) {
  140. return `${days}天前`
  141. } else {
  142. return viewTime.toLocaleDateString()
  143. }
  144. },
  145. // 跳转到用户详情页
  146. goUserDetail(userId) {
  147. uni.navigateTo({
  148. url: `/pages/recommend/index?userId=${userId}`,
  149. fail: (err) => {
  150. console.error('跳转用户详情失败:', err)
  151. uni.showToast({
  152. title: '页面不存在',
  153. icon: 'none'
  154. })
  155. }
  156. })
  157. },
  158. // 跳转到推荐页面
  159. goRecommend() {
  160. uni.navigateTo({
  161. url: '/pages/recommend/index'
  162. })
  163. },
  164. // 上拉加载更多
  165. loadMore() {
  166. if (!this.loading && this.hasMore) {
  167. this.loadBrowseHistory()
  168. }
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .like-page {
  175. min-height: 100vh;
  176. background-color: #F5F5F5;
  177. padding: 0 5rpx;
  178. box-sizing: border-box;
  179. overflow-x: hidden;
  180. }
  181. .loading-container {
  182. display: flex;
  183. flex-direction: column;
  184. align-items: center;
  185. justify-content: center;
  186. padding: 100rpx 0;
  187. .loading-text {
  188. margin-top: 20rpx;
  189. font-size: 28rpx;
  190. color: #999999;
  191. }
  192. }
  193. .empty-container {
  194. display: flex;
  195. flex-direction: column;
  196. align-items: center;
  197. justify-content: center;
  198. padding: 150rpx 0;
  199. .empty-icon {
  200. font-size: 120rpx;
  201. margin-bottom: 30rpx;
  202. }
  203. .empty-text {
  204. font-size: 32rpx;
  205. color: #999999;
  206. margin-bottom: 40rpx;
  207. }
  208. .action-btn {
  209. background: linear-gradient(135deg, #FF6B9D 0%, #E91E63 100%);
  210. color: #FFFFFF;
  211. border: none;
  212. padding: 18rpx 70rpx;
  213. border-radius: 45rpx;
  214. font-size: 28rpx;
  215. font-weight: 600;
  216. box-shadow: 0 6rpx 20rpx rgba(233, 30, 99, 0.3);
  217. transition: all 0.3s ease;
  218. letter-spacing: 1rpx;
  219. &:active {
  220. transform: translateY(2rpx);
  221. box-shadow: 0 3rpx 12rpx rgba(233, 30, 99, 0.4);
  222. background: linear-gradient(135deg, #E91E63 0%, #C2185B 100%);
  223. }
  224. }
  225. }
  226. .history-list {
  227. padding: 20rpx;
  228. height: calc(100vh - 88rpx);
  229. }
  230. .load-more {
  231. text-align: center;
  232. padding: 30rpx 0;
  233. color: #999;
  234. font-size: 24rpx;
  235. }
  236. .history-item {
  237. display: flex;
  238. align-items: center;
  239. background-color: #FFFFFF;
  240. border-radius: 20rpx;
  241. padding: 20rpx;
  242. margin-bottom: 20rpx;
  243. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  244. transition: all 0.3s ease;
  245. &:active {
  246. transform: translateY(2rpx);
  247. box-shadow: 0 1rpx 5rpx rgba(0, 0, 0, 0.05);
  248. }
  249. .user-avatar {
  250. width: 120rpx;
  251. height: 120rpx;
  252. border-radius: 50%;
  253. margin-right: 20rpx;
  254. border: 4rpx solid #FFF9F9;
  255. box-shadow: 0 4rpx 15rpx rgba(233, 30, 99, 0.2);
  256. }
  257. .user-info {
  258. flex: 1;
  259. .user-basic {
  260. display: flex;
  261. align-items: center;
  262. margin-bottom: 10rpx;
  263. .user-nickname {
  264. font-size: 32rpx;
  265. font-weight: bold;
  266. color: #333333;
  267. margin-right: 15rpx;
  268. }
  269. .user-age {
  270. font-size: 28rpx;
  271. color: #666666;
  272. }
  273. }
  274. .user-details {
  275. display: flex;
  276. flex-wrap: wrap;
  277. gap: 15rpx;
  278. margin-bottom: 10rpx;
  279. .detail-item {
  280. font-size: 24rpx;
  281. color: #999999;
  282. background-color: #F5F5F5;
  283. padding: 6rpx 15rpx;
  284. border-radius: 15rpx;
  285. }
  286. }
  287. .browse-time {
  288. .time-text {
  289. font-size: 22rpx;
  290. color: #CCCCCC;
  291. }
  292. }
  293. }
  294. .browse-status {
  295. .browse-icon {
  296. font-size: 40rpx;
  297. color: #E91E63;
  298. }
  299. }
  300. }
  301. </style>