visited-by-me.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. const diff = now - viewTime
  138. const minutes = Math.floor(diff / (1000 * 60))
  139. const hours = Math.floor(diff / (1000 * 60 * 60))
  140. const days = Math.floor(diff / (1000 * 60 * 60 * 24))
  141. if (minutes < 60) {
  142. return `${minutes}分钟前`
  143. } else if (hours < 24) {
  144. return `${hours}小时前`
  145. } else if (days < 30) {
  146. return `${days}天前`
  147. } else {
  148. return viewTime.toLocaleDateString()
  149. }
  150. },
  151. // 跳转到用户详情页
  152. goUserDetail(userId) {
  153. uni.navigateTo({
  154. url: `/pages/recommend/user-detail?userId=${userId}`,
  155. fail: (err) => {
  156. console.error('跳转用户详情失败:', err)
  157. uni.showToast({
  158. title: '页面不存在',
  159. icon: 'none'
  160. })
  161. }
  162. })
  163. },
  164. // 跳转到推荐页面
  165. goRecommend() {
  166. uni.navigateTo({
  167. url: '/pages/recommend/index'
  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: 100vh;
  229. box-sizing: border-box;
  230. overflow-x: hidden;
  231. }
  232. .history-item {
  233. display: flex;
  234. align-items: center;
  235. background-color: #FFFFFF;
  236. border-radius: 20rpx;
  237. padding: 20rpx;
  238. margin-bottom: 20rpx;
  239. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  240. transition: all 0.3s ease;
  241. &:active {
  242. transform: translateY(2rpx);
  243. box-shadow: 0 1rpx 5rpx rgba(0, 0, 0, 0.05);
  244. }
  245. .user-avatar {
  246. width: 120rpx;
  247. height: 120rpx;
  248. border-radius: 50%;
  249. margin-right: 20rpx;
  250. border: 4rpx solid #FFF9F9;
  251. box-shadow: 0 4rpx 15rpx rgba(233, 30, 99, 0.2);
  252. }
  253. .user-info {
  254. flex: 1;
  255. .user-basic {
  256. display: flex;
  257. align-items: center;
  258. margin-bottom: 10rpx;
  259. .user-nickname {
  260. font-size: 32rpx;
  261. font-weight: bold;
  262. color: #333333;
  263. margin-right: 15rpx;
  264. }
  265. .user-age {
  266. font-size: 28rpx;
  267. color: #666666;
  268. }
  269. }
  270. .user-details {
  271. display: flex;
  272. flex-wrap: wrap;
  273. gap: 15rpx;
  274. margin-bottom: 10rpx;
  275. .detail-item {
  276. font-size: 24rpx;
  277. color: #999999;
  278. background-color: #F5F5F5;
  279. padding: 6rpx 15rpx;
  280. border-radius: 15rpx;
  281. }
  282. }
  283. .browse-time {
  284. .time-text {
  285. font-size: 22rpx;
  286. color: #CCCCCC;
  287. }
  288. }
  289. }
  290. }
  291. </style>