修复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
@@ -33,6 +33,12 @@ Component({
if (item) this.triggerEvent('select', { item })
},
onAvatarError(event) {
const index = Number(event.currentTarget.dataset.index)
if (!Number.isInteger(index) || !this.data.items[index]) return
this.setData({ [`items[${index}].avatar`]: '' })
},
retry() {
this.triggerEvent('retry')
},
@@ -30,7 +30,7 @@
<view wx:elif="{{items.length === 0}}" class="selector-state">{{emptyText}}</view>
<view wx:else class="selector-list {{viewMode === 'card' ? 'card-view' : ''}}">
<view wx:for="{{items}}" wx:key="id" class="selector-item {{selectedId == item.id ? 'selected' : ''}} {{viewMode === 'card' ? 'card-view' : ''}}" data-index="{{index}}" bindtap="selectItem">
<image wx:if="{{item.avatar}}" class="selector-avatar" src="{{item.avatar}}" mode="aspectFill"></image>
<image wx:if="{{item.avatar}}" class="selector-avatar" src="{{item.avatar}}" mode="aspectFill" data-index="{{index}}" binderror="onAvatarError"></image>
<view class="selector-copy {{item.avatar ? '' : 'without-avatar'}}">
<view class="selector-title-row">
<text class="selector-item-title">{{item.title}}</text>
@@ -25,6 +25,14 @@ Component({
const item = this.data.items[Number(event.currentTarget.dataset.index)]
if (item) this.triggerEvent('select', { item })
},
onCoverImageError(event) {
const index = Number(event.currentTarget.dataset.index)
if (!Number.isInteger(index) || !this.data.items[index]) return
this.setData({ [`items[${index}].coverImage`]: '' })
},
onManualImageError() {
this.setData({ manualImageUrl: '' })
},
openManual() { this.triggerEvent('openmanual') },
backToList() { this.triggerEvent('backtolist') },
onManualInput(event) {
@@ -12,7 +12,7 @@
<view wx:elif="{{items.length === 0}}" class="product-selector-state">{{emptyText}}</view>
<view wx:else class="product-selector-list">
<view wx:for="{{items}}" wx:key="id" class="product-selector-item {{selectedId == item.id ? 'selected' : ''}}" data-index="{{index}}" bindtap="selectItem">
<image wx:if="{{item.coverImage}}" class="product-selector-cover" src="{{item.coverImage}}" mode="aspectFill"></image><view wx:else class="product-selector-cover placeholder">图</view>
<image wx:if="{{item.coverImage}}" class="product-selector-cover" src="{{item.coverImage}}" mode="aspectFill" data-index="{{index}}" binderror="onCoverImageError"></image><view wx:else class="product-selector-cover placeholder">图</view>
<view class="product-selector-copy"><view class="product-selector-name-row"><text class="product-selector-name">{{item.title}}</text><text class="product-selector-price">{{item.priceText || (item.price == null ? '价格待定' : '¥' + item.price)}}</text></view><text class="product-selector-meta">{{item.durationText || '时长待定'}} · {{item.artistText || '全部美甲师'}}</text><view class="product-selector-tags"><text wx:for="{{item.tagList}}" wx:for-item="tag" wx:key="*this">{{tag}}</text></view></view><text class="product-selector-check">{{selectedId == item.id ? '✓' : '›'}}</text>
</view>
</view>
@@ -22,7 +22,7 @@
<block wx:else>
<scroll-view class="product-selector-scroll manual" scroll-y enhanced show-scrollbar="{{false}}">
<view class="manual-product-card"><view class="manual-product-grid"><input value="{{manualForm.title}}" data-field="title" bindinput="onManualInput" placeholder="作品名称" /><input value="{{manualForm.price}}" data-field="price" bindinput="onManualInput" type="digit" placeholder="价格" /></view><view wx:if="{{showManualExtra}}" class="manual-product-more" bindtap="toggleMore">{{manualMoreExpanded ? '⌃ 收起更多信息' : '⌄ 补充更多信息'}}</view></view>
<view wx:if="{{showManualExtra && manualMoreExpanded}}" class="manual-product-extra"><textarea value="{{manualForm.description}}" data-field="description" bindinput="onManualInput" placeholder="作品描述(选填)"></textarea><input value="{{manualForm.tags}}" data-field="tags" bindinput="onManualInput" placeholder="标签,多个用逗号分隔(选填)" /><input value="{{manualForm.targetAudience}}" data-field="targetAudience" bindinput="onManualInput" placeholder="适合人群(选填)" /><input value="{{manualForm.precautions}}" data-field="precautions" bindinput="onManualInput" placeholder="注意事项(选填)" /><view class="manual-product-image-row"><image wx:if="{{manualImageUrl}}" src="{{manualImageUrl}}" class="manual-product-image" mode="aspectFill"></image><view wx:else class="manual-product-image placeholder">图</view><button bindtap="chooseImage" loading="{{manualImageUploading}}">上传图片</button><button wx:if="{{manualImageUrl}}" bindtap="removeImage">移除</button></view></view>
<view wx:if="{{showManualExtra && manualMoreExpanded}}" class="manual-product-extra"><textarea value="{{manualForm.description}}" data-field="description" bindinput="onManualInput" placeholder="作品描述(选填)"></textarea><input value="{{manualForm.tags}}" data-field="tags" bindinput="onManualInput" placeholder="标签,多个用逗号分隔(选填)" /><input value="{{manualForm.targetAudience}}" data-field="targetAudience" bindinput="onManualInput" placeholder="适合人群(选填)" /><input value="{{manualForm.precautions}}" data-field="precautions" bindinput="onManualInput" placeholder="注意事项(选填)" /><view class="manual-product-image-row"><image wx:if="{{manualImageUrl}}" src="{{manualImageUrl}}" class="manual-product-image" mode="aspectFill" binderror="onManualImageError"></image><view wx:else class="manual-product-image placeholder">图</view><button bindtap="chooseImage" loading="{{manualImageUploading}}">上传图片</button><button wx:if="{{manualImageUrl}}" bindtap="removeImage">移除</button></view></view>
</scroll-view>
<view class="product-selector-footer manual-footer"><button class="product-selector-confirm" bindtap="confirmManual">使用此作品</button><button class="product-selector-back" bindtap="backToList">‹ 返回作品列表</button></view>
</block>
@@ -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">