修复Salon对象存储头像展示

This commit is contained in:
2026-11-01 00:41:51 +08:00
parent e52e04685d
commit f30abbc26c
29 changed files with 229 additions and 28 deletions
@@ -2065,6 +2065,10 @@ Page({
this.persistDraft(true)
},
onSelectedProductImageError() {
this.setData({ 'selectedProduct.coverImage': '' })
},
back() {
wx.navigateBack()
}
@@ -27,7 +27,7 @@
<text class="chevron">›</text>
</button>
<view wx:else class="selected-style-card" bindtap="openManualProduct">
<image wx:if="{{selectedProduct.coverImage}}" class="selected-style-image" src="{{selectedProduct.coverImage}}" mode="aspectFill"></image>
<image wx:if="{{selectedProduct.coverImage}}" class="selected-style-image" src="{{selectedProduct.coverImage}}" mode="aspectFill" binderror="onSelectedProductImageError"></image>
<view wx:else class="field-icon">✦</view>
<view class="selected-style-copy"><text class="selected-style-title">{{selectedProduct.title}}</text><text class="selected-style-meta">参考价 {{selectedProductPriceText || '待定'}} · 本次 {{form.amount || '待填'}} 元 · {{form.durationMinutes || '60'}} 分钟</text></view>
<button class="switch-manual-action" catchtap="openManualProduct">调整</button>
@@ -121,6 +121,7 @@ Page({
async chooseManualProductImage() { if (this.data.manualImageUploading) return; const remaining = 9 - (this.data.form.manualProductImages || []).length; if (remaining <= 0) { wx.showToast({ title: '最多添加9张图片', icon: 'none' }); return } try { this.setData({ manualImageUploading: true }); const paths = await chooseImages(remaining); for (const filePath of paths) { const result = await uploadObjectFile(filePath); const fileId = result.id || result.fileId; if (!fileId) throw new Error('图片上传成功但未返回文件ID'); this.setData(imagePatch((this.data.form.manualProductImages || []).concat({ fileId: String(fileId), fileUrl: result.fileUrl || result.primaryUrl || '', previewUrl: filePath }))) } } catch (error) { wx.showToast({ title: error.message || '图片上传失败', icon: 'none' }) } finally { this.setData({ manualImageUploading: false }) } },
removeManualProductImage(event) { const index = Number(event.currentTarget.dataset.index); this.setData(imagePatch((this.data.form.manualProductImages || []).filter((item, itemIndex) => itemIndex !== index))) },
onManualProductImageError(event) { const index = Number(event.currentTarget.dataset.index); const images = this.data.form.manualProductImages || []; if (!images[index] || !images[index].fileUrl) return; const fallback = images.slice(); fallback[index] = { ...fallback[index], previewUrl: fallback[index].fileUrl }; this.setData(imagePatch(fallback)) },
onSelectedProductImageError() { this.setData({ 'selectedProduct.coverImage': '' }) },
onInput(event) { const field = event.currentTarget.dataset.field; const value = event.detail.value; this.setData({ [`form.${field}`]: value, ...(field === 'amount' ? { 'manualProductDraft.price': value } : {}) }) },
onDateChange(event) { this.setData({ 'form.serviceDate': event.detail.value }) },
onTimeChange(event) { this.setData({ 'form.serviceTime': event.detail.value }) },
@@ -25,7 +25,7 @@
<text class="chevron">›</text>
</button>
<view wx:else class="selected-style-card" bindtap="openManualProduct">
<image wx:if="{{selectedProduct.coverImage}}" class="selected-style-image" src="{{selectedProduct.coverImage}}" mode="aspectFill"></image>
<image wx:if="{{selectedProduct.coverImage}}" class="selected-style-image" src="{{selectedProduct.coverImage}}" mode="aspectFill" binderror="onSelectedProductImageError"></image>
<view wx:else class="field-icon">✦</view>
<view class="selected-style-copy"><text class="selected-style-title">{{selectedProduct.title}}</text><text class="selected-style-meta">参考价 {{selectedProductPriceText || '待定'}} · 本次 {{form.amount || '待填'}} 元 · {{form.durationMinutes || '60'}} 分钟</text></view>
<button class="switch-manual-action" catchtap="openManualProduct">调整</button>
@@ -56,10 +56,11 @@ Page({
if (!filePath) return
this.setData({ avatarUploading: true })
const uploadResult = await uploadObjectFile(filePath)
const avatarUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath
// 私有对象存储地址可能无法被小程序直接访问,上传完成后先用本地临时文件即时预览。
const storedAvatar = uploadResult.fileUrl || uploadResult.primaryUrl || ''
this.setData({
'form.avatar': avatarUrl,
'form.avatarUrl': avatarUrl
'form.avatar': storedAvatar,
'form.avatarUrl': filePath
})
} catch (error) {
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
@@ -72,6 +73,10 @@ Page({
this.setData({ 'form.avatar': '', 'form.avatarUrl': '' })
},
onAvatarError() {
this.setData({ 'form.avatarUrl': '' })
},
stopTouchMove() {
},
@@ -5,7 +5,7 @@
</view>
<view class="card avatar-card" bindtap="chooseAvatar">
<image wx:if="{{form.avatarUrl}}" class="avatar-preview" src="{{form.avatarUrl}}" mode="aspectFill"></image>
<image wx:if="{{form.avatarUrl}}" class="avatar-preview" src="{{form.avatarUrl}}" mode="aspectFill" binderror="onAvatarError"></image>
<image wx:else class="avatar-preview" src="/assets/images/default-user-avatar.png" mode="aspectFit"></image>
<view class="avatar-copy">
<text class="avatar-title">美甲师头像</text>
@@ -44,6 +44,10 @@ Page({
wx.navigateTo({ url: `${event.currentTarget.dataset.url}?id=${this.data.id}` })
},
onAvatarError() {
this.setData({ 'employee.avatar': '' })
},
back() {
wx.navigateBack()
}
@@ -5,7 +5,8 @@
</view>
<view wx:else class="card employee-head">
<view class="avatar" style="background: {{employee.color}};">{{employee.shortName}}</view>
<view wx:if="{{employee.avatar}}" class="avatar image-avatar" style="background: {{employee.color}};"><image src="{{employee.avatar}}" mode="aspectFill" binderror="onAvatarError"></image></view>
<view wx:else class="avatar" style="background: {{employee.color}};">{{employee.shortName}}</view>
<view>
<text class="employee-name">{{employee.name}}</text>
<text class="tag" style="background: {{employee.color}}; color: #fff;">美甲师色</text>
@@ -26,6 +26,12 @@
color: #fff;
font-size: 34rpx;
font-weight: 900;
overflow: hidden;
}
.image-avatar image {
width: 100%;
height: 100%;
}
.employee-name {
+12
View File
@@ -291,6 +291,18 @@ Page({
}
},
onEmployeeAvatarError(event) {
const index = Number(event.currentTarget.dataset.index)
if (!Number.isInteger(index) || !this.data.employees[index]) return
this.setData({ [`employees[${index}].avatar`]: '' })
},
onReviewAvatarError(event) {
const index = Number(event.currentTarget.dataset.index)
if (!Number.isInteger(index) || !this.data.reviewApplications[index]) return
this.setData({ [`reviewApplications[${index}].applicantAvatar`]: '' })
},
openDetail(event) {
wx.navigateTo({ url: `/pages/employee-detail/index?id=${event.currentTarget.dataset.id}` })
},
+2 -2
View File
@@ -20,7 +20,7 @@
<view wx:elif="{{reviewApplications.length === 0}}" class="review-state">暂无待审核美甲师申请</view>
<view wx:else class="review-list">
<view wx:for="{{reviewApplications}}" wx:key="id" class="review-item">
<image class="review-avatar" src="{{item.applicantAvatar || '/assets/images/default-user-avatar.png'}}" mode="aspectFill"></image>
<image class="review-avatar" src="{{item.applicantAvatar || '/assets/images/default-user-avatar.png'}}" mode="aspectFill" data-index="{{index}}" binderror="onReviewAvatarError"></image>
<view class="review-info">
<text class="review-name">{{item.applicantDisplayName}}</text>
<text wx:if="{{item.targetArtistUserId}}" class="review-meta">已预关联美甲师</text>
@@ -45,7 +45,7 @@
<view wx:for="{{employees}}" wx:key="id" class="card employee-card" data-id="{{item.id}}" bindtap="openDetail">
<view class="employee-left">
<view wx:if="{{item.avatar}}" class="avatar image-avatar">
<image src="{{item.avatar}}" mode="aspectFill"></image>
<image src="{{item.avatar}}" mode="aspectFill" data-index="{{index}}" binderror="onEmployeeAvatarError"></image>
</view>
<view wx:else class="avatar" style="background: {{item.color}};">{{item.shortName}}</view>
<view>
+4
View File
@@ -331,6 +331,10 @@ Page({
this.loadCalendar()
},
onProfileAvatarError() {
this.setData({ 'profileForm.avatar': '' })
},
selectWeekDate(event) {
const appointmentDate = dateUtil.formatDate(event.currentTarget.dataset.date)
const target = toLocalDate(appointmentDate)
+1 -1
View File
@@ -44,7 +44,7 @@
<view class="profile-prompt">
<text class="profile-prompt-title">完善你的工作名片</text><text class="profile-prompt-desc">头像和昵称会用于门店协作展示,可暂时跳过。</text>
<button class="wechat-avatar" open-type="chooseAvatar" bindchooseavatar="chooseWechatAvatar" disabled="{{profileSaving}}">
<image class="wechat-avatar-image {{profileForm.avatar ? 'is-real' : 'is-default'}}" src="{{profileForm.avatar || '/assets/images/default-user-avatar.png'}}" mode="aspectFill"></image>
<image class="wechat-avatar-image {{profileForm.avatar ? 'is-real' : 'is-default'}}" src="{{profileForm.avatar || '/assets/images/default-user-avatar.png'}}" mode="aspectFill" binderror="onProfileAvatarError"></image>
<view class="wechat-avatar-hint">{{profileSaving ? '上传中' : '点击更换'}}</view>
</button>
<input class="wechat-nickname" type="nickname" value="{{profileForm.nickname}}" bindinput="onNicknameInput" placeholder="填写微信昵称" />
@@ -139,6 +139,10 @@ Page({
}
},
onAvatarImageError() {
this.setData({ 'form.avatar': '' })
},
async chooseWechatAvatar(event) {
if (this.data.loading || this.data.avatarUploading || this.data.saving) return
try {
@@ -3,7 +3,7 @@
<view class="card avatar-card">
<view class="avatar-preview" bindtap="chooseAvatar">
<image wx:if="{{form.avatar}}" src="{{form.avatar}}" mode="aspectFill"></image>
<image wx:if="{{form.avatar}}" src="{{form.avatar}}" mode="aspectFill" binderror="onAvatarImageError"></image>
<text wx:else class="avatar-letter">{{avatarText}}</text>
<view class="avatar-change-tip">{{avatarUploading ? '上传中' : '点击更换'}}</view>
</view>
+4
View File
@@ -90,6 +90,10 @@ Page({
wx.navigateTo({ url: event.currentTarget.dataset.url })
},
onProfileAvatarError() {
this.setData({ 'profileCard.avatar': '' })
},
async loadProfile() {
try {
const profile = await profileCache.getProfile()
+1 -1
View File
@@ -2,7 +2,7 @@
<view class="card profile-card">
<view class="profile-main">
<view class="account-avatar">
<image wx:if="{{profileCard.avatar}}" src="{{profileCard.avatar}}" mode="aspectFill"></image>
<image wx:if="{{profileCard.avatar}}" src="{{profileCard.avatar}}" mode="aspectFill" binderror="onProfileAvatarError"></image>
<text wx:else>{{profileCard.avatarText}}</text>
</view>
<view class="profile-copy">