优化:我的页面展示账号头像昵称
This commit is contained in:
@@ -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: '未设置门店'
|
||||
})
|
||||
Reference in New Issue
Block a user