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

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) {