visited-by-me.vue 8.6 KB

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