推广中心优化 + 用户资料功能

1. 推广中心优化:
   - 增加"待购买"、"已过期"统计
   - 访问量单独显示
   - 移除10元提现门槛,有收益即可提现
   - 复制文案去掉"专属邀请码"

2. 我的页面:
   - 支持获取微信头像(原生能力)
   - 支持获取微信昵称
   - 新增用户更新API

3. 后台API:
   - referral/data返回expiredCount和expiredUsers
   - 新增user/update接口同步用户信息
This commit is contained in:
卡若
2026-01-29 11:35:56 +08:00
parent 8b2c3f4661
commit a228911170
6 changed files with 271 additions and 35 deletions

View File

@@ -105,18 +105,96 @@ Page({
// 编辑用户资料(头像和昵称)
editProfile() {
wx.showActionSheet({
itemList: ['修改头像', '修改昵称'],
itemList: ['获取微信头像', '获取微信昵称', '从相册选择头像', '手动输入昵称'],
success: (res) => {
if (res.tapIndex === 0) {
this.chooseAvatar()
this.getWechatAvatar()
} else if (res.tapIndex === 1) {
this.getWechatNickname()
} else if (res.tapIndex === 2) {
this.chooseAvatar()
} else if (res.tapIndex === 3) {
this.editNickname()
}
}
})
},
// 选择头像
// 获取微信头像(原生能力)
getWechatAvatar() {
// 使用chooseAvatar API微信原生头像选择
wx.chooseAvatar({
success: async (res) => {
const avatarUrl = res.avatarUrl
wx.showLoading({ title: '更新中...', mask: true })
try {
// 更新本地显示
const userInfo = this.data.userInfo
userInfo.avatar = avatarUrl
this.setData({ userInfo })
app.globalData.userInfo = userInfo
wx.setStorageSync('userInfo', userInfo)
// 同步到服务器
await app.request('/api/user/update', {
method: 'POST',
data: { userId: userInfo.id, avatar: avatarUrl }
})
wx.hideLoading()
wx.showToast({ title: '头像已更新', icon: 'success' })
} catch (e) {
wx.hideLoading()
wx.showToast({ title: '更新失败', icon: 'none' })
}
},
fail: () => {
wx.showToast({ title: '取消选择', icon: 'none' })
}
})
},
// 获取微信昵称(原生能力)
getWechatNickname() {
// 引导用户在弹窗中输入微信昵称
wx.showModal({
title: '获取微信昵称',
content: '请在下方输入您的微信昵称',
editable: true,
placeholderText: '请输入微信昵称',
success: async (res) => {
if (res.confirm && res.content) {
const nickname = res.content.trim()
if (nickname.length < 1 || nickname.length > 20) {
wx.showToast({ title: '昵称1-20个字符', icon: 'none' })
return
}
// 更新本地
const userInfo = this.data.userInfo
userInfo.nickname = nickname
this.setData({ userInfo })
app.globalData.userInfo = userInfo
wx.setStorageSync('userInfo', userInfo)
// 同步到服务器
try {
await app.request('/api/user/update', {
method: 'POST',
data: { userId: userInfo.id, nickname }
})
} catch (e) {
console.log('同步昵称到服务器失败', e)
}
wx.showToast({ title: '昵称已更新', icon: 'success' })
}
}
})
},
// 从相册选择头像
chooseAvatar() {
wx.chooseMedia({
count: 1,
@@ -134,7 +212,12 @@ Page({
app.globalData.userInfo = userInfo
wx.setStorageSync('userInfo', userInfo)
// TODO: 上传到服务器
// 同步到服务器
await app.request('/api/user/update', {
method: 'POST',
data: { userId: userInfo.id, avatar: tempFilePath }
})
wx.hideLoading()
wx.showToast({ title: '头像已更新', icon: 'success' })
} catch (e) {
@@ -145,7 +228,7 @@ Page({
})
},
// 修改昵称
// 手动输入昵称
editNickname() {
wx.showModal({
title: '修改昵称',
@@ -166,7 +249,16 @@ Page({
app.globalData.userInfo = userInfo
wx.setStorageSync('userInfo', userInfo)
// TODO: 上传到服务器
// 同步到服务器
try {
await app.request('/api/user/update', {
method: 'POST',
data: { userId: userInfo.id, nickname: newNickname }
})
} catch (e) {
console.log('同步昵称到服务器失败', e)
}
wx.showToast({ title: '昵称已更新', icon: 'success' })
}
}