优化:个人资料与手机号设置入口
This commit is contained in:
@@ -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()
|
||||
})
|
||||
|
||||
@@ -13,10 +13,26 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card wechat-profile-card">
|
||||
<view class="wechat-profile-entry" bindtap="toggleWechatProfile">
|
||||
<view class="wechat-profile-mark">微</view>
|
||||
<text>使用微信资料</text>
|
||||
<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">
|
||||
<image wx:if="{{form.avatar}}" src="{{form.avatar}}" mode="aspectFill"></image>
|
||||
<text wx:else>{{avatarText}}</text>
|
||||
<view class="wechat-avatar-tip">选择微信头像</view>
|
||||
</button>
|
||||
<input class="wechat-nickname-input" type="nickname" value="{{form.nickname}}" bindinput="onWechatNicknameInput" placeholder="填写微信昵称" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section-title">基本资料</view>
|
||||
<view class="card form-card">
|
||||
<view class="field"><text class="field-label required">昵称</text><input value="{{form.nickname}}" data-field="nickname" bindinput="onInput" maxlength="30" placeholder="请输入昵称" /></view>
|
||||
<view class="field"><text class="field-label">联系电话</text><input value="{{form.contactPhone}}" data-field="contactPhone" bindinput="onInput" type="number" maxlength="11" placeholder="请输入联系电话" /></view>
|
||||
<view class="field phone-field" bindtap="goAccountSettings"><text class="field-label">手机号</text><view class="phone-value"><text>{{phoneDisplay}}</text><text class="phone-arrow">›</text></view></view>
|
||||
<view class="field"><text class="field-label">微信号</text><input value="{{form.wechatId}}" data-field="wechatId" bindinput="onInput" maxlength="50" placeholder="请输入微信号" /></view>
|
||||
<view class="field signature-field"><text class="field-label">个性签名</text><textarea value="{{form.signature}}" data-field="signature" bindinput="onInput" maxlength="200" placeholder="请输入个人签名" /></view>
|
||||
</view>
|
||||
|
||||
@@ -8,10 +8,22 @@
|
||||
.avatar-copy { display:flex; min-width:0; flex:1; flex-direction:column; margin-left:20rpx; }
|
||||
.avatar-title { color:#30483c; font-size:30rpx; font-weight:800; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
||||
.avatar-signature { margin-top:10rpx; color:#8a9a91; font-size:22rpx; line-height:1.5; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
||||
.wechat-profile-card { margin-top:20rpx; overflow:hidden; }
|
||||
.wechat-profile-entry { display:flex; min-height:92rpx; align-items:center; padding:0 24rpx; color:#30483c; font-size:26rpx; font-weight:800; }
|
||||
.wechat-profile-mark { display:flex; width:48rpx; height:48rpx; align-items:center; justify-content:center; margin-right:16rpx; border-radius:14rpx; background:#dcebe1; color:#35634d; font-size:21rpx; }
|
||||
.expand-arrow { margin-left:auto; color:#8a9a91; font-size:38rpx; transition:transform 180ms ease; }
|
||||
.expand-arrow.expanded { transform:rotate(90deg); }
|
||||
.wechat-profile-panel { display:flex; align-items:center; gap:20rpx; padding:22rpx 24rpx 26rpx; border-top:1rpx solid #eee8df; background:#faf8f3; }
|
||||
.wechat-avatar-picker { position:relative; display:flex; width:112rpx; min-width:112rpx; max-width:112rpx; height:112rpx; min-height:112rpx; align-items:center; justify-content:center; overflow:hidden; border-radius:28rpx; background:#6f8f83; color:#fff; font-size:36rpx; font-weight:900; }
|
||||
.wechat-avatar-picker image { width:100%; height:100%; }
|
||||
.wechat-avatar-tip { position:absolute; right:0; bottom:0; left:0; height:34rpx; background:rgba(35,42,39,.62); color:#fff; font-size:15rpx; font-weight:500; line-height:34rpx; text-align:center; }
|
||||
.wechat-nickname-input { height:78rpx; min-width:0; flex:1; padding:0 20rpx; border:1rpx solid #dde8e0; border-radius:12rpx; background:#fff; color:#27231f; font-size:27rpx; }
|
||||
.section-title { margin:30rpx 4rpx 14rpx; }
|
||||
.form-card { padding:0 24rpx; }
|
||||
.field-label { width:170rpx; }
|
||||
.field input,.field textarea { text-align:right; }
|
||||
.phone-value { display:flex; min-width:0; flex:1; align-items:center; justify-content:flex-end; color:#7f776f; font-size:27rpx; }
|
||||
.phone-arrow { margin-left:14rpx; color:#aaa198; font-size:38rpx; }
|
||||
.signature-field { align-items:flex-start; }
|
||||
.signature-field .field-label { padding-top:34rpx; }
|
||||
.signature-field textarea { text-align:left; }
|
||||
|
||||
Reference in New Issue
Block a user