This commit is contained in:
kron
2025-06-08 12:52:49 +08:00
parent 5a50632c6c
commit deff79aa7b
15 changed files with 900 additions and 139 deletions

View File

@@ -2,19 +2,21 @@
import { ref, onMounted } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { getGameAPI } from "@/apis";
import TeamResult from "@/components/TeamResult.vue";
import MeleeResult from "@/components/MeleeResult.vue";
const battleId = ref("");
const show = ref(true);
onLoad((options) => {
battleId.value = options.battleId;
});
// onLoad(async (options) => {
// battleId.value = options.battleId;
// const result = await getGameAPI(options.battleId);
// console.log(1111, result);
// });
function exit() {
uni.navigateBack();
}
onMounted(async () => {
const result = await getGameAPI("BATTLE-1749121128909437828-799");
conosle.log(1111, result);
});
onMounted(async () => {});
</script>
<template>
@@ -35,9 +37,11 @@ onMounted(async () => {
</view>
<text>你是朋友中的佼佼者哦</text>
<view>
<view>查看靶纸</view>
<view @click="() => (show = true)">查看靶纸</view>
<view @click="exit">退出</view>
</view>
<!-- <TeamResult :show="show" :onClose="() => (show = false)" /> -->
<MeleeResult :show="show" :onClose="() => (show = false)" />
</view>
</template>

View File

@@ -75,6 +75,7 @@ const chooseVip = (index) => {
<style scoped>
.header {
width: calc(100% - 30px);
display: flex;
align-items: center;
justify-content: space-between;

172
src/pages/match-detail.vue Normal file
View File

@@ -0,0 +1,172 @@
<script setup>
import { ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import Container from "@/components/Container.vue";
import BattleHeader from "@/components/BattleHeader.vue";
import Avatar from "@/components/Avatar.vue";
const id = ref("");
const type = ref("");
const data = {
blueTeam: {
name: "选手1",
avatar: "../static/avatar.png",
arrows: [4, 6, 2],
score: 1,
},
redTeam: {
name: "选手2",
avatar: "../static/avatar.png",
arrows: [4, 6, 2],
score: 1,
},
};
const result = ref([
{
round: 1,
...data,
},
{
round: 2,
...data,
},
{
round: 3,
...data,
},
{
round: 4,
...data,
},
{
round: 5,
...data,
},
]);
onLoad((options) => {
type.value = options.type;
id.value = options.id;
});
</script>
<template>
<Container title="详情">
<view class="container">
<BattleHeader
:blueTeam="[
{ name: '选手1', avatar: '../static/avatar.png', winner: true },
]"
:redTeam="[{ name: '选手2', avatar: '../static/avatar.png' }]"
/>
<view class="score-header">
<text>决金箭轮环数</text>
<view>
<text>查看靶纸</text>
<image src="../static/back.png" mode="widthFix" />
</view>
</view>
<view class="score-row">
<view>
<Avatar src="../static/avatar.png" :size="25" :borderColor="1" />
<text>9</text>
<text>10</text>
<text>7</text>
</view>
<image src="../static/winner-badge.png" mode="widthFix" />
</view>
<view class="score-row" :style="{ marginBottom: '5px' }">
<view>
<Avatar src="../static/avatar.png" :size="25" :borderColor="2" />
<text>9</text>
<text>10</text>
<text>7</text>
</view>
</view>
<view v-for="(item, index) in result" :key="index">
<view class="score-header">
<text>{{ item.round }}</text>
<view>
<text>查看靶纸</text>
<image src="../static/back.png" mode="widthFix" />
</view>
</view>
<view class="score-row">
<view>
<Avatar src="../static/avatar.png" :size="25" :borderColor="1" />
<text>9</text>
<text>10</text>
<text>7</text>
</view>
<view>
<text :style="{ color: '#64BAFF' }">18</text>
<text>得分 +1</text>
</view>
</view>
<view class="score-row" :style="{ marginBottom: '5px' }">
<view>
<Avatar src="../static/avatar.png" :size="25" :borderColor="2" />
<text>9</text>
<text>10</text>
<text>7</text>
</view>
<view>
<text :style="{ color: '#FF6767' }">18</text>
<text>得分 +1</text>
</view>
</view>
</view>
<view :style="{ height: '20px' }"></view>
</view>
</Container>
</template>
<style scoped>
.container {
width: 100%;
height: 100%;
}
.score-header,
.score-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
color: #fff9;
font-size: 15px;
border-bottom: 1px solid #fff3;
}
.score-header > text:first-child {
color: #fed847;
}
.score-header > view:last-child {
display: flex;
align-items: center;
}
.score-header > view:last-child > image {
margin-left: 5px;
width: 15px;
height: 15px;
transform: rotate(180deg);
margin-top: -2px;
}
.score-row > view {
display: flex;
align-items: center;
}
.score-row > view:first-child > text {
margin-left: 20px;
color: #fff;
display: block;
width: 30px;
}
.score-row > image:last-child {
width: 40px;
}
.score-row > view:last-child {
padding-right: 5px;
}
.score-row > view:last-child > text:last-child {
margin-left: 20px;
}
</style>

View File

@@ -26,10 +26,6 @@ const tips = ref("即将开始...");
const seq = ref(0);
const timerSeq = ref(0);
const roundResults = ref([
// {
// blueArrows: [{ ring: 2 }, { ring: 2 }],
// redArrows: [{ ring: 2 }, { ring: 3 }],
// },
]);
onLoad((options) => {

View File

@@ -15,107 +15,98 @@ const handleSelect = async (index) => {
}
selectedIndex.value = index;
};
const toMatchDetail = () => {
uni.navigateTo({
url: "/pages/match-detail",
});
};
</script>
<template>
<Container title="我的成长脚印">
<view class="tabs">
<view
v-for="(rankType, index) in ['排位赛', '好友约战', '射馆练习']"
:key="index"
:style="{
color: index === selectedIndex ? '#000' : '#fff',
backgroundColor: index === selectedIndex ? '#FFD947' : 'transparent',
}"
@tap="handleSelect(index)"
>
{{ rankType }}
</view>
</view>
<view class="contents">
<view
:style="{
display: selectedIndex !== 2 ? 'flex' : 'none',
}"
>
<view>
<view class="contest-header">
<text>1V1</text>
<text>2025.01.21 14:09:23</text>
<image src="../static/back.png" mode="widthFix" />
</view>
<view class="contest-1v1">
<view class="player">
<Avatar frame src="../static/avatar.png" />
<text>选手1</text>
<image src="../static/winner-badge.png" mode="widthFix" />
</view>
<view class="player">
<Avatar frame src="../static/avatar.png" />
<text>选手2</text>
</view>
</view>
</view>
<view>
<view class="contest-header">
<text>1V1</text>
<text>2025.01.21 14:09:23</text>
<image src="../static/back.png" mode="widthFix" />
</view>
<view class="contest-1v1">
<view class="player">
<Avatar frame src="../static/avatar.png" />
<text>选手1</text>
<image src="../static/winner-badge.png" mode="widthFix" />
</view>
<view class="player">
<Avatar frame src="../static/avatar.png" />
<text>选手2</text>
</view>
</view>
</view>
<view>
<view class="contest-header">
<text>5v5</text>
<text>2025.01.21 14:09:23</text>
<image src="../static/back.png" mode="widthFix" />
</view>
<view class="contest-multi">
<view class="player">
<Avatar :rank="1" src="../static/avatar.png" />
<text>选手1</text>
</view>
<view class="player">
<Avatar :rank="2" src="../static/avatar.png" />
<text>选手2</text>
</view>
<view class="player">
<Avatar :rank="3" src="../static/avatar.png" />
<text>选手3</text>
</view>
<view class="player">
<Avatar :rank="4" src="../static/avatar.png" />
<text>选手4</text>
</view>
<view class="player">
<Avatar :rank="5" src="../static/avatar.png" />
<text>选手5</text>
</view>
</view>
</view>
</view>
<view
:style="{
display: selectedIndex === 2 ? 'flex' : 'none',
}"
>
<view class="container">
<view class="tabs">
<view
v-for="(item, index) in practiseList"
v-for="(rankType, index) in ['排位赛', '好友约战', '射馆练习']"
:key="index"
class="practice-record"
:style="{
color: index === selectedIndex ? '#000' : '#fff',
backgroundColor:
index === selectedIndex ? '#FFD947' : 'transparent',
}"
@tap="handleSelect(index)"
>
<text>单组练习 {{ item.createdAt }}</text>
<image src="../static/back.png" mode="widthFix" />
{{ rankType }}
</view>
</view>
<view class="contents">
<view
:style="{
display: selectedIndex !== 2 ? 'flex' : 'none',
}"
>
<view @click="toMatchDetail">
<view class="contest-header">
<text>1V1</text>
<text>2025.01.21 14:09:23</text>
<image src="../static/back.png" mode="widthFix" />
</view>
<view class="contest-1v1">
<view class="player">
<Avatar frame src="../static/avatar.png" />
<text>选手1</text>
<image src="../static/winner-badge.png" mode="widthFix" />
</view>
<view class="player">
<Avatar frame src="../static/avatar.png" />
<text>选手2</text>
</view>
</view>
</view>
<view @click="toMatchDetail">
<view class="contest-header">
<text>5v5</text>
<text>2025.01.21 14:09:23</text>
<image src="../static/back.png" mode="widthFix" />
</view>
<view class="contest-multi">
<view class="player">
<Avatar :rank="1" src="../static/avatar.png" />
<text>选手1</text>
</view>
<view class="player">
<Avatar :rank="2" src="../static/avatar.png" />
<text>选手2</text>
</view>
<view class="player">
<Avatar :rank="3" src="../static/avatar.png" />
<text>选手3</text>
</view>
<view class="player">
<Avatar :rank="4" src="../static/avatar.png" />
<text>选手4</text>
</view>
<view class="player">
<Avatar :rank="5" src="../static/avatar.png" />
<text>选手5</text>
</view>
</view>
</view>
</view>
<view
:style="{
display: selectedIndex === 2 ? 'flex' : 'none',
}"
>
<view
v-for="(item, index) in practiseList"
:key="index"
class="practice-record"
>
<text>单组练习 {{ item.createdAt }}</text>
<image src="../static/back.png" mode="widthFix" />
</view>
</view>
</view>
</view>
@@ -123,6 +114,9 @@ const handleSelect = async (index) => {
</template>
<style scoped>
.container {
width: 100%;
}
.tabs {
width: calc(100% - 30px);
display: flex;

View File

@@ -8,9 +8,15 @@ const handleSelect = (index) => {
selectedIndex.value = index;
};
const toMatchPage = (gameType, teamSize) => {
const toTeamMatchPage = (gameType, teamSize) => {
uni.navigateTo({
url: `/pages/match-room?gameType=${gameType}&teamSize=${teamSize}`,
url: `/pages/team-match?gameType=${gameType}&teamSize=${teamSize}`,
});
};
const toMeleeMatchPage = (gameType, teamSize) => {
uni.navigateTo({
url: `/pages/team-match?gameType=${gameType}&teamSize=${teamSize}`,
});
};
</script>
@@ -50,17 +56,17 @@ const toMatchPage = (gameType, teamSize) => {
<image
src="../static/battle1v1.png"
mode="widthFix"
@click="() => toMatchPage(1, 2)"
@click="() => toTeamMatchPage(1, 2)"
/>
<image
src="../static/battle5.png"
mode="widthFix"
@click="() => toMatchPage(2, 5)"
@click="() => toMeleeMatchPage(2, 5)"
/>
<image
src="../static/battle10.png"
mode="widthFix"
@click="() => toMatchPage(2, 10)"
@click="() => toMeleeMatchPage(2, 10)"
/>
</view>
<view class="data-progress">

167
src/pages/team-match.vue Normal file
View File

@@ -0,0 +1,167 @@
<script setup>
import { ref, onMounted, onUnmounted } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import Container from "@/components/Container.vue";
import BowTarget from "@/components/BowTarget.vue";
import ShootProgress from "@/components/ShootProgress.vue";
import PlayersRow from "@/components/PlayersRow.vue";
import Timer from "@/components/Timer.vue";
import BattleFooter from "@/components/BattleFooter.vue";
import SButton from "@/components/SButton.vue";
import { matchGameAPI, readyGameAPI } from "@/apis";
import { MESSAGETYPES, roundsName } from "@/constants";
const gameType = ref(0);
const teamSize = ref(0);
const matching = ref(false);
const start = ref(false);
const battleId = ref("");
const currentRound = ref(1);
const totalRounds = ref(0);
const power = ref(0);
const scores = ref([]);
const redTeam = ref([]);
const blueTeam = ref([]);
const currentShooterId = ref(0);
const tips = ref("即将开始...");
const seq = ref(0);
const timerSeq = ref(0);
const roundResults = ref([
// {
// blueArrows: [{ ring: 2 }, { ring: 2 }],
// redArrows: [{ ring: 2 }, { ring: 3 }],
// },
]);
onLoad((options) => {
gameType.value = options.gameType;
teamSize.value = options.teamSize;
});
async function startMatch() {
if (gameType.value && teamSize.value) {
await matchGameAPI(true, gameType.value, teamSize.value);
startMatch.value = true;
}
}
async function stopMatch() {
if (gameType.value && teamSize.value) {
await matchGameAPI(false, gameType.value, teamSize.value);
startMatch.value = false;
}
}
async function readyToGo() {
if (battleId.value) {
await readyGameAPI(battleId.value);
start.value = true;
timerSeq.value = 0;
}
}
async function onReceiveMessage(content) {
const messages = JSON.parse(content).data.updates || [];
messages.forEach((msg) => {
if (
!msg.id ||
(battleId.value && msg.id === battleId.value) ||
msg.constructor === MESSAGETYPES.WaitForAllReady
) {
console.log("收到消息:", msg);
}
if (!start.value && msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
scores.value.push(msg.target);
power.value = msg.target.battery;
}
if (msg.constructor === MESSAGETYPES.WaitForAllReady) {
// 这里会掉多次;
timerSeq.value += 1;
battleId.value = msg.id;
redTeam.value = msg.groupUserStatus.redTeam;
blueTeam.value = msg.groupUserStatus.blueTeam;
totalRounds.value = msg.groupUserStatus.config.maxRounds;
}
if (msg.id !== battleId.value) return;
if (msg.constructor === MESSAGETYPES.AllReady) {
start.value = true;
timerSeq.value = 0;
}
if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) {
scores.value = [];
seq.value += 1;
currentShooterId.value = msg.userId;
if (redTeam.value[0].id === currentShooterId.value) {
tips.value = `请红队射箭-第${roundsName[currentRound.value]}`;
} else {
tips.value = `请蓝队射箭-第${roundsName[currentRound.value]}`;
}
}
if (msg.constructor === MESSAGETYPES.ShootResult) {
scores.value = [msg.target];
}
if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) {
const result = msg.preRoundResult;
scores.value = [];
currentShooterId.value = 0;
if (result.currentRound > 0 && result.currentRound < totalRounds.value) {
// 开始下一轮;
roundResults.value = result.roundResults;
currentRound.value = result.currentRound + 1;
}
}
if (msg.constructor === MESSAGETYPES.MatchOver) {
uni.redirectTo({
url: "/pages/battle-result?battleId=" + msg.id,
});
}
});
}
onMounted(() => {
uni.$on("socket-inbox", onReceiveMessage);
});
onUnmounted(() => {
uni.$off("socket-inbox", onReceiveMessage);
if (startMatch.value) {
matchGameAPI(false, gameType.value, teamSize.value);
}
});
</script>
<template>
<Container title="排位赛" :bgType="1">
<view class="container">
<ShootProgress v-if="start" :tips="tips" :seq="seq" />
<PlayersRow
v-if="start"
:currentShooterId="currentShooterId"
:blueTeam="blueTeam"
:redTeam="redTeam"
/>
<BowTarget
:power="power"
:currentRound="currentRound"
:totalRound="totalRounds"
:scores="scores"
:tips="
!start && scores.length > 0
? `本次射程${scores[scores.length - 1].dst / 100}米,${
scores[scores.length - 1].dst / 100 >= 5 ? '已' : '未'
}达到距离要求`
: ''
"
/>
<BattleFooter
v-if="roundResults.length > 0"
:roundResults="roundResults"
/>
<Timer :seq="timerSeq" :callBack="readyToGo" />
</view>
<SButton v-if="!battleId" :onClick="matching ? stopMatch : startMatch">{{
matching ? "取消匹配" : "开始匹配"
}}</SButton>
<SButton v-if="battleId && !start" :onClick="readyToGo">准备完毕</SButton>
</Container>
</template>
<style scoped>
.container {
width: 100%;
}
</style>