完善小程序登录排班与个人资料流程
This commit is contained in:
@@ -25,6 +25,8 @@ function buildPageState(profile, fallbackShopName) {
|
||||
form: {
|
||||
nickname: source.nickname || '',
|
||||
avatar: normalizeAvatar(source.avatar),
|
||||
avatarFileId: '',
|
||||
avatarChanged: false,
|
||||
wechatId: source.wechatId || '',
|
||||
signature: source.signature || ''
|
||||
}
|
||||
@@ -41,7 +43,7 @@ Page({
|
||||
roleText: '管理端',
|
||||
shopName: BRAND_CONFIG.defaultShopName,
|
||||
phoneDisplay: '未绑定',
|
||||
form: { nickname: '', avatar: '', wechatId: '', signature: '' }
|
||||
form: { nickname: '', avatar: '', avatarFileId: '', avatarChanged: false, wechatId: '', signature: '' }
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
@@ -116,12 +118,21 @@ Page({
|
||||
async uploadAvatar(filePath) {
|
||||
if (!filePath) return
|
||||
const previousAvatar = this.data.form.avatar
|
||||
const previousAvatarFileId = this.data.form.avatarFileId
|
||||
this.setData({ avatarUploading: true, 'form.avatar': filePath })
|
||||
try {
|
||||
const avatar = await uploadProfileImage(filePath)
|
||||
this.setData({ 'form.avatar': avatar })
|
||||
const uploaded = await uploadProfileImage(filePath)
|
||||
this.setData({
|
||||
'form.avatar': filePath,
|
||||
'form.avatarFileId': uploaded && uploaded.fileId ? String(uploaded.fileId) : '',
|
||||
'form.avatarChanged': true
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({ 'form.avatar': previousAvatar })
|
||||
this.setData({
|
||||
'form.avatar': previousAvatar,
|
||||
'form.avatarFileId': previousAvatarFileId,
|
||||
'form.avatarChanged': false
|
||||
})
|
||||
throw error
|
||||
} finally {
|
||||
this.setData({ avatarUploading: false })
|
||||
@@ -160,21 +171,26 @@ Page({
|
||||
wx.showToast({ title: '请填写昵称', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (form.avatarChanged && !form.avatarFileId) {
|
||||
wx.showToast({ title: '头像上传未完成,请重新选择', icon: 'none', duration: 3000 })
|
||||
return
|
||||
}
|
||||
this.setData({ saving: true })
|
||||
try {
|
||||
await userApi.updateInfo({
|
||||
const payload = {
|
||||
nickname,
|
||||
avatar: form.avatar || '',
|
||||
wechatId: String(form.wechatId || '').trim(),
|
||||
signature: String(form.signature || '').trim()
|
||||
})
|
||||
}
|
||||
if (form.avatarChanged) payload.avatarFileId = form.avatarFileId || undefined
|
||||
await userApi.updateInfo(payload)
|
||||
profileCache.invalidate()
|
||||
const profile = await profileCache.getProfile({ force: true })
|
||||
this.syncProfileToSession(profile)
|
||||
wx.showToast({ title: '已保存', icon: 'success' })
|
||||
wx.showToast({ title: '已保存', icon: 'success', duration: 3000 })
|
||||
setTimeout(() => wx.navigateBack(), 350)
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '保存失败', icon: 'none' })
|
||||
wx.showToast({ title: error.message || '保存失败', icon: 'none', duration: 3000 })
|
||||
} finally {
|
||||
this.setData({ saving: false })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user