diff --git a/JY-Salon-WeChat/pages/profile/index.js b/JY-Salon-WeChat/pages/profile/index.js index 2b46207b..eee47beb 100644 --- a/JY-Salon-WeChat/pages/profile/index.js +++ b/JY-Salon-WeChat/pages/profile/index.js @@ -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 { diff --git a/JY-Salon-WeChat/pages/profile/index.wxml b/JY-Salon-WeChat/pages/profile/index.wxml index 64644f70..eb811577 100644 --- a/JY-Salon-WeChat/pages/profile/index.wxml +++ b/JY-Salon-WeChat/pages/profile/index.wxml @@ -1,8 +1,8 @@ -