1v1排位数据交互完善

This commit is contained in:
kron
2025-06-08 20:59:41 +08:00
parent 312906fec3
commit 80e0b07c0e
10 changed files with 232 additions and 84 deletions

View File

@@ -120,10 +120,37 @@ export const readyGameAPI = (battleId) => {
}); });
}; };
export const getGameAPI = (battleId) => { export const getGameAPI = async (battleId) => {
return request("POST", "/user/battle/detail", { const result = await request("POST", "/user/battle/detail", {
id: battleId, id: battleId,
}); });
const { battleStats = {}, playerStats = {} } = result;
const data = {
winner: battleStats.winner,
redTotal: battleStats.redTotal,
blueTotal: battleStats.blueTotal,
roundsData: {},
redPlayers: {},
bluePlayers: {},
};
playerStats.forEach((item) => {
const { playerBattleStats = {}, roundRecords = [] } = item;
if (playerBattleStats.team === 0) {
data.redPlayers[playerBattleStats.playerId] = playerBattleStats;
}
if (playerBattleStats.team === 1) {
data.bluePlayers[playerBattleStats.playerId] = playerBattleStats;
}
roundRecords.forEach((round) => {
data.roundsData[round.roundNumber] = {
...data.roundsData[round.roundNumber],
[round.playerId]: round.arrowHistory,
};
});
});
console.log("game result:", result);
console.log("format data:", data);
return data;
}; };
export const simulShootAPI = (device_id, x, y) => { export const simulShootAPI = (device_id, x, y) => {

View File

@@ -4,12 +4,24 @@ defineProps({
type: Array, type: Array,
default: () => [], default: () => [],
}, },
bluePoints: {
type: Number,
default: 0,
},
redPoints: {
type: Number,
default: 0,
},
}); });
</script> </script>
<template> <template>
<view class="container"> <view class="container">
<image src="../static/battle-header.png" mode="widthFix" /> <view>
<image src="../static/battle-header-melee.png" mode="widthFix" />
<text>蓝队({{ bluePoints }})</text>
<text>红队({{ redPoints }})</text>
</view>
<view class="players"> <view class="players">
<view> <view>
<view v-for="(result, index) in roundResults" :key="index"> <view v-for="(result, index) in roundResults" :key="index">
@@ -28,9 +40,11 @@ defineProps({
<view v-for="(result, index) in roundResults" :key="index"> <view v-for="(result, index) in roundResults" :key="index">
<text>Round {{ index + 1 }}</text> <text>Round {{ index + 1 }}</text>
<view> <view>
<text>{{ result.redArrows <text>{{
result.redArrows
.map((item) => item.ring) .map((item) => item.ring)
.reduce((last, next) => last + next, 0) }}</text> .reduce((last, next) => last + next, 0)
}}</text>
<text></text> <text></text>
</view> </view>
</view> </view>
@@ -42,13 +56,29 @@ defineProps({
<style scoped> <style scoped>
.container { .container {
width: 100%; width: 100%;
position: relative;
margin-top: 20px; margin-top: 20px;
} }
.container > image:first-child { .container > view:first-child {
position: relative;
display: flex;
justify-content: space-around;
align-items: center;
font-size: 13px;
}
.container > view:first-child > image:first-child {
position: absolute; position: absolute;
width: 100%; width: 100%;
top: -10px; top: -6px;
}
.container > view:first-child > text {
z-index: 1;
margin-top: 2px;
}
.container > view:first-child > text:nth-child(2) {
color: #364469;
}
.container > view:first-child > text:nth-child(3) {
color: #692735;
} }
.players { .players {
display: flex; display: flex;
@@ -60,7 +90,7 @@ defineProps({
align-items: center; align-items: center;
justify-content: center; justify-content: center;
color: #fff; color: #fff;
padding-top: 20px; padding-top: 5px;
} }
.players > view:first-child { .players > view:first-child {
background-color: #364469; background-color: #364469;

View File

@@ -27,22 +27,26 @@ defineProps({
</view> </view>
<view v-if="!isMelee" class="players"> <view v-if="!isMelee" class="players">
<view> <view>
<Avatar v-if="blueTeam[0]" :src="blueTeam[0].avatar" frame /> <block v-if="blueTeam[0]">
<text>{{ blueTeam[0].name }}</text> <Avatar :src="blueTeam[0].avatar" frame />
<image <text>{{ blueTeam[0].name }}</text>
v-if="blueTeam[0].winner" <image
src="../static/winner-badge.png" v-if="blueTeam[0].winner"
mode="widthFix" src="../static/winner-badge.png"
/> mode="widthFix"
/>
</block>
</view> </view>
<view> <view>
<Avatar v-if="redTeam[0]" :src="redTeam[0].avatar" frame /> <block v-if="redTeam[0]">
<text>{{ redTeam[0].name }}</text> <Avatar v-if="redTeam[0]" :src="redTeam[0].avatar" frame />
<image <text>{{ redTeam[0].name }}</text>
v-if="redTeam[0].winner" <image
src="../static/winner-badge.png" v-if="redTeam[0].winner"
mode="widthFix" src="../static/winner-badge.png"
/> mode="widthFix"
/>
</block>
</view> </view>
</view> </view>
</view> </view>

View File

@@ -30,6 +30,10 @@ const props = defineProps({
type: Array, type: Array,
default: () => [], default: () => [],
}, },
showE: {
type: Boolean,
default: true,
},
}); });
const showRoundTips = ref(false); const showRoundTips = ref(false);
@@ -71,10 +75,14 @@ function calcRealY(num) {
<BowPower v-if="power > 0" :power="power" /> <BowPower v-if="power > 0" :power="power" />
</view> </view>
<view class="target"> <view class="target">
<view v-if="scores.length && showRoundTips" class="e-value fade-in" <view
v-if="scores.length && showRoundTips && showE"
class="e-value fade-in"
>经验 +1</view >经验 +1</view
> >
<view v-if="scores.length && showRoundTips" class="round-tip fade-in" <view
v-if="scores.length && showRoundTips && scores[scores.length - 1].ring"
class="round-tip fade-in"
>{{ scores[scores.length - 1].ring }}<text></text></view >{{ scores[scores.length - 1].ring }}<text></text></view
> >
<image <image
@@ -152,7 +160,6 @@ function calcRealY(num) {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
margin-bottom: 20px;
} }
.header > image:first-child { .header > image:first-child {
width: 40px; width: 40px;

View File

@@ -113,7 +113,7 @@ defineProps({
.container > view > view > text { .container > view > view > text {
margin: 0 10px; margin: 0 10px;
overflow: hidden; overflow: hidden;
width: 100px; width: 120px;
transition: all 0.3s linear; transition: all 0.3s linear;
} }
.avatar { .avatar {

View File

@@ -1,7 +1,8 @@
<script setup> <script setup>
import { ref } from "vue"; import { ref, watch } from "vue";
import BowTarget from "@/components/BowTarget.vue"; import BowTarget from "@/components/BowTarget.vue";
import Avatar from "@/components/Avatar.vue"; import Avatar from "@/components/Avatar.vue";
import { roundsName } from "@/constants";
const props = defineProps({ const props = defineProps({
show: { show: {
type: Boolean, type: Boolean,
@@ -11,9 +12,50 @@ const props = defineProps({
type: Function, type: Function,
default: () => {}, default: () => {},
}, },
data: {
type: Object,
default: () => ({}),
},
}); });
const selected = ref(0); const selected = ref(0);
const tabs = ["所有轮次", "决金箭", "第三轮", "第二轮", "第一轮"]; const scores = ref([]);
const tabs = ref(["所有轮次"]);
const players = ref([]);
const onClickTab = (index) => {
selected.value = index;
scores.value = [];
if (index === 0) {
Object.values(props.data.roundsData).forEach((round) => {
Object.values(round).forEach((arrows) => {
scores.value = [...scores.value, ...Object.values(arrows)];
});
});
} else {
Object.values(props.data.roundsData[index]).forEach((arrows) => {
scores.value = [...scores.value, ...Object.values(arrows)];
});
}
};
watch(
() => props.data,
(value) => {
if (value.winner === 0) {
players.value = [
...Object.values(value.redPlayers),
...Object.values(value.bluePlayers),
];
} else if (value.winner === 1) {
players.value = [
...Object.values(value.bluePlayers),
...Object.values(value.redPlayers),
];
}
Object.keys(value.roundsData).forEach((key) => {
tabs.value.push(`${roundsName[key]}`);
});
onClickTab(0);
}
);
</script> </script>
<template> <template>
@@ -28,35 +70,28 @@ const tabs = ["所有轮次", "决金箭", "第三轮", "第二轮", "第一轮"
<view <view
v-for="(tab, index) in tabs" v-for="(tab, index) in tabs"
:key="index" :key="index"
@click="() => (selected = index)" @click="() => onClickTab(index)"
:class="selected === index ? 'selected-tab' : ''" :class="selected === index ? 'selected-tab' : ''"
> >
{{ tab }} {{ tab }}
</view> </view>
</view> </view>
<view :style="{ width: '95%' }"> <view :style="{ width: '95%' }">
<BowTarget /> <BowTarget :scores="scores" :showE="false" />
</view> </view>
<view class="score-row"> <view class="score-row" v-for="(player, index) in players" :key="index">
<Avatar src="../static/avatar.png" :borderColor="1" /> <Avatar
:src="player.avatar"
:borderColor="data.bluePlayers[player.playerId] ? 1 : 2"
/>
<view <view
v-for="(score, index) in [7, 9, 7, 3, 8]" v-if="selected > 0"
v-for="(score, index) in data.roundsData[selected][player.playerId]"
:key="index" :key="index"
class="score-item" class="score-item"
:style="{ width: '13vw', height: '13vw' }" :style="{ width: '13vw', height: '13vw' }"
> >
{{ score }} {{ score.ringScore }}
</view>
</view>
<view class="score-row">
<Avatar src="../static/avatar.png" :borderColor="2" />
<view
v-for="(score, index) in [7, 9, 7, 3, 8]"
:key="index"
class="score-item"
:style="{ width: '13vw', height: '13vw' }"
>
{{ score }}
</view> </view>
</view> </view>
</view> </view>
@@ -88,7 +123,7 @@ const tabs = ["所有轮次", "决金箭", "第三轮", "第二轮", "第一轮"
.container > view:first-child > view:last-child { .container > view:first-child > view:last-child {
position: absolute; position: absolute;
right: 5px; right: 5px;
top:32px; top: 32px;
} }
.container > view:first-child > view:last-child > image { .container > view:first-child > view:last-child > image {
width: 40px; width: 40px;
@@ -97,9 +132,15 @@ const tabs = ["所有轮次", "决金箭", "第三轮", "第二轮", "第一轮"
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: flex-start; justify-content: flex-start;
width: 100%; width: calc(100% - 20px);
color: #fff9; color: #fff9;
padding-left: 15px; padding: 0 10px;
overflow-x: auto;
}
.container > view:nth-child(2)::-webkit-scrollbar {
width: 0;
height: 0;
color: transparent;
} }
.container > view:nth-child(2) > view { .container > view:nth-child(2) > view {
border: 1px solid #fff9; border: 1px solid #fff9;
@@ -107,6 +148,7 @@ const tabs = ["所有轮次", "决金箭", "第三轮", "第二轮", "第一轮"
padding: 7px 10px; padding: 7px 10px;
margin: 0 5px; margin: 0 5px;
font-size: 14px; font-size: 14px;
flex: 0 0 auto;
} }
.selected-tab { .selected-tab {
background-color: #fed847; background-color: #fed847;

View File

@@ -8,6 +8,7 @@ export const MESSAGETYPES = {
ToSomeoneShoot: parseInt("0x077ACD1A"), // 125488410 ToSomeoneShoot: parseInt("0x077ACD1A"), // 125488410
SomeGuyIsReady: parseInt("0xAEE8C236"), // 2934489654 SomeGuyIsReady: parseInt("0xAEE8C236"), // 2934489654
MatchOver: parseInt("0xB7815EEF"), // 3078708975 MatchOver: parseInt("0xB7815EEF"), // 3078708975
RoundPoint: 4061248646,
}; };
export const roundsName = { export const roundsName = {

View File

@@ -4,15 +4,32 @@ import { onLoad } from "@dcloudio/uni-app";
import { getGameAPI } from "@/apis"; import { getGameAPI } from "@/apis";
import TeamResult from "@/components/TeamResult.vue"; import TeamResult from "@/components/TeamResult.vue";
import MeleeResult from "@/components/MeleeResult.vue"; import MeleeResult from "@/components/MeleeResult.vue";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
const battleId = ref(""); const battleId = ref("");
const show = ref(true); const ifWin = ref(false);
const data = ref({});
const totalPoints = ref(0);
const show = ref(false);
// onLoad(async (options) => { onLoad(async (options) => {
// battleId.value = options.battleId; battleId.value = options.battleId;
// const result = await getGameAPI(options.battleId); const result = await getGameAPI(
// console.log(1111, result); options.battleId || "BATTLE-1749386862250435325-854"
// }); );
data.value = result;
if (result.redPlayers[user.value.id]) {
totalPoints.value = result.redTotal;
ifWin.value = result.winner === 0;
}
if (result.bluePlayers[user.value.id]) {
totalPoints.value = result.redTotal;
ifWin.value = result.winner === 1;
}
});
function exit() { function exit() {
uni.navigateBack(); uni.navigateBack();
} }
@@ -21,27 +38,32 @@ onMounted(async () => {});
<template> <template>
<view class="container"> <view class="container">
<image class="tag" src="../static/winner-yellow.png" mode="widthFix" /> <image
:style="{ opacity: ifWin ? '1' : '0' }"
class="tag"
src="../static/winner-yellow.png"
mode="widthFix"
/>
<view> <view>
<image src="../static/battle-result.png" mode="widthFix" /> <image src="../static/battle-result.png" mode="widthFix" />
</view> </view>
<view> <view>
<image src="../static/shining-bg.png" mode="widthFix" /> <image src="../static/shining-bg.png" mode="widthFix" />
<image src="../static/throphy.png" mode="widthFix" /> <image src="../static/throphy.png" mode="widthFix" />
<text>蓝队获胜</text> <text>{{ ifWin && data.winner === 1 ? "蓝队" : "红队" }}获胜</text>
<text>强势登顶荣耀加冕</text> <text>强势登顶荣耀加冕</text>
</view> </view>
<view> <view>
<image src="../static/row-yellow-bg.png" mode="widthFix" /> <image src="../static/row-yellow-bg.png" mode="widthFix" />
<text>经验 +20</text> <text>经验 +{{ totalPoints }}</text>
</view> </view>
<text>你是朋友中的佼佼者哦</text> <text>你是朋友中的佼佼者哦</text>
<view> <view>
<view @click="() => (show = true)">查看靶纸</view> <view @click="() => (show = true)">查看靶纸</view>
<view @click="exit">退出</view> <view @click="exit">退出</view>
</view> </view>
<!-- <TeamResult :show="show" :onClose="() => (show = false)" /> --> <TeamResult :show="show" :onClose="() => (show = false)" :data="data" />
<MeleeResult :show="show" :onClose="() => (show = false)" /> <!-- <MeleeResult :show="show" :onClose="() => (show = false)" /> -->
</view> </view>
</template> </template>

View File

@@ -1,6 +1,11 @@
<script setup> <script setup>
import Container from "@/components/Container.vue"; import Container from "@/components/Container.vue";
import Avatar from "@/components/Avatar.vue";
import { ref } from "vue"; import { ref } from "vue";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
const selectedIndex = ref(0); const selectedIndex = ref(0);
@@ -27,11 +32,8 @@ const toMeleeMatchPage = (gameType, teamSize) => {
<view class="ranking-my-data"> <view class="ranking-my-data">
<view> <view>
<view class="user-info"> <view class="user-info">
<view class="avatar" @click="toUserPage"> <Avatar :src="user.avatarUrl" frame :size="30" />
<image src="../static/avatar-frame.png" mode="widthFix" /> <text>{{ user.nickName }}</text>
<image src="../static/avatar.png" mode="widthFix" />
</view>
<text>打酱油·路过</text>
</view> </view>
<view class="ranking-season"> <view class="ranking-season">
<text>第14赛季</text> <text>第14赛季</text>
@@ -166,22 +168,8 @@ const toMeleeMatchPage = (gameType, teamSize) => {
color: #fff; color: #fff;
font-size: 14px; font-size: 14px;
} }
.avatar { .user-info > text {
position: relative; margin-left: 15px;
display: flex;
align-items: center;
justify-content: center;
margin-right: 15px;
}
.avatar > image:first-child {
position: absolute;
width: 40px;
height: 40px;
}
.avatar > image {
width: 30px;
height: 30px;
border-radius: 50%;
} }
.ranking-season { .ranking-season {
display: flex; display: flex;

View File

@@ -2,6 +2,8 @@
import { ref, onMounted, onUnmounted } from "vue"; import { ref, onMounted, onUnmounted } from "vue";
import { onLoad } from "@dcloudio/uni-app"; import { onLoad } from "@dcloudio/uni-app";
import Container from "@/components/Container.vue"; import Container from "@/components/Container.vue";
import BattleHeader from "@/components/BattleHeader.vue";
import Guide from "@/components/Guide.vue";
import BowTarget from "@/components/BowTarget.vue"; import BowTarget from "@/components/BowTarget.vue";
import ShootProgress from "@/components/ShootProgress.vue"; import ShootProgress from "@/components/ShootProgress.vue";
import PlayersRow from "@/components/PlayersRow.vue"; import PlayersRow from "@/components/PlayersRow.vue";
@@ -10,6 +12,10 @@ import BattleFooter from "@/components/BattleFooter.vue";
import SButton from "@/components/SButton.vue"; import SButton from "@/components/SButton.vue";
import { matchGameAPI, readyGameAPI } from "@/apis"; import { matchGameAPI, readyGameAPI } from "@/apis";
import { MESSAGETYPES, roundsName } from "@/constants"; import { MESSAGETYPES, roundsName } from "@/constants";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
const gameType = ref(0); const gameType = ref(0);
const teamSize = ref(0); const teamSize = ref(0);
const matching = ref(false); const matching = ref(false);
@@ -31,6 +37,8 @@ const roundResults = ref([
// redArrows: [{ ring: 2 }, { ring: 3 }], // redArrows: [{ ring: 2 }, { ring: 3 }],
// }, // },
]); ]);
const redPoints = ref(0);
const bluePoints = ref(0);
onLoad((options) => { onLoad((options) => {
gameType.value = options.gameType; gameType.value = options.gameType;
@@ -38,6 +46,7 @@ onLoad((options) => {
}); });
async function startMatch() { async function startMatch() {
if (gameType.value && teamSize.value) { if (gameType.value && teamSize.value) {
scores.value = [];
await matchGameAPI(true, gameType.value, teamSize.value); await matchGameAPI(true, gameType.value, teamSize.value);
startMatch.value = true; startMatch.value = true;
} }
@@ -82,6 +91,7 @@ async function onReceiveMessage(content) {
if (msg.constructor === MESSAGETYPES.AllReady) { if (msg.constructor === MESSAGETYPES.AllReady) {
start.value = true; start.value = true;
timerSeq.value = 0; timerSeq.value = 0;
scores.value = [];
} }
if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) { if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) {
scores.value = []; scores.value = [];
@@ -96,6 +106,10 @@ async function onReceiveMessage(content) {
if (msg.constructor === MESSAGETYPES.ShootResult) { if (msg.constructor === MESSAGETYPES.ShootResult) {
scores.value = [msg.target]; scores.value = [msg.target];
} }
if (msg.constructor === MESSAGETYPES.RoundPoint) {
bluePoints.value += msg.blueScore;
redPoints.value += msg.redScore;
}
if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) { if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) {
const result = msg.preRoundResult; const result = msg.preRoundResult;
scores.value = []; scores.value = [];
@@ -108,7 +122,7 @@ async function onReceiveMessage(content) {
} }
if (msg.constructor === MESSAGETYPES.MatchOver) { if (msg.constructor === MESSAGETYPES.MatchOver) {
uni.redirectTo({ uni.redirectTo({
url: "/pages/battle-result?battleId=" + msg.id, url: `/pages/battle-result?battleId=${msg.id}&winner=${msg.endStatus.winner}`,
}); });
} }
}); });
@@ -127,6 +141,16 @@ onUnmounted(() => {
<template> <template>
<Container title="排位赛" :bgType="1"> <Container title="排位赛" :bgType="1">
<view class="container"> <view class="container">
<BattleHeader v-if="!start" :redTeam="redTeam" :blueTeam="blueTeam" />
<Guide noBg v-if="!start">
<view :style="{ display: 'flex', justifyContent: 'space-between' }">
<view :style="{ display: 'flex', flexDirection: 'column' }">
<text :style="{ color: '#fed847' }">请预先射几箭测试</text>
<text>请确保射击距离只有5米</text>
</view>
<BowPower :power="45" />
</view>
</Guide>
<ShootProgress v-if="start" :tips="tips" :seq="seq" /> <ShootProgress v-if="start" :tips="tips" :seq="seq" />
<PlayersRow <PlayersRow
v-if="start" v-if="start"
@@ -135,7 +159,8 @@ onUnmounted(() => {
:redTeam="redTeam" :redTeam="redTeam"
/> />
<BowTarget <BowTarget
:power="power" :showE="start && user.id === currentShooterId"
:power="start ? power : 0"
:currentRound="currentRound" :currentRound="currentRound"
:totalRound="totalRounds" :totalRound="totalRounds"
:scores="scores" :scores="scores"
@@ -148,8 +173,10 @@ onUnmounted(() => {
" "
/> />
<BattleFooter <BattleFooter
v-if="roundResults.length > 0" v-if="start"
:roundResults="roundResults" :roundResults="roundResults"
:redPoints="redPoints"
:bluePoints="bluePoints"
/> />
<Timer :seq="timerSeq" :callBack="readyToGo" /> <Timer :seq="timerSeq" :callBack="readyToGo" />
</view> </view>