| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- <template>
- <view class="like-page">
- <!-- 数据加载状态 -->
- <view class="loading-container" v-if="loading">
- <uni-loading type="circle" color="#E91E63"></uni-loading>
- <text class="loading-text">加载中...</text>
- </view>
-
- <!-- 空数据状态 -->
- <view class="empty-container" v-else-if="browseHistory.length === 0">
- <text class="empty-icon">👀</text>
- <text class="empty-text">暂无浏览记录</text>
- <view class="empty-action">
- <button class="action-btn" @click="goRecommend">去推荐看看</button>
- </view>
- </view>
-
- <!-- 浏览记录列表 -->
- <scroll-view class="history-list" scroll-y="true">
- <view class="history-item" v-for="item in browseHistory" :key="item.id" @click="goUserDetail(item.userId)">
- <image class="user-avatar" :src="item.avatar" mode="aspectFill"></image>
- <view class="user-info">
- <view class="user-basic">
- <text class="user-nickname">{{ item.nickname }}</text>
- <text class="user-age">{{ item.age }}岁</text>
- </view>
- <view class="user-details">
- <text class="detail-item" v-if="item.height">{{ item.height }}cm</text>
- <text class="detail-item" v-if="item.weight">{{ item.weight }}kg</text>
- <text class="detail-item" v-if="item.educationText">{{ item.educationText }}</text>
- <text class="detail-item" v-if="item.salaryText">{{ item.salaryText }}</text>
- </view>
- <view class="browse-time">
- <text class="time-text">{{ formatTime(item.viewTime) }}</text>
- </view>
- </view>
- <view class="browse-status">
- <text class="browse-icon">👁️</text>
- </view>
- </view>
- </scroll-view>
- </view>
- </template>
- <script>
- import api from '@/utils/api.js'
- export default {
- data() {
- return {
- browseHistory: [],
- loading: true,
- pageNum: 1,
- pageSize: 20,
- hasMore: true
- }
- },
- onLoad() {
- this.loadBrowseHistory()
- },
- methods: {
- // 加载浏览记录
- async loadBrowseHistory() {
- try {
- this.loading = true
- // 获取当前登录用户ID
- const userId = uni.getStorageSync('userId')
- if (!userId) {
- uni.showToast({
- title: '请先登录',
- icon: 'none'
- })
- return
- }
-
- // 调用API获取浏览记录
- const history = await api.recommend.getBrowseHistory(parseInt(userId), this.pageSize, (this.pageNum - 1) * this.pageSize)
- if (history && Array.isArray(history)) {
- // 处理API返回的数据,转换为页面需要的格式
- this.browseHistory = history.map(item => ({
- id: item.userId,
- userId: item.userId,
- avatar: item.avatarUrl || '/static/close.png',
- nickname: item.nickname || '未设置',
- age: this.calculateAge(item.birthDate),
- height: item.height,
- weight: item.weight,
- educationText: this.getEducationText(item.educationLevel),
- salaryText: this.getSalaryText(item.salaryRange),
- viewTime: item.createTime || new Date().toISOString()
- }))
- } else {
- this.browseHistory = []
- }
- } catch (error) {
- console.error('加载浏览记录失败:', error)
- uni.showToast({
- title: '加载失败,请重试',
- icon: 'none'
- })
- } finally {
- this.loading = false
- }
- },
-
- // 计算年龄
- calculateAge(birthDate) {
- if (!birthDate) return ''
- const birth = new Date(birthDate)
- const now = new Date()
- let age = now.getFullYear() - birth.getFullYear()
- if (now.getMonth() < birth.getMonth() || (now.getMonth() === birth.getMonth() && now.getDate() < birth.getDate())) {
- age--
- }
- return age
- },
-
- // 获取学历文本
- getEducationText(educationLevel) {
- if (educationLevel === undefined || educationLevel === null) return ''
- const educationMap = {
- 1: '高中及以下',
- 2: '大专',
- 3: '本科',
- 4: '硕士',
- 5: '博士'
- }
- return educationMap[educationLevel] || ''
- },
-
- // 获取收入文本
- getSalaryText(salaryRange) {
- if (salaryRange === undefined || salaryRange === null) return ''
- const salaryMap = {
- 1: '<5k',
- 2: '5-10k',
- 3: '10-20k',
- 4: '20-50k',
- 5: '50k+'
- }
- return salaryMap[salaryRange] || ''
- },
-
- // 格式化时间
- formatTime(time) {
- if (!time) return ''
-
- const now = new Date()
- const viewTime = new Date(time)
- const diff = now - viewTime
-
- const minutes = Math.floor(diff / (1000 * 60))
- const hours = Math.floor(diff / (1000 * 60 * 60))
- const days = Math.floor(diff / (1000 * 60 * 60 * 24))
-
- if (minutes < 60) {
- return `${minutes}分钟前`
- } else if (hours < 24) {
- return `${hours}小时前`
- } else if (days < 30) {
- return `${days}天前`
- } else {
- return viewTime.toLocaleDateString()
- }
- },
-
- // 跳转到用户详情页
- goUserDetail(userId) {
- uni.navigateTo({
- url: `/pages/recommend/index?userId=${userId}`,
- fail: (err) => {
- console.error('跳转用户详情失败:', err)
- uni.showToast({
- title: '页面不存在',
- icon: 'none'
- })
- }
- })
- },
-
- // 跳转到推荐页面
- goRecommend() {
- uni.navigateTo({
- url: '/pages/recommend/index'
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .like-page {
- min-height: 100vh;
- background-color: #F5F5F5;
- padding: 0 5rpx;
- box-sizing: border-box;
- overflow-x: hidden;
- }
- .loading-container {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- padding: 100rpx 0;
-
- .loading-text {
- margin-top: 20rpx;
- font-size: 28rpx;
- color: #999999;
- }
- }
- .empty-container {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- padding: 150rpx 0;
-
- .empty-icon {
- font-size: 120rpx;
- margin-bottom: 30rpx;
- }
-
- .empty-text {
- font-size: 32rpx;
- color: #999999;
- margin-bottom: 40rpx;
- }
-
- .action-btn {
- background: linear-gradient(135deg, #FF6B9D 0%, #E91E63 100%);
- color: #FFFFFF;
- border: none;
- padding: 18rpx 70rpx;
- border-radius: 45rpx;
- font-size: 28rpx;
- font-weight: 600;
- box-shadow: 0 6rpx 20rpx rgba(233, 30, 99, 0.3);
- transition: all 0.3s ease;
- letter-spacing: 1rpx;
-
- &:active {
- transform: translateY(2rpx);
- box-shadow: 0 3rpx 12rpx rgba(233, 30, 99, 0.4);
- background: linear-gradient(135deg, #E91E63 0%, #C2185B 100%);
- }
- }
- }
- .history-list {
- padding: 20rpx;
- height: calc(100vh - 88rpx);
- }
- .history-item {
- display: flex;
- align-items: center;
- background-color: #FFFFFF;
- border-radius: 20rpx;
- padding: 20rpx;
- margin-bottom: 20rpx;
- box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
- transition: all 0.3s ease;
-
- &:active {
- transform: translateY(2rpx);
- box-shadow: 0 1rpx 5rpx rgba(0, 0, 0, 0.05);
- }
-
- .user-avatar {
- width: 120rpx;
- height: 120rpx;
- border-radius: 50%;
- margin-right: 20rpx;
- border: 4rpx solid #FFF9F9;
- box-shadow: 0 4rpx 15rpx rgba(233, 30, 99, 0.2);
- }
-
- .user-info {
- flex: 1;
-
- .user-basic {
- display: flex;
- align-items: center;
- margin-bottom: 10rpx;
-
- .user-nickname {
- font-size: 32rpx;
- font-weight: bold;
- color: #333333;
- margin-right: 15rpx;
- }
-
- .user-age {
- font-size: 28rpx;
- color: #666666;
- }
- }
-
- .user-details {
- display: flex;
- flex-wrap: wrap;
- gap: 15rpx;
- margin-bottom: 10rpx;
-
- .detail-item {
- font-size: 24rpx;
- color: #999999;
- background-color: #F5F5F5;
- padding: 6rpx 15rpx;
- border-radius: 15rpx;
- }
- }
-
- .browse-time {
- .time-text {
- font-size: 22rpx;
- color: #CCCCCC;
- }
- }
- }
-
- .browse-status {
- .browse-icon {
- font-size: 40rpx;
- color: #E91E63;
- }
- }
- }
- </style>
|