添加全局返回游戏

This commit is contained in:
kron
2025-07-13 14:57:16 +08:00
parent b6d78d6070
commit fa959c73aa
10 changed files with 109 additions and 10 deletions

View File

@@ -0,0 +1,60 @@
<script setup>
import { ref, onMounted } from "vue";
import { onShow } from "@dcloudio/uni-app";
import { isGamingAPI, getCurrentGameAPI } from "@/apis";
const props = defineProps({
signin: {
type: Function,
default: () => {},
},
});
const show = ref(false);
onShow(async () => {
const isGaming = await isGamingAPI();
show.value = isGaming;
});
const onClick = async () => {
const result = await getCurrentGameAPI();
};
</script>
<template>
<view v-if="show" class="back-to-game" @click="onClick">
<image src="../static/back-to-game-bg.png" mode="widthFix" />
<image src="../static/pk-icon.png" mode="widthFix" />
<text>返回进行中的对局</text>
<image src="../static/back.png" mode="widthFix" />
</view>
</template>
<style scoped>
.back-to-game {
position: fixed;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
width: 56vw;
left: calc(50% - 28vw);
top: 12%;
z-index: 999;
}
.back-to-game > image:first-child {
position: absolute;
width: 100%;
}
.back-to-game > image:nth-child(2) {
position: relative;
width: 50px;
}
.back-to-game > text:nth-child(3) {
position: relative;
font-size: 14px;
}
.back-to-game > image:nth-child(4) {
position: relative;
width: 15px;
margin-left: 5px;
transform: rotate(180deg);
}
</style>

View File

@@ -214,7 +214,7 @@ const simulShoot2 = async () => {
top: calcRealY(bow.y),
backgroundColor: 'blue',
}"
>{{ bow.ring }}</view
>{{ index + 1 }}</view
>
</block>
<image src="../static/bow-target.png" mode="widthFix" />

View File

@@ -4,6 +4,7 @@ import { onShow } from "@dcloudio/uni-app";
import AppBackground from "@/components/AppBackground.vue";
import Header from "@/components/Header.vue";
import ScreenHint from "@/components/ScreenHint.vue";
import BackToGame from "@/components/BackToGame.vue";
import { getCurrentGameAPI } from "@/apis";
import { debounce } from "@/util";
defineProps({
@@ -27,6 +28,10 @@ defineProps({
type: Boolean,
default: false,
},
showBackToGame: {
type: Boolean,
default: true,
},
});
const isIos = ref(true);
const showHint = ref(false);
@@ -55,6 +60,7 @@ const goBack = () => {
<view>
<AppBackground :type="bgType" />
<Header v-if="!isHome" :title="title" :onBack="onBack" />
<BackToGame v-if="showBackToGame" />
<view
class="content"
:style="{
@@ -66,7 +72,9 @@ const goBack = () => {
</view>
<ScreenHint :show="showHint">
<view v-if="hintType === 1" class="tip-content">
<text>完成进行中的对局才能开启新的您有正在进行中的对局是否进入?</text>
<text
>完成进行中的对局才能开启新的您有正在进行中的对局是否进入?</text
>
<view>
<button hover-class="none" @click="backToGame">进入</button>
<button hover-class="none" @click="() => (showHint = false)">

View File

@@ -56,11 +56,11 @@ watch(
watch(
() => props.start,
(newVal, oldVal) => {
if (newVal === false) {
(newVal) => {
if (!newVal && timer.value) {
if (timer.value) clearInterval(timer.value);
}
if (!oldVal && newVal === true) {
if (newVal) {
remain.value = props.total;
// setTimeout(() => {
timer.value = setInterval(() => {
@@ -81,7 +81,15 @@ watch(
);
const updateRemain = (value) => {
if (timer.value) clearInterval(timer.value);
remain.value = Math.floor(value);
timer.value = setInterval(() => {
if (remain.value > 0) {
remain.value--;
} else {
props.onTimeIsUp();
}
}, 1000);
};
onMounted(() => {

View File

@@ -277,6 +277,11 @@ async function onReceiveMessage(messages = []) {
msg.target
);
}
} else {
roundResults.value.push({
redArrows: [],
blueArrows: [],
});
}
}
if (room.value.battleType === 2) {
@@ -373,7 +378,12 @@ onUnmounted(() => {
</script>
<template>
<Container title="对战" :onBack="onBack" :bgType="battleId ? 1 : 0">
<Container
title="对战"
:onBack="onBack"
:bgType="battleId ? 1 : 0"
:showBackToGame="false"
>
<view class="standby-phase" v-if="step === 1">
<Guide>
<view class="battle-guide">

View File

@@ -7,6 +7,7 @@ import UserHeader from "@/components/UserHeader.vue";
import SModal from "@/components/SModal.vue";
import Signin from "@/components/Signin.vue";
import BubbleTip from "@/components/BubbleTip.vue";
import BackToGame from "@/components/BackToGame.vue";
import {
getAppConfig,
getHomeData,
@@ -100,6 +101,7 @@ const comingSoon = () => {
<Container :isHome="true">
<view class="container" :style="{ paddingTop: isIos ? '100rpx' : '70rpx' }">
<UserHeader showRank :onSignin="() => (showModal = true)" />
<BackToGame />
<view :style="{ padding: '12px 10px' }">
<view class="feature-grid">
<view class="bow-card">

View File

@@ -93,7 +93,7 @@ onLoad(async (options) => {
}
});
async function stopMatch() {
uni.navigateBack();
uni.$showHint(3);
}
async function readyToGo() {
if (battleId.value) {
@@ -184,6 +184,7 @@ onUnmounted(() => {
:title="battleId ? '大乱斗排位赛' : '搜索对手...'"
:bgType="1"
:onBack="onBack"
:showBackToGame="false"
>
<view class="container">
<block v-if="battleId">

View File

@@ -47,7 +47,7 @@ const isFinalShoot = ref(false);
onLoad(async (options) => {
if (options.battleId) {
const battleInfo = uni.getStorageSync(`battle-${options.battleId}`);
// console.log("----battleInfo", battleInfo);
console.log("----battleInfo", battleInfo);
if (battleInfo) {
battleId.value = battleInfo.id;
start.value = true;
@@ -83,7 +83,7 @@ onLoad(async (options) => {
}
});
async function stopMatch() {
uni.navigateBack();
uni.$showHint(3);
}
async function readyToGo() {
if (battleId.value) {
@@ -153,6 +153,11 @@ async function onReceiveMessage(messages = []) {
msg.target
);
}
} else {
roundResults.value.push({
redArrows: [],
blueArrows: [],
});
}
}
if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) {
@@ -217,6 +222,7 @@ onUnmounted(() => {
:title="battleId ? '1V1排位赛' : '搜索对手...'"
:bgType="1"
:onBack="onBack"
:showBackToGame="false"
>
<view class="container">
<block v-if="battleId">
@@ -260,7 +266,11 @@ onUnmounted(() => {
:round="currentRound - 1"
:bluePoint="currentBluePoint"
:redPoint="currentRedPoint"
:roundData="roundResults[roundResults.length - 1]"
:roundData="
roundResults[roundResults.length - 2]
? roundResults[roundResults.length - 2]
: []
"
:onAutoClose="() => (showRoundTip = false)"
/>
</ScreenHint>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
src/static/pk-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB