修复店务默认头像显示异常

This commit is contained in:
2026-07-20 19:59:36 +08:00
parent 72e3470525
commit e82dea0cfd
3 changed files with 34 additions and 6 deletions
+24 -4
View File
@@ -4,6 +4,8 @@ const authApi = require('../../api/auth')
const auth = require('../../utils/auth')
const { chooseImageFilePath, uploadAvatar } = require('../../utils/upload')
const DEFAULT_BACKEND_AVATAR_URL = 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'
function resolveRoleText(type) {
const role = Number(type)
if (role === 2) return '店长'
@@ -12,6 +14,19 @@ function resolveRoleText(type) {
return '管理端'
}
function normalizeAvatarUrl(avatar) {
const value = String(avatar || '').trim()
if (!value) return ''
return value.split('?')[0]
}
function resolveDisplayAvatar(avatar) {
const value = String(avatar || '').trim()
if (!value) return ''
if (normalizeAvatarUrl(value) === DEFAULT_BACKEND_AVATAR_URL) return ''
return value
}
Page({
data: {
shopName: BRAND_CONFIG.defaultShopName,
@@ -47,11 +62,15 @@ Page({
refreshFromSession() {
const app = getApp()
const userInfo = app.globalData.userInfo || {}
const displayAvatar = resolveDisplayAvatar(userInfo.avatar)
this.setData({
shopName: app.globalData.shopName || BRAND_CONFIG.appName,
phone: userInfo.contactPhone || userInfo.phone || userInfo.account || '店长端',
roleText: resolveRoleText(userInfo.type),
userInfo
userInfo: {
...userInfo,
displayAvatar
}
})
},
@@ -130,7 +149,8 @@ Page({
wechatId: profile.wechatId || '',
signature: profile.signature || '',
type: profile.type || currentUserInfo.type,
shopId: profile.shopId || currentUserInfo.shopId
shopId: profile.shopId || currentUserInfo.shopId,
displayAvatar: resolveDisplayAvatar(profile.avatar || '')
}
app.setSession({
...session,
@@ -149,7 +169,7 @@ Page({
editModalVisible: true,
profileForm: {
nickname: userInfo.nickname || '',
avatar: userInfo.avatar || '',
avatar: userInfo.displayAvatar || '',
contactPhone: userInfo.contactPhone || '',
wechatId: userInfo.wechatId || '',
signature: userInfo.signature || ''
@@ -190,7 +210,7 @@ Page({
...profile,
avatar: profile.avatar || avatar
})
this.setData({ 'profileForm.avatar': profile.avatar || avatar })
this.setData({ 'profileForm.avatar': resolveDisplayAvatar(profile.avatar || avatar) })
} catch (error) {
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
} finally {
+2 -2
View File
@@ -1,8 +1,8 @@
<view class="page">
<view class="card profile-card">
<view class="profile-main">
<view wx:if="{{userInfo.avatar}}" class="shop-logo image-avatar">
<image src="{{userInfo.avatar}}" mode="aspectFill"></image>
<view wx:if="{{userInfo.displayAvatar}}" class="shop-logo image-avatar">
<image src="{{userInfo.displayAvatar}}" mode="aspectFill"></image>
</view>
<view wx:else class="shop-logo">指</view>
<view class="profile-copy">
+8
View File
@@ -128,3 +128,11 @@
- 处理方式:修正测试环境对象存储配置,至少保证一个 Provider 可用;阿里云 OSS 的 bucket 必须改为真实存在且全小写的 bucket,例如 `jayucloud`,并确认七牛的 bucket、zone、domain、access-key、secret-key 与实际空间一致。
- 以后避免:排查对象存储上传失败时先看 `ObjectStorageOrchestrationServiceImpl` 中每个 Provider 的 WARN 根因,不要只看最终包装异常;配置摘要只输出 provider、bucket、zone、domain、enabled 和密钥 present/empty,不输出明文密钥。
- 验证方式:配置刷新或重启 Core 后重试头像上传,日志不再出现 `Upload object to provider failed` 和 `No available object storage provider`,返回头像 URL 且小程序头像可刷新。
## 2026-07-20 后端默认头像不能当作用户真实头像渲染
- 问题:店务小程序个人页在默认头像状态下渲染后端返回的默认头像 URL,头像透明或非满铺区域会露出小程序占位容器的绿色底色。
- 原因:后端用固定默认头像 URL 表示“用户未上传头像”,但前端只按 `avatar` 是否有值判断是否走图片分支,导致占位语义被当成真实头像。
- 处理方式:前端展示层识别后端默认头像 URL,将其归一化为空展示头像;真实上传头像保持原 URL,保存资料时不把默认 URL 当作用户头像提交。
- 以后避免:新增默认图片、占位图或后端兜底 URL 时,要区分“存储值”和“展示值”;界面条件渲染应使用归一化后的展示字段。
- 验证方式:默认头像用户在个人页顶部和资料弹窗中都走本地占位;上传真实头像后页面显示真实图片;保存资料不会把后端默认头像 URL 写回为用户自定义头像。