修复:微信头像选择后未生效

This commit is contained in:
2026-10-10 18:01:34 +08:00
parent ff98e89ab7
commit d57f9b736a
3 changed files with 22 additions and 5 deletions
+15 -4
View File
@@ -48,9 +48,12 @@ Page({
const app = getApp()
const state = buildPageState(app.globalData.userInfo || {}, app.globalData.shopName || BRAND_CONFIG.defaultShopName)
this.setData(state)
this.loadProfile()
},
onShow() {
if (!this._refreshAfterAccountSettings) return
this._refreshAfterAccountSettings = false
this.loadProfile()
},
@@ -107,22 +110,30 @@ Page({
},
goAccountSettings() {
wx.navigateTo({ url: '/pages/account-settings/index' })
this._refreshAfterAccountSettings = true
wx.navigateTo({
url: '/pages/account-settings/index',
fail: () => { this._refreshAfterAccountSettings = false }
})
},
async uploadAvatar(filePath) {
if (!filePath) return
this.setData({ avatarUploading: true })
const previousAvatar = this.data.form.avatar
this.setData({ avatarUploading: true, 'form.avatar': filePath })
try {
const avatar = await uploadProfileImage(filePath)
this.setData({ 'form.avatar': avatar })
} catch (error) {
this.setData({ 'form.avatar': previousAvatar })
throw error
} finally {
this.setData({ avatarUploading: false })
}
},
async chooseAvatar() {
if (this.data.avatarUploading || this.data.saving) return
if (this.data.loading || this.data.avatarUploading || this.data.saving) return
try {
const filePath = await chooseImageFilePath()
if (!filePath) return
@@ -133,7 +144,7 @@ Page({
},
async chooseWechatAvatar(event) {
if (this.data.avatarUploading || this.data.saving) return
if (this.data.loading || this.data.avatarUploading || this.data.saving) return
try {
await this.uploadAvatar(event.detail && event.detail.avatarUrl)
} catch (error) {
@@ -20,7 +20,7 @@
<text class="expand-arrow {{wechatProfileExpanded ? 'expanded' : ''}}">›</text>
</view>
<view wx:if="{{wechatProfileExpanded}}" class="wechat-profile-panel">
<button class="wechat-avatar-picker" open-type="chooseAvatar" loading="{{avatarUploading}}" disabled="{{saving}}" bindchooseavatar="chooseWechatAvatar">
<button class="wechat-avatar-picker" open-type="chooseAvatar" loading="{{avatarUploading}}" disabled="{{loading || saving}}" bindchooseavatar="chooseWechatAvatar">
<image wx:if="{{form.avatar}}" src="{{form.avatar}}" mode="aspectFill"></image>
<text wx:else>{{avatarText}}</text>
<view class="wechat-avatar-tip">选择微信头像</view>
+6
View File
@@ -1,5 +1,11 @@
# 项目变更记录
## 2026-10-10 Salon 微信头像选择即时预览修复
- 修复微信头像选择器返回页面时 `onShow` 重新加载旧资料、覆盖新头像的问题。
- 选择微信头像或本地图片后立即预览,上传成功替换为正式地址,上传失败恢复原头像。
- 个人信息页仅首次进入和从账号设置返回时刷新资料,避免系统选择器唤回页面时重置未保存表单。
## 2026-10-10 Salon 个人资料与手机号入口优化
- 个人信息页手机号改为只读展示,点击跳转账号设置;个人资料保存请求不再提交联系电话或手机号字段。