|
|
@@ -63,8 +63,35 @@ export default {
|
|
|
async loadBrowseHistory() {
|
|
|
try {
|
|
|
this.loading = true
|
|
|
- // 不调用真实API,显示空数据
|
|
|
- this.browseHistory = []
|
|
|
+ // 获取当前登录用户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({
|
|
|
@@ -76,6 +103,44 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ // 计算年龄
|
|
|
+ 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 ''
|