feat(game): 支持玩家显示名称的多种数据源

- 在麻将游戏页面中添加本地缓存头像URL的优先级处理
- 为玩家座位信息添加自定义显示名称功能
- 支持从player_name或PlayerName字段获取玩家名称
- 实现当前用户显示名称的回退逻辑
- 更新API接口定义以支持可选的玩家名称字段
This commit is contained in:
2026-03-25 21:15:40 +08:00
parent 6168117eb2
commit ae5d8d48c4
3 changed files with 8 additions and 1 deletions

View File

@@ -10,6 +10,8 @@ export interface RoomItem {
players?: Array<{ players?: Array<{
index: number index: number
player_id: string player_id: string
player_name?: string
PlayerName?: string
ready: boolean ready: boolean
}> }>
status: string status: string

View File

@@ -257,10 +257,11 @@ const seatDecor = computed<Record<SeatKey, SeatPlayerCardModel>>(() => {
const avatarUrl = seat.isSelf const avatarUrl = seat.isSelf
? (localCachedAvatarUrl.value || seat.player.avatarURL || '') ? (localCachedAvatarUrl.value || seat.player.avatarURL || '')
: (seat.player.avatarURL || '') : (seat.player.avatarURL || '')
const selfDisplayName = seat.player.displayName || loggedInUserName.value || '你自己'
result[seat.key] = { result[seat.key] = {
avatarUrl, avatarUrl,
name: seat.isSelf ? '你自己' : displayName, name: seat.isSelf ? selfDisplayName : displayName,
dealer: seat.player.seatIndex === dealerIndex, dealer: seat.player.seatIndex === dealerIndex,
isTurn: seat.isTurn, isTurn: seat.isTurn,
missingSuitLabel: missingSuitLabel(seat.player.missingSuit), missingSuitLabel: missingSuitLabel(seat.player.missingSuit),

View File

@@ -131,6 +131,10 @@ function mapRoomPlayers(room: RoomItem): RoomPlayerState[] {
.map((item, fallbackIndex) => ({ .map((item, fallbackIndex) => ({
index: Number.isFinite(item.index) ? item.index : fallbackIndex, index: Number.isFinite(item.index) ? item.index : fallbackIndex,
playerId: item.player_id, 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), ready: Boolean(item.ready),
hand: [], hand: [],
melds: [], melds: [],