比赛结果数据源修改

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>

View File

@@ -73,8 +73,8 @@ watch(
onLoad(async (options) => {
if (options.battleId) {
const battleInfo = uni.getStorageSync(`battle-${options.battleId}`);
// console.log("----battleInfo", battleInfo);
const battleInfo = uni.getStorageSync("current-battle");
console.log("----battleInfo", battleInfo);
if (battleInfo) {
battleId.value = battleInfo.id;
start.value = true;
@@ -406,7 +406,7 @@ async function onReceiveMessage(messages = []) {
tips.value = "准备下半场";
}
if (msg.constructor === MESSAGETYPES.MatchOver) {
uni.setStorageSync("battle", msg.endStatus);
uni.setStorageSync("last-battle", msg.endStatus);
uni.redirectTo({
url: `/pages/battle-result?battleId=${msg.id}`,
});
@@ -541,10 +541,10 @@ onUnmounted(() => {
:total="total"
:currentRound="currentRound"
:battleId="battleId"
:melee="room.battleType === 2"
:melee="players.length > 0"
/>
<PlayersRow
v-if="room.battleType === 1"
v-if="blueTeam.length && redTeam.length"
:blueTeam="blueTeam"
:redTeam="redTeam"
:currentShooterId="currentShooterId"

View File

@@ -106,7 +106,7 @@ const comingSoon = () => {
<view class="feature-grid">
<view class="bow-card">
<image
src="https://api.shelingxingqiu.com/attachment/2025-07-15/dbci3g2g77tbxnujdl.webp"
src="https://api.shelingxingqiu.com/attachment/2025-07-15/dbciq9qhkpd3pqxawo.webp"
mode="widthFix"
@click="() => toPage('/pages/my-device')"
/>
@@ -343,12 +343,13 @@ const comingSoon = () => {
.player-avatar,
.more-players {
width: 80rpx;
height: 80rpx;
width: 82rpx;
height: 82rpx;
border-radius: 50%;
margin-right: -10px;
border: 1px solid #000;
position: relative;
box-sizing: border-box;
}
.player-avatar > image:first-child,

View File

@@ -22,7 +22,7 @@ const { user } = storeToRefs(store);
const gameType = ref(0);
const teamSize = ref(0);
const start = ref(false);
const countDown = ref(90);
const startCount = ref(false);
const battleId = ref("");
const currentRound = ref(1);
const power = ref(0);
@@ -35,6 +35,7 @@ const playersSorted = ref([]);
const playersScores = ref({});
const halfTimeTip = ref(false);
const onComplete = ref(null);
const total = ref(90);
watch(
() => [players.value, playersScores.value],
@@ -53,7 +54,7 @@ watch(
onLoad(async (options) => {
if (options.battleId) {
const battleInfo = uni.getStorageSync(`battle-${options.battleId}`);
const battleInfo = uni.getStorageSync("current-battle");
console.log("----battleInfo", battleInfo);
if (battleInfo) {
battleId.value = battleInfo.id;
@@ -71,7 +72,7 @@ onLoad(async (options) => {
}, 300);
} else if (remain > 90 && remain <= 110) {
halfTimeTip.value = true;
countDown.value = 20;
total.value = 20;
tips.value = "准备下半场";
setTimeout(() => {
uni.$emit("update-ramain", 110 - remain);
@@ -129,11 +130,12 @@ async function onReceiveMessage(messages = []) {
if (msg.id !== battleId.value) return;
if (msg.constructor === MESSAGETYPES.MeleeAllReady) {
start.value = true;
startCount.value = true;
seq.value += 1;
timerSeq.value = 0;
tips.value = "请连续射出6支箭";
scores.value = [];
countDown.value = 90;
total.value = 90;
}
if (msg.constructor === MESSAGETYPES.ShootResult) {
if (msg.userId === user.value.id) {
@@ -143,11 +145,13 @@ async function onReceiveMessage(messages = []) {
playersScores.value[msg.userId].push(msg.target);
}
if (msg.constructor === MESSAGETYPES.HalfTimeOver) {
startCount.value = false;
halfTimeTip.value = true;
countDown.value = 20;
total.value = 20;
tips.value = "准备下半场";
}
if (msg.constructor === MESSAGETYPES.MatchOver) {
uni.setStorageSync("last-battle", msg.endStatus);
uni.redirectTo({
url: `/pages/battle-result?battleId=${msg.id}`,
});
@@ -192,9 +196,9 @@ onUnmounted(() => {
<ShootProgress
v-if="start"
:seq="seq"
:start="start"
:start="start && startCount"
:tips="tips"
:total="countDown"
:total="total"
:melee="true"
/>
<view v-if="start" class="user-row">
@@ -207,6 +211,7 @@ onUnmounted(() => {
:currentRound="scores.length"
:totalRound="start ? 12 : 0"
:scores="scores"
:stop="halfTimeTip && !startCount"
/>
<view :style="{ paddingBottom: '20px' }">
<PlayerScore

View File

@@ -46,7 +46,7 @@ const isFinalShoot = ref(false);
onLoad(async (options) => {
if (options.battleId) {
const battleInfo = uni.getStorageSync(`battle-${options.battleId}`);
const battleInfo = uni.getStorageSync("current-battle");
// console.log("----battleInfo", battleInfo);
if (battleInfo) {
battleId.value = battleInfo.id;
@@ -203,6 +203,7 @@ async function onReceiveMessage(messages = []) {
}
}
if (msg.constructor === MESSAGETYPES.MatchOver) {
uni.setStorageSync("last-battle", msg.endStatus);
uni.redirectTo({
url: `/pages/battle-result?battleId=${msg.id}`,
});

View File

@@ -38,7 +38,7 @@ function createWebSocket(token, onMessage) {
if (!msg) return;
if (msg.constructor === MESSAGETYPES.BackToGame) {
const { battleInfo } = msg;
uni.setStorageSync(`battle-${battleInfo.id}`, battleInfo);
uni.setStorageSync("current-battle", battleInfo);
// 约战
if (battleInfo.config.battleMode === 1) {
uni.navigateTo({