diff --git a/xuan-deduct-uniapp/src/pages/mine/account.vue b/xuan-deduct-uniapp/src/pages/mine/account.vue index 339a4a9..5b428c9 100644 --- a/xuan-deduct-uniapp/src/pages/mine/account.vue +++ b/xuan-deduct-uniapp/src/pages/mine/account.vue @@ -3,7 +3,7 @@ - {{ userInfo.username || '玄机用户' }} + {{ userInfo.username || userInfo.nickname || '玄机用户' }} ID: {{ userInfo.userId || '100001' }} @@ -56,37 +56,56 @@ export default { userId: '', username: '玄机用户', avatarUrl: '', - phone: '' - } + phone: '', + nickname: '', + vipLevel: 0, + coins: 0, + streakDays: 0 + }, + defaultAvatar: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0' } }, onShow() { this.loadUserInfo() }, methods: { - loadUserInfo() { + async loadUserInfo() { const userInfoStr = uni.getStorageSync('userInfo') if (userInfoStr) { - this.userInfo = JSON.parse(userInfoStr) + const localUserInfo = JSON.parse(userInfoStr) + try { + const res = await api.userApi.getInfo(localUserInfo.userId) + if (res.success && res.data) { + this.userInfo = res.data + uni.setStorageSync('userInfo', JSON.stringify(res.data)) + } else { + this.userInfo = localUserInfo + } + } catch (e) { + console.error('获取用户信息失败:', e) + this.userInfo = localUserInfo + } } }, - bindPhone() { + async bindPhone() { uni.showModal({ title: '绑定手机号', editable: true, placeholderText: '请输入手机号', success: async (res) => { if (res.confirm && res.content) { - this.userInfo.phone = res.content try { - await api.userApi.updatePhone(this.userInfo.userId, this.userInfo.phone) + await api.userApi.updatePhone(this.userInfo.userId, res.content) + this.userInfo.phone = res.content + uni.setStorageSync('userInfo', JSON.stringify(this.userInfo)) uni.showToast({ title: '绑定成功', icon: 'success' }) } catch (e) { + console.error('绑定手机号失败:', e) uni.showToast({ - title: '绑定失败', + title: '绑定失败:' + (e.message || '未知错误'), icon: 'none' }) } diff --git a/xuan-deduct-uniapp/src/utils/api.js b/xuan-deduct-uniapp/src/utils/api.js index 3e1d1e5..ce09d5c 100644 --- a/xuan-deduct-uniapp/src/utils/api.js +++ b/xuan-deduct-uniapp/src/utils/api.js @@ -346,6 +346,13 @@ const userApi = { data: { userId: userId } }) }, + getInfo: (userId) => { + return request({ + url: '/user/info', + method: 'GET', + data: { userId: userId } + }) + }, updateVipLevel: (userId, vipLevel) => { return request({ url: '/user/vip',