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

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">