feat(game): 支持玩家显示名称的多种数据源
- 在麻将游戏页面中添加本地缓存头像URL的优先级处理 - 为玩家座位信息添加自定义显示名称功能 - 支持从player_name或PlayerName字段获取玩家名称 - 实现当前用户显示名称的回退逻辑 - 更新API接口定义以支持可选的玩家名称字段
This commit is contained in:
@@ -10,6 +10,8 @@ export interface RoomItem {
|
||||
players?: Array<{
|
||||
index: number
|
||||
player_id: string
|
||||
player_name?: string
|
||||
PlayerName?: string
|
||||
ready: boolean
|
||||
}>
|
||||
status: string
|
||||
|
||||
@@ -257,10 +257,11 @@ const seatDecor = computed<Record<SeatKey, SeatPlayerCardModel>>(() => {
|
||||
const avatarUrl = seat.isSelf
|
||||
? (localCachedAvatarUrl.value || seat.player.avatarURL || '')
|
||||
: (seat.player.avatarURL || '')
|
||||
const selfDisplayName = seat.player.displayName || loggedInUserName.value || '你自己'
|
||||
|
||||
result[seat.key] = {
|
||||
avatarUrl,
|
||||
name: seat.isSelf ? '你自己' : displayName,
|
||||
name: seat.isSelf ? selfDisplayName : displayName,
|
||||
dealer: seat.player.seatIndex === dealerIndex,
|
||||
isTurn: seat.isTurn,
|
||||
missingSuitLabel: missingSuitLabel(seat.player.missingSuit),
|
||||
|
||||
@@ -131,6 +131,10 @@ function mapRoomPlayers(room: RoomItem): RoomPlayerState[] {
|
||||
.map((item, fallbackIndex) => ({
|
||||
index: Number.isFinite(item.index) ? item.index : fallbackIndex,
|
||||
playerId: item.player_id,
|
||||
displayName:
|
||||
(typeof item.player_name === 'string' && item.player_name) ||
|
||||
(typeof item.PlayerName === 'string' && item.PlayerName) ||
|
||||
(item.player_id === currentUserId.value ? displayName.value : undefined),
|
||||
ready: Boolean(item.ready),
|
||||
hand: [],
|
||||
melds: [],
|
||||
|
||||
Reference in New Issue
Block a user