From 76efe5a2070500d5c25322490ef931c8154d5445 Mon Sep 17 00:00:00 2001 From: chenlimao Date: Sat, 9 May 2026 17:41:41 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E7=BB=93=E7=AE=97=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=BB=8F=E9=AA=8C=E8=BF=9B=E5=BA=A6=E6=9D=A1=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E5=AF=B9=E6=8E=A5=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/friend-battle-result.vue | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/pages/friend-battle-result.vue b/src/pages/friend-battle-result.vue index bae1fe2..f832bb3 100644 --- a/src/pages/friend-battle-result.vue +++ b/src/pages/friend-battle-result.vue @@ -30,15 +30,15 @@ const overlayTimer = ref(null); /** 控制经验条是否执行进场动画(弹窗关闭后才置 true,避免动画被遮挡) */ const showExpAnim = ref(false); -// ---- Mock 数据(等待后端补充经验接口后替换)---- -/** 本局获得的经验值(MOCK:后端暂未返回,待接口就绪后替换) */ -const expGained = ref(24); -/** 当前经验进度值(MOCK) */ -const expCurrent = ref(66); -/** 升级所需总经验(MOCK) */ +// ---- 经验进度条数据(onLoad 中从 teams.players 解析填充)---- +/** 本局获得的经验值 */ +const expGained = ref(0); +/** 对战结束后当前经验进度值 */ +const expCurrent = ref(0); +/** 升级到下一级所需的总经验(兜底 100,防止分母为 0) */ const expTotal = ref(100); -/** 用户当前等级(MOCK) */ -const userLvl = ref(90); +/** 用户当前等级 */ +const userLvl = ref(0); // ---- 计算属性 ---- @@ -170,6 +170,20 @@ onLoad(async (options) => { const result = await getBattleAPI(options.battleId); data.value = result; + // 从 teams 各队伍的 players 中找到当前用户,解析经验进度条所需字段 + // 后端字段:exp(本局经验)/ currentExp(当前经验)/ upgradeExp(升级所需经验)/ level(当前等级) + const myIdStr = String(user.value.id); + for (const team of Object.values(result.teams || {})) { + const p = (team.players || []).find((pl) => String(pl.id) === myIdStr); + if (p) { + expGained.value = p.exp ?? 0; + expCurrent.value = p.currentExp ?? 0; + expTotal.value = p.upgradeExp ?? 100; + userLvl.value = p.level ?? 0; + break; + } + } + // 判断当前用户是否在胜利队伍中 // 优先使用接口返回的 winTeam 字段;若缺失则以队伍得分高低作为兜底判断 const myId = String(user.value.id);