visited-by-me.vue 8.2 KB

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