返回游戏时添加声音加载

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

@@ -132,6 +132,7 @@ class AudioManager {
this.localFileCache = uni.getStorageSync("audio_local_files") || {};
// 启动时自动清理过期的缓存文件URL 已不在 audioFils 中的文件)
this.cleanObsoleteCache();
this.initAudios();
}
@@ -374,7 +375,6 @@ class AudioManager {
debugLog(`命中本地缓存: ${key}`);
setupAudio(localPath);
} else {
console.log("download");
// 下载并尝试保存
uni.downloadFile({
url: src,
@@ -382,7 +382,7 @@ class AudioManager {
success: (res) => {
if (res.tempFilePath) {
// 尝试保存文件到本地存储(持久化)
uni.saveFile({
uni.getFileSystemManager().saveFile({
tempFilePath: res.tempFilePath,
success: (saveRes) => {
const savedPath = saveRes.savedFilePath;

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;
}
);