完成用户升级交互

This commit is contained in:
kron
2025-07-23 20:47:31 +08:00
parent 76e85501d5
commit b1874ba830
6 changed files with 124 additions and 72 deletions

View File

@@ -15,39 +15,50 @@ const ifWin = ref(false);
const data = ref({});
const totalPoints = ref(0);
const rank = ref(0);
const showUpgrade = ref(false);
const timer = ref(null);
const latestLvl = ref(0);
function exit() {
uni.navigateBack();
}
onLoad(async (options) => {
if (options.battleId) {
battleId.value = options.battleId;
const result = await getGameAPI(
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;
// }
} else {
const battleInfo = uni.getStorageSync("last-battle");
if (!battleInfo) return;
data.value = battleInfo;
const mine = battleInfo.playerStats.find((p) => p.id === user.value.id);
rank.value =
battleInfo.playerStats.findIndex((p) => p.id === user.value.id) + 1;
if (mine) {
totalPoints.value = mine.totalScore;
ifWin.value = battleInfo.mode === 1 && mine.team === battleInfo.winner;
}
}
});
const checkBowData = () => {
uni.navigateTo({
url: `/pages/match-detail?id=${data.value.id}`,
});
};
onMounted(async () => {
const battleInfo = uni.getStorageSync("last-battle");
data.value = battleInfo;
const mine = battleInfo.playerStats.find((p) => p.id === user.value.id);
rank.value =
battleInfo.playerStats.findIndex((p) => p.id === user.value.id) + 1;
if (mine) {
totalPoints.value = mine.totalScore;
ifWin.value = battleInfo.mode === 1 && mine.team === battleInfo.winner;
}
timer.value = setTimeout(() => {
const lastLvl = uni.getStorageSync("latest-lvl");
if (parseInt(lastLvl) > user.value.lvl) {
latestLvl.value = parseInt(lastLvl);
}
}, 1000);
});
onUnmounted(() => {
if (timer.value) clearTimeout(timer.value);
});
</script>
<template>
@@ -164,11 +175,7 @@ onUnmounted(() => {
<view @click="checkBowData">查看成绩</view>
<view @click="exit">退出</view>
</view>
<UserUpgrade
:show="showUpgrade"
:onClose="() => (showUpgrade = false)"
:lvl="latestLvl"
/>
<UserUpgrade />
</view>
</template>

View File

@@ -479,7 +479,7 @@ async function onReceiveMessage(messages = []) {
isEnded.value = true;
setTimeout(() => {
uni.redirectTo({
url: `/pages/battle-result?battleId=${msg.id}`,
url: "/pages/battle-result",
});
}, 1500);
}
@@ -533,6 +533,7 @@ onUnmounted(() => {
exitRoomAPI(roomNumber.value);
}
});
const refreshTimer = ref(null);
onShow(async () => {
if (battleId.value) {

View File

@@ -175,7 +175,7 @@ async function onReceiveMessage(messages = []) {
isEnded.value = true;
setTimeout(() => {
uni.redirectTo({
url: `/pages/battle-result?battleId=${msg.id}`,
url: "/pages/battle-result",
});
}, 1500);
}
@@ -211,7 +211,7 @@ onUnmounted(() => {
const refreshTimer = ref(null);
onShow(async () => {
if (battleId.value) {
if (!isEnded.value && (await isGameEnded())) return;
if (!isEnded.value && (await isGameEnded(battleId.value))) return;
getCurrentGameAPI();
const refreshData = () => {
const lastAwakeTime = uni.getStorageSync("last-awake-time");

View File

@@ -253,7 +253,7 @@ async function onReceiveMessage(messages = []) {
isEnded.value = true;
setTimeout(() => {
uni.redirectTo({
url: `/pages/battle-result?battleId=${msg.id}`,
url: "/pages/battle-result",
});
}, 1500);
}