优化:个人信息改为独立页面
This commit is contained in:
@@ -1,18 +1,25 @@
|
||||
const DEFAULT_AVATAR_URL = 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'
|
||||
|
||||
function cleanText(value) {
|
||||
return String(value || '').trim()
|
||||
}
|
||||
|
||||
function normalizeAvatar(value) {
|
||||
const avatar = cleanText(value)
|
||||
return avatar === DEFAULT_AVATAR_URL ? '' : avatar
|
||||
}
|
||||
|
||||
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),
|
||||
avatar: normalizeAvatar(user.avatar),
|
||||
avatarText: Array.from(nickname)[0] || '用',
|
||||
nickname,
|
||||
shopName
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { buildProfileCard }
|
||||
module.exports = { DEFAULT_AVATAR_URL, buildProfileCard, normalizeAvatar }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const assert = require('assert')
|
||||
|
||||
const { buildProfileCard } = require('./profile-card')
|
||||
const { DEFAULT_AVATAR_URL, buildProfileCard, normalizeAvatar } = require('./profile-card')
|
||||
|
||||
assert.deepStrictEqual(buildProfileCard({
|
||||
nickname: '小屿',
|
||||
@@ -26,3 +26,6 @@ assert.deepStrictEqual(buildProfileCard({}, ''), {
|
||||
nickname: '未设置昵称',
|
||||
shopName: '未设置门店'
|
||||
})
|
||||
|
||||
assert.strictEqual(normalizeAvatar(DEFAULT_AVATAR_URL), '')
|
||||
assert.strictEqual(buildProfileCard({ nickname: '小屿', avatar: DEFAULT_AVATAR_URL }, '中心店').avatar, '')
|
||||
|
||||
Reference in New Issue
Block a user