xiangqinxiaochengxu/miniprogram/pages/my-matches/my-matches.js
2026-04-17 10:49:14 +08:00

46 lines
1.4 KiB
JavaScript

const request = require('../../utils/request')
Page({
data: {
matches: []
},
onShow() {
this.loadMatches()
},
async loadMatches() {
try {
const matches = await request({ url: '/matches/my' })
const safeMatches = Array.isArray(matches) ? matches : []
this.setData({
matches: safeMatches.map((item) => ({
...item,
other_user: {
...(item.other_user || {}),
nicknameText: item.other_user && item.other_user.nickname ? item.other_user.nickname : '匿名用户',
cityText: item.other_user && item.other_user.city ? item.other_user.city : '城市未知',
educationText: item.other_user && item.other_user.education ? item.other_user.education : '学历未知',
hobbiesText: item.other_user && Array.isArray(item.other_user.hobbies) ? item.other_user.hobbies.join('、') : '未填写爱好',
hobbies_text: item.other_user && Array.isArray(item.other_user.hobbies) ? item.other_user.hobbies.join('、') : ''
}
}))
})
} catch (err) {
console.error('Load my matches failed:', err)
wx.showToast({ title: '我的匹配加载失败', icon: 'none' })
this.setData({ matches: [] })
}
},
viewDetail(e) {
const matchId = e.currentTarget.dataset.matchId
if (!matchId) {
return
}
wx.navigateTo({
url: `/pages/match-detail/match-detail?match_id=${matchId}`
})
}
})