比赛结果数据源修改

This commit is contained in:
kron
2025-07-15 18:14:59 +08:00
parent 16f8048b55
commit 32baa7279d
6 changed files with 68 additions and 47 deletions

View File

@@ -10,47 +10,61 @@ const store = useStore();
const { user } = storeToRefs(store);
const { updateUser, getLvlName } = store;
const battleId = ref("");
const ifWin = ref(false);
const data = ref({});
const totalPoints = ref(0);
onLoad(async (options) => {
battleId.value = options.battleId;
const result = await getGameAPI(
// options.battleId || "BATTLE-1750867490990424058-718"
options.battleId || "BATTLE-1752563964391008873-624"
);
data.value = result;
if (result.mode === 1 && result.redPlayers[user.value.id]) {
totalPoints.value = result.redPlayers[user.value.id].totalScore;
ifWin.value = result.winner === 0;
}
if (result.mode === 1 && result.bluePlayers[user.value.id]) {
totalPoints.value = result.bluePlayers[user.value.id].totalScore;
ifWin.value = result.winner === 1;
}
if (result.mode === 2) {
const mine = result.players.find((p) => p.playerId === user.value.id);
if (mine) totalPoints.value = mine.totalScore;
}
});
// onLoad(async (options) => {
// battleId.value = options.battleId;
// const result = await getGameAPI(
// // options.battleId || "BATTLE-1750867490990424058-718"
// options.battleId || "BATTLE-1752563964391008873-624"
// );
// data.value = result;
// if (result.mode === 1 && result.redPlayers[user.value.id]) {
// totalPoints.value = result.redPlayers[user.value.id].totalScore;
// ifWin.value = result.winner === 0;
// }
// if (result.mode === 1 && result.bluePlayers[user.value.id]) {
// totalPoints.value = result.bluePlayers[user.value.id].totalScore;
// ifWin.value = result.winner === 1;
// }
// if (result.mode === 2) {
// const mine = result.players.find((p) => p.playerId === user.value.id);
// if (mine) totalPoints.value = mine.totalScore;
// }
// });
function exit() {
uni.navigateBack();
}
onMounted(async () => {
const result = await getHomeData();
if (result.user) updateUser(result.user);
const battleInfo = uni.getStorageSync("last-battle");
console.log("----battleInfo", battleInfo);
data.value = battleInfo;
if (battleInfo.mode === 1) {
battleInfo.playerStats.forEach((p) => {
if (p.id === user.value.id) {
totalPoints.value = p.totalScore;
if (p.team === battleInfo.winner) ifWin.value = true;
}
});
} else if (battleInfo.mode === 2) {
const mine = battleInfo.playerStats.find((p) => p.id === user.value.id);
if (mine) totalPoints.value = mine.totalScore;
}
// const result = await getHomeData();
// if (result.user) updateUser(result.user);
});
const checkBowData = () => {
if (data.value.mode === 1) {
uni.navigateTo({
url: `/pages/team-bow-data?battleId=${battleId.value}`,
url: `/pages/team-bow-data?battleId=${data.value.id}`,
});
} else if (data.value.mode === 2) {
uni.navigateTo({
url: `/pages/melee-bow-data?battleId=${battleId.value}`,
url: `/pages/melee-bow-data?battleId=${data.value.id}`,
});
}
};
@@ -84,14 +98,14 @@ const checkBowData = () => {
<view
class="players"
:style="{
height: `${Math.max(data.players.length > 5 ? '330' : '300')}px`,
height: `${Math.max(data.playerStats.length > 5 ? '330' : '300')}px`,
}"
>
<view
v-for="(player, index) in data.players"
v-for="(player, index) in data.playerStats"
:key="index"
:style="{
border: player.playerId === user.id ? '1px solid #B04630' : 'none',
border: player.id === user.id ? '1px solid #B04630' : 'none',
}"
>
<image
@@ -150,10 +164,10 @@ const checkBowData = () => {
<view class="battle-e">
<image src="../static/row-yellow-bg.png" mode="widthFix" />
<Avatar v-if="data.mode === 1" :src="user.avatar" :size="40" />
<text v-if="data.gameMode === 1"
<text v-if="data.battleMode === 1"
>经验 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }}</text
>
<text v-if="data.gameMode === 2"
<text v-if="data.battleMode === 2"
>积分 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }}</text
>
</view>