优化:我的页面展示账号头像昵称

This commit is contained in:
2026-10-10 17:04:03 +08:00
parent d511070fc7
commit 9148bdb027
6 changed files with 79 additions and 16 deletions
+10 -8
View File
@@ -6,6 +6,7 @@ const planningApi = require('../../api/planning')
const employeesApi = require('../../api/employees')
const shopApi = require('../../api/shop')
const dateUtil = require('../../utils/date')
const { buildProfileCard } = require('../../utils/profile-card')
function resolveRoleText(type) {
const role = Number(type)
@@ -17,10 +18,9 @@ function resolveRoleText(type) {
Page({
data: {
shopName: BRAND_CONFIG.defaultShopName,
phone: '店长端',
roleText: '管理端',
userInfo: {},
profileCard: buildProfileCard({}, BRAND_CONFIG.defaultShopName),
editModalVisible: false,
profileSaving: false,
avatarUploading: false,
@@ -109,11 +109,11 @@ Page({
refreshFromSession() {
const app = getApp()
const userInfo = app.globalData.userInfo || {}
const fallbackShopName = app.globalData.shopName || BRAND_CONFIG.defaultShopName
this.setData({
shopName: app.globalData.shopName || BRAND_CONFIG.appName,
phone: userInfo.contactPhone || userInfo.phone || userInfo.account || '店长端',
roleText: resolveRoleText(userInfo.type),
userInfo
userInfo,
profileCard: buildProfileCard(userInfo, fallbackShopName)
})
},
@@ -152,16 +152,18 @@ Page({
wechatId: profile.wechatId || '',
signature: profile.signature || '',
type: profile.type || currentUserInfo.type,
shopId: profile.shopId || currentUserInfo.shopId
shopId: profile.shopId || currentUserInfo.shopId,
shopName: profile.shopName || currentUserInfo.shopName || session.shopName || app.globalData.shopName || ''
}
app.setSession({
...session,
shopName: nextUserInfo.shopName || session.shopName,
userInfo: nextUserInfo
})
this.setData({
userInfo: nextUserInfo,
phone: nextUserInfo.contactPhone || nextUserInfo.phone || nextUserInfo.account || '店长端',
roleText: resolveRoleText(nextUserInfo.type)
roleText: resolveRoleText(nextUserInfo.type),
profileCard: buildProfileCard(nextUserInfo, BRAND_CONFIG.defaultShopName)
})
},
+6 -3
View File
@@ -1,10 +1,13 @@
<view class="page">
<view class="card profile-card">
<view class="profile-main">
<view class="shop-logo">指</view>
<view class="account-avatar">
<image wx:if="{{profileCard.avatar}}" src="{{profileCard.avatar}}" mode="aspectFill"></image>
<text wx:else>{{profileCard.avatarText}}</text>
</view>
<view class="profile-copy">
<text class="shop-name">{{shopName}}</text>
<text class="phone">{{phone}}</text>
<text class="profile-name">{{profileCard.nickname}}</text>
<text class="profile-shop">{{profileCard.shopName}}</text>
</view>
</view>
<text class="role-badge">{{roleText}}</text>
+11 -5
View File
@@ -17,13 +17,14 @@
min-width: 0;
}
.shop-logo {
.account-avatar {
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
width: 96rpx;
height: 96rpx;
overflow: hidden;
border-radius: 24rpx;
background: #6f8f83;
color: #fff;
@@ -31,12 +32,17 @@
font-weight: 900;
}
.shop-name,
.phone {
.account-avatar image {
width: 100%;
height: 100%;
}
.profile-name,
.profile-shop {
display: block;
}
.shop-name {
.profile-name {
font-size: 34rpx;
font-weight: 800;
overflow: hidden;
@@ -44,7 +50,7 @@
white-space: nowrap;
}
.phone {
.profile-shop {
margin-top: 8rpx;
color: #91897f;
font-size: 24rpx;
+18
View File
@@ -0,0 +1,18 @@
function cleanText(value) {
return String(value || '').trim()
}
function buildProfileCard(userInfo, fallbackShopName) {
const user = userInfo || {}
const nickname = cleanText(user.nickname) || cleanText(user.account) || '未设置昵称'
const shopName = cleanText(user.shopName) || cleanText(fallbackShopName) || '未设置门店'
return {
avatar: cleanText(user.avatar),
avatarText: Array.from(nickname)[0] || '用',
nickname,
shopName
}
}
module.exports = { buildProfileCard }
@@ -0,0 +1,28 @@
const assert = require('assert')
const { buildProfileCard } = require('./profile-card')
assert.deepStrictEqual(buildProfileCard({
nickname: '小屿',
avatar: 'https://example.com/avatar.png',
shopName: '甲屿中心店'
}, '默认门店'), {
avatar: 'https://example.com/avatar.png',
avatarText: '小',
nickname: '小屿',
shopName: '甲屿中心店'
})
assert.deepStrictEqual(buildProfileCard({ account: 'manager01' }, '默认门店'), {
avatar: '',
avatarText: 'm',
nickname: 'manager01',
shopName: '默认门店'
})
assert.deepStrictEqual(buildProfileCard({}, ''), {
avatar: '',
avatarText: '未',
nickname: '未设置昵称',
shopName: '未设置门店'
})
+6
View File
@@ -1,5 +1,11 @@
# 项目变更记录
## 2026-10-10 Salon 小程序“我的”页面账号卡优化
- “我的”页面顶部卡片改为展示当前账号头像、昵称、所属门店和角色,不再展示固定品牌图标与“店长端”占位信息。
- 头像缺失时显示昵称首字;昵称缺失时使用登录账号或明确占位文案,门店名称优先取当前用户所属门店。
- 统一首次会话渲染、资料接口刷新和编辑保存后的展示规则,并补充账号卡兜底逻辑测试。
## 2026-10-10 Salon 小程序记住登录体验优化
- 新增独立启动鉴权页;已记住且账号状态正常的用户启动后自动登录并直接进入规划页,不再短暂显示登录页。