84 lines
1.9 KiB
JavaScript
84 lines
1.9 KiB
JavaScript
const request = require('../../utils/request')
|
|
|
|
function addCacheVersion(url, version) {
|
|
if (!url) {
|
|
return ''
|
|
}
|
|
const joiner = url.includes('?') ? '&' : '?'
|
|
return `${url}${joiner}v=${encodeURIComponent(version)}`
|
|
}
|
|
|
|
Page({
|
|
data: {
|
|
loading: false,
|
|
userInfo: null,
|
|
auditTextMap: {
|
|
0: '未提交',
|
|
1: '待审核',
|
|
2: '已通过',
|
|
3: '已驳回'
|
|
}
|
|
},
|
|
|
|
onShow() {
|
|
this.refreshFromCache()
|
|
this.loadProfile(true)
|
|
},
|
|
|
|
async loadProfile(silent = false) {
|
|
if (!silent) {
|
|
this.setData({ loading: true })
|
|
}
|
|
try {
|
|
const userInfo = await request({ url: '/users/me' })
|
|
this.applyUserInfo(userInfo)
|
|
wx.setStorageSync('profile_page_cache', userInfo)
|
|
} catch (err) {
|
|
console.error('Load profile failed:', err)
|
|
if (!this.data.userInfo) {
|
|
this.setData({ userInfo: null })
|
|
}
|
|
} finally {
|
|
if (!silent) {
|
|
this.setData({ loading: false })
|
|
}
|
|
}
|
|
},
|
|
|
|
applyUserInfo(userInfo) {
|
|
const avatarVersion = Date.now().toString()
|
|
this.setData({
|
|
userInfo: {
|
|
...userInfo,
|
|
avatar_url: addCacheVersion(userInfo.avatar_url || '', avatarVersion),
|
|
avatar_blur_url: addCacheVersion(userInfo.avatar_blur_url || '', avatarVersion),
|
|
nicknameText: userInfo.nickname || '未设置昵称',
|
|
auditStatusText: this.data.auditTextMap[userInfo.audit_status] || '未知'
|
|
}
|
|
})
|
|
},
|
|
|
|
refreshFromCache() {
|
|
const cached = wx.getStorageSync('profile_page_cache')
|
|
if (cached) {
|
|
this.applyUserInfo(cached)
|
|
}
|
|
},
|
|
|
|
goEdit() {
|
|
wx.navigateTo({ url: '/pages/profile-edit/profile-edit' })
|
|
},
|
|
|
|
goAudit() {
|
|
wx.navigateTo({ url: '/pages/audit-status/audit-status' })
|
|
},
|
|
|
|
goMyActivities() {
|
|
wx.navigateTo({ url: '/pages/my-activities/my-activities' })
|
|
},
|
|
|
|
goMyMatches() {
|
|
wx.navigateTo({ url: '/pages/my-matches/my-matches' })
|
|
}
|
|
})
|