返回游戏时添加声音加载

This commit is contained in:
kron
2026-01-06 18:13:55 +08:00
parent ab3537e35d
commit 7cb203a08f
4 changed files with 33 additions and 15 deletions

View File

@@ -1,12 +1,14 @@
<script setup>
import { ref, watch, onMounted, onBeforeUnmount } from "vue";
import { onShow } from "@dcloudio/uni-app";
import { isGamingAPI, getCurrentGameAPI } from "@/apis";
import { debounce } from "@/util";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
const { user } = storeToRefs(useStore());
const props = defineProps({
signin: {
type: Function,
@@ -14,12 +16,15 @@ const props = defineProps({
},
});
const show = ref(false);
const loading = ref(false);
onShow(async () => {
if (user.value.id) {
const isGaming = await isGamingAPI();
show.value = isGaming;
}
});
watch(
() => user.value,
async (value) => {
@@ -31,16 +36,26 @@ watch(
}
}
);
const onClick = debounce(async () => {
const isGaming = await isGamingAPI();
show.value = isGaming;
if (isGaming) {
const result = await getCurrentGameAPI();
} else {
uni.showToast({
title: "比赛已结束",
icon: "none",
});
if (loading.value) return;
try {
const isGaming = await isGamingAPI();
show.value = isGaming;
if (isGaming) {
loading.value = true;
await uni.$checkAudio();
const result = await getCurrentGameAPI();
loading.value = false;
} else {
uni.showToast({
title: "比赛已结束",
icon: "none",
});
}
} finally {
loading.value = false;
}
});
const gameOver = () => {

View File

@@ -245,7 +245,10 @@ onBeforeUnmount(() => {
<image src="../static/bow-target.png" mode="widthFix" />
</view>
<view class="footer">
<PointSwitcher :onChange="(val) => (pMode = val)" />
<PointSwitcher
:onChange="(val) => (pMode = val)"
:style="{ zIndex: 999 }"
/>
</view>
<view class="simul" v-if="env !== 'release'">
<button @click="simulShoot">模拟</button>

View File

@@ -37,7 +37,7 @@ watch(
? "请红方射箭"
: "请蓝方射箭"
);
audioManager.play(key);
audioManager.play(key, false);
currentRoundEnded.value = false;
}
);