fix(listings): 优化账号详情页 UI 与皮肤展台并修复全局居中样式
This commit is contained in:
@@ -22,6 +22,28 @@ export interface ListingDisplaySkinGroup {
|
||||
options: string[]
|
||||
}
|
||||
|
||||
export type DetailSkinType =
|
||||
| 'operatorRed'
|
||||
| 'melee'
|
||||
| 'operatorGold'
|
||||
| 'weaponGold'
|
||||
| 'weapon'
|
||||
| 'operator'
|
||||
| 'other'
|
||||
|
||||
export interface DetailSkinGroup extends ListingDisplaySkinGroup {
|
||||
type: DetailSkinType
|
||||
badge: string
|
||||
tierLabel: string
|
||||
isWide?: boolean
|
||||
}
|
||||
|
||||
export interface ListingHighlightSkinItem {
|
||||
name: string
|
||||
type: DetailSkinType
|
||||
badge: string
|
||||
}
|
||||
|
||||
export function getCoinWan(item: PublicListingItem) {
|
||||
return Math.round(Number(item.haf_coin_amount || 0) / 10000)
|
||||
}
|
||||
@@ -271,10 +293,128 @@ export function getListingSkinGroups(item: PublicListingItem): ListingDisplaySki
|
||||
.filter(group => group.options.length)
|
||||
}
|
||||
|
||||
const DETAIL_SKIN_META: Record<
|
||||
string,
|
||||
{ title: string; type: DetailSkinType; badge: string; tierLabel: string; order: number }
|
||||
> = {
|
||||
melee: { title: '近战皮肤', type: 'melee', badge: '近战', tierLabel: '典藏近战', order: 1 },
|
||||
operatorRed: {
|
||||
title: '干员红皮',
|
||||
type: 'operatorRed',
|
||||
badge: '红皮',
|
||||
tierLabel: '臻红限定',
|
||||
order: 2,
|
||||
},
|
||||
operatorGold: {
|
||||
title: '干员金皮',
|
||||
type: 'operatorGold',
|
||||
badge: '金皮',
|
||||
tierLabel: '耀金品质',
|
||||
order: 3,
|
||||
},
|
||||
weaponGold: {
|
||||
title: '武器金皮',
|
||||
type: 'weaponGold',
|
||||
badge: '武金',
|
||||
tierLabel: '鎏金涂装',
|
||||
order: 4,
|
||||
},
|
||||
weapon: { title: '武器皮肤', type: 'weapon', badge: '武器', tierLabel: '精工涂装', order: 5 },
|
||||
operator: {
|
||||
title: '干员皮肤',
|
||||
type: 'operator',
|
||||
badge: '干员',
|
||||
tierLabel: '战术外观',
|
||||
order: 6,
|
||||
},
|
||||
other: { title: '其他皮肤', type: 'other', badge: '精选', tierLabel: '精选外观', order: 7 },
|
||||
imported: { title: '其他皮肤', type: 'other', badge: '精选', tierLabel: '精选外观', order: 8 },
|
||||
}
|
||||
|
||||
export function getDetailSkinGroups(item: PublicListingItem): DetailSkinGroup[] {
|
||||
const skinGroups = item.asset_summary?.skin_groups
|
||||
if (typeof skinGroups !== 'object' || skinGroups === null) return []
|
||||
|
||||
const groups: DetailSkinGroup[] = Object.entries(skinGroups as Record<string, unknown>)
|
||||
.map(([key, value], index) => {
|
||||
const meta = DETAIL_SKIN_META[key] || {
|
||||
title: key,
|
||||
type: 'other' as DetailSkinType,
|
||||
badge: '精选',
|
||||
tierLabel: '精选外观',
|
||||
order: 99 + index,
|
||||
}
|
||||
const seen = new Set<string>()
|
||||
const options = Array.isArray(value)
|
||||
? value
|
||||
.filter((skin): skin is string => typeof skin === 'string')
|
||||
.map(skin => skin.trim())
|
||||
.filter(skin => {
|
||||
if (!skin || seen.has(skin)) return false
|
||||
seen.add(skin)
|
||||
return true
|
||||
})
|
||||
: []
|
||||
return {
|
||||
key,
|
||||
type: meta.type,
|
||||
title: meta.title,
|
||||
badge: meta.badge,
|
||||
tierLabel: meta.tierLabel,
|
||||
order: meta.order,
|
||||
options,
|
||||
isWide: options.length >= 4,
|
||||
}
|
||||
})
|
||||
.filter(group => group.options.length > 0)
|
||||
.sort((a, b) => a.order - b.order)
|
||||
.map(({ order: _order, ...group }) => group)
|
||||
|
||||
// 2 列 Bento 排版消缺:连续非通栏卡片若为奇数个,将最后一个设为通栏,避免右侧留白
|
||||
let halfRun = 0
|
||||
for (let i = 0; i < groups.length; i += 1) {
|
||||
const group = groups[i]
|
||||
if (!group) continue
|
||||
if (group.isWide) {
|
||||
if (halfRun % 2 === 1 && i > 0) {
|
||||
const prev = groups[i - 1]
|
||||
if (prev) prev.isWide = true
|
||||
}
|
||||
halfRun = 0
|
||||
} else {
|
||||
halfRun += 1
|
||||
}
|
||||
}
|
||||
if (halfRun % 2 === 1 && groups.length > 0) {
|
||||
const last = groups[groups.length - 1]
|
||||
if (last) last.isWide = true
|
||||
}
|
||||
|
||||
return groups
|
||||
}
|
||||
|
||||
export function getSkinNames(item: PublicListingItem) {
|
||||
return getListingSkinGroups(item).flatMap(group => group.options)
|
||||
}
|
||||
|
||||
export function getHighlightSkins(item: PublicListingItem, limit = 6): ListingHighlightSkinItem[] {
|
||||
const groups = getDetailSkinGroups(item)
|
||||
const result: ListingHighlightSkinItem[] = []
|
||||
for (const group of groups) {
|
||||
for (const name of group.options) {
|
||||
result.push({
|
||||
name,
|
||||
type: group.type,
|
||||
badge: group.badge,
|
||||
})
|
||||
if (result.length >= limit) {
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export function assetRegions(item: PublicListingItem) {
|
||||
const regions = item.asset_summary?.common_regions
|
||||
return Array.isArray(regions)
|
||||
|
||||
Reference in New Issue
Block a user