|
@@ -1,10 +1,5 @@
|
|
|
<template>
|
|
<template>
|
|
|
<view class="like-page">
|
|
<view class="like-page">
|
|
|
- <!-- 页面标题栏 -->
|
|
|
|
|
- <view class="page-header">
|
|
|
|
|
- <text class="header-title">我喜欢的</text>
|
|
|
|
|
- </view>
|
|
|
|
|
-
|
|
|
|
|
<!-- 数据加载状态 -->
|
|
<!-- 数据加载状态 -->
|
|
|
<view class="loading-container" v-if="loading">
|
|
<view class="loading-container" v-if="loading">
|
|
|
<uni-loading type="circle" color="#E91E63"></uni-loading>
|
|
<uni-loading type="circle" color="#E91E63"></uni-loading>
|
|
@@ -21,7 +16,7 @@
|
|
|
</view>
|
|
</view>
|
|
|
|
|
|
|
|
<!-- 用户列表 -->
|
|
<!-- 用户列表 -->
|
|
|
- <scroll-view class="user-list" scroll-y="true">
|
|
|
|
|
|
|
+ <scroll-view class="user-list" scroll-y="true" @refresherrefresh="onRefresh" @scrolltolower="onLoadMore" refresher-enabled="true" refresher-triggered="refreshing">
|
|
|
<view class="user-item" v-for="user in users" :key="user.userId" @click="goUserDetail(user.userId)">
|
|
<view class="user-item" v-for="user in users" :key="user.userId" @click="goUserDetail(user.userId)">
|
|
|
<image class="user-avatar" :src="user.avatar" mode="aspectFill"></image>
|
|
<image class="user-avatar" :src="user.avatar" mode="aspectFill"></image>
|
|
|
<view class="user-info">
|
|
<view class="user-info">
|
|
@@ -39,10 +34,16 @@
|
|
|
<text class="location-text">{{ user.location }}</text>
|
|
<text class="location-text">{{ user.location }}</text>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
- <view class="like-status">
|
|
|
|
|
|
|
+ <view class="like-status" @click.stop="cancelLike(user.userId)">
|
|
|
<text class="like-icon">❤️</text>
|
|
<text class="like-icon">❤️</text>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 加载更多提示 -->
|
|
|
|
|
+ <view class="load-more" v-if="users.length > 0">
|
|
|
|
|
+ <text v-if="hasMore">加载中...</text>
|
|
|
|
|
+ <text v-else>没有更多数据了</text>
|
|
|
|
|
+ </view>
|
|
|
</scroll-view>
|
|
</scroll-view>
|
|
|
</view>
|
|
</view>
|
|
|
</template>
|
|
</template>
|
|
@@ -55,6 +56,7 @@ export default {
|
|
|
return {
|
|
return {
|
|
|
users: [],
|
|
users: [],
|
|
|
loading: true,
|
|
loading: true,
|
|
|
|
|
+ refreshing: false,
|
|
|
pageNum: 1,
|
|
pageNum: 1,
|
|
|
pageSize: 20,
|
|
pageSize: 20,
|
|
|
hasMore: true
|
|
hasMore: true
|
|
@@ -67,9 +69,36 @@ export default {
|
|
|
// 加载我喜欢的用户列表
|
|
// 加载我喜欢的用户列表
|
|
|
async loadUsers() {
|
|
async loadUsers() {
|
|
|
try {
|
|
try {
|
|
|
- this.loading = true
|
|
|
|
|
- // 不调用真实API,显示空数据
|
|
|
|
|
- this.users = []
|
|
|
|
|
|
|
+ // 从本地存储获取当前用户ID
|
|
|
|
|
+ const userId = parseInt(uni.getStorageSync('userId') || 1)
|
|
|
|
|
+ // 计算偏移量
|
|
|
|
|
+ const offset = (this.pageNum - 1) * this.pageSize
|
|
|
|
|
+ // 调用后端API获取我喜欢的用户列表
|
|
|
|
|
+ const likedUsers = await api.recommend.getLikedUsers(userId, this.pageSize, offset)
|
|
|
|
|
+ // 处理返回的数据,确保字段名匹配页面需要的格式
|
|
|
|
|
+ const formattedUsers = likedUsers.map(user => ({
|
|
|
|
|
+ userId: user.userId,
|
|
|
|
|
+ nickname: user.nickname,
|
|
|
|
|
+ avatar: user.avatarUrl || '',
|
|
|
|
|
+ age: this.calculateAge(user.birthDate),
|
|
|
|
|
+ height: user.height,
|
|
|
|
|
+ weight: user.weight,
|
|
|
|
|
+ educationText: this.formatEducation(user.educationLevel),
|
|
|
|
|
+ salaryText: this.formatSalary(user.salaryRange),
|
|
|
|
|
+ location: this.formatLocation(user.provinceId, user.cityId, user.areaId)
|
|
|
|
|
+ }))
|
|
|
|
|
+
|
|
|
|
|
+ // 根据是否是刷新操作来处理数据
|
|
|
|
|
+ if (this.pageNum === 1) {
|
|
|
|
|
+ // 首次加载或刷新,直接替换数据
|
|
|
|
|
+ this.users = formattedUsers
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 加载更多,追加数据
|
|
|
|
|
+ this.users = [...this.users, ...formattedUsers]
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 判断是否还有更多数据
|
|
|
|
|
+ this.hasMore = formattedUsers.length >= this.pageSize
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error('加载喜欢的用户失败:', error)
|
|
console.error('加载喜欢的用户失败:', error)
|
|
|
uni.showToast({
|
|
uni.showToast({
|
|
@@ -78,6 +107,71 @@ export default {
|
|
|
})
|
|
})
|
|
|
} finally {
|
|
} finally {
|
|
|
this.loading = false
|
|
this.loading = false
|
|
|
|
|
+ this.refreshing = false
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 下拉刷新
|
|
|
|
|
+ async onRefresh() {
|
|
|
|
|
+ this.refreshing = true
|
|
|
|
|
+ this.pageNum = 1
|
|
|
|
|
+ this.hasMore = true
|
|
|
|
|
+ await this.loadUsers()
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 上拉加载更多
|
|
|
|
|
+ async onLoadMore() {
|
|
|
|
|
+ if (this.loading || !this.hasMore) return
|
|
|
|
|
+ this.pageNum++
|
|
|
|
|
+ await this.loadUsers()
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 计算年龄
|
|
|
|
|
+ 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
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 格式化教育程度
|
|
|
|
|
+ formatEducation(educationLevel) {
|
|
|
|
|
+ if (!educationLevel) return ''
|
|
|
|
|
+ const map = {1:'高中',2:'大专',3:'本科',4:'硕士',5:'博士'}
|
|
|
|
|
+ return map[educationLevel] || ''
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 格式化薪资
|
|
|
|
|
+ formatSalary(salaryRange) {
|
|
|
|
|
+ if (!salaryRange) return ''
|
|
|
|
|
+ const map = {1:'<5k',2:'5-10k',3:'10-20k',4:'20-50k',5:'50k+'}
|
|
|
|
|
+ return map[salaryRange] || ''
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 格式化地理位置
|
|
|
|
|
+ formatLocation(provinceId, cityId, areaId) {
|
|
|
|
|
+ // 这里简化处理,实际可能需要根据ID查询名称
|
|
|
|
|
+ return ''
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 取消喜欢
|
|
|
|
|
+ async cancelLike(targetUserId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 从本地存储获取当前用户ID
|
|
|
|
|
+ const userId = parseInt(uni.getStorageSync('userId') || 1)
|
|
|
|
|
+ // 调用后端API取消喜欢
|
|
|
|
|
+ await api.recommend.feedback({ userId, targetUserId, type: 'dislike' })
|
|
|
|
|
+ // 刷新页面,重新加载喜欢的用户列表
|
|
|
|
|
+ await this.onRefresh()
|
|
|
|
|
+ // 显示操作成功提示
|
|
|
|
|
+ uni.showToast({ title: '已取消喜欢', icon: 'success' })
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('取消喜欢失败:', error)
|
|
|
|
|
+ uni.showToast({ title: '取消喜欢失败', icon: 'none' })
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -109,20 +203,9 @@ export default {
|
|
|
.like-page {
|
|
.like-page {
|
|
|
min-height: 100vh;
|
|
min-height: 100vh;
|
|
|
background-color: #F5F5F5;
|
|
background-color: #F5F5F5;
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-.page-header {
|
|
|
|
|
- height: 88rpx;
|
|
|
|
|
- line-height: 88rpx;
|
|
|
|
|
- background-color: #E91E63;
|
|
|
|
|
- text-align: center;
|
|
|
|
|
- position: relative;
|
|
|
|
|
-
|
|
|
|
|
- .header-title {
|
|
|
|
|
- font-size: 36rpx;
|
|
|
|
|
- font-weight: bold;
|
|
|
|
|
- color: #FFFFFF;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ padding: 0 5rpx;
|
|
|
|
|
+ box-sizing: border-box;
|
|
|
|
|
+ overflow-x: hidden;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
.loading-container {
|
|
.loading-container {
|
|
@@ -179,7 +262,16 @@ export default {
|
|
|
|
|
|
|
|
.user-list {
|
|
.user-list {
|
|
|
padding: 20rpx;
|
|
padding: 20rpx;
|
|
|
- height: calc(100vh - 88rpx);
|
|
|
|
|
|
|
+ height: 100vh;
|
|
|
|
|
+ box-sizing: border-box;
|
|
|
|
|
+ overflow-x: hidden;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.load-more {
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+ padding: 30rpx 0;
|
|
|
|
|
+ font-size: 28rpx;
|
|
|
|
|
+ color: #999999;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
.user-item {
|
|
.user-item {
|