优化:个人资料与手机号设置入口

This commit is contained in:
2026-10-10 17:56:44 +08:00
parent 0ceea1578f
commit cd08d3c3b0
7 changed files with 94 additions and 17 deletions
+41 -13
View File
@@ -20,10 +20,10 @@ function buildPageState(profile, fallbackShopName) {
avatarText: card.avatarText,
roleText: resolveRoleText(source.type),
shopName: card.shopName,
phoneDisplay: source.maskedPhone || source.phone || '未绑定',
form: {
nickname: source.nickname || '',
avatar: normalizeAvatar(source.avatar),
contactPhone: source.contactPhone || '',
wechatId: source.wechatId || '',
signature: source.signature || ''
}
@@ -39,7 +39,9 @@ Page({
avatarText: '用',
roleText: '管理端',
shopName: BRAND_CONFIG.defaultShopName,
form: { nickname: '', avatar: '', contactPhone: '', wechatId: '', signature: '' }
phoneDisplay: '未绑定',
wechatProfileExpanded: false,
form: { nickname: '', avatar: '', wechatId: '', signature: '' }
},
onLoad() {
@@ -92,18 +94,50 @@ Page({
this.setData(nextData)
},
toggleWechatProfile() {
this.setData({ wechatProfileExpanded: !this.data.wechatProfileExpanded })
},
onWechatNicknameInput(event) {
const nickname = event.detail.value
this.setData({
'form.nickname': nickname,
avatarText: Array.from(String(nickname || '').trim())[0] || '用'
})
},
goAccountSettings() {
wx.navigateTo({ url: '/pages/account-settings/index' })
},
async uploadAvatar(filePath) {
if (!filePath) return
this.setData({ avatarUploading: true })
try {
const avatar = await uploadProfileImage(filePath)
this.setData({ 'form.avatar': avatar })
} finally {
this.setData({ avatarUploading: false })
}
},
async chooseAvatar() {
if (this.data.avatarUploading || this.data.saving) return
try {
const filePath = await chooseImageFilePath()
if (!filePath) return
this.setData({ avatarUploading: true })
const avatar = await uploadProfileImage(filePath)
this.setData({ 'form.avatar': avatar })
await this.uploadAvatar(filePath)
} catch (error) {
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
} finally {
this.setData({ avatarUploading: false })
}
},
async chooseWechatAvatar(event) {
if (this.data.avatarUploading || this.data.saving) return
try {
await this.uploadAvatar(event.detail && event.detail.avatarUrl)
} catch (error) {
wx.showToast({ title: error.message || '微信头像获取失败', icon: 'none' })
}
},
@@ -111,21 +145,15 @@ Page({
if (this.data.saving || this.data.avatarUploading) return
const form = this.data.form
const nickname = String(form.nickname || '').trim()
const contactPhone = String(form.contactPhone || '').trim()
if (!nickname) {
wx.showToast({ title: '请填写昵称', icon: 'none' })
return
}
if (contactPhone && !/^1[3-9]\d{9}$/.test(contactPhone)) {
wx.showToast({ title: '请输入正确联系电话', icon: 'none' })
return
}
this.setData({ saving: true })
try {
await userApi.updateInfo({
nickname,
avatar: form.avatar || '',
contactPhone,
wechatId: String(form.wechatId || '').trim(),
signature: String(form.signature || '').trim()
})