返回游戏时添加声音加载
This commit is contained in:
@@ -132,6 +132,7 @@ class AudioManager {
|
|||||||
this.localFileCache = uni.getStorageSync("audio_local_files") || {};
|
this.localFileCache = uni.getStorageSync("audio_local_files") || {};
|
||||||
// 启动时自动清理过期的缓存文件(URL 已不在 audioFils 中的文件)
|
// 启动时自动清理过期的缓存文件(URL 已不在 audioFils 中的文件)
|
||||||
this.cleanObsoleteCache();
|
this.cleanObsoleteCache();
|
||||||
|
|
||||||
this.initAudios();
|
this.initAudios();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,7 +375,6 @@ class AudioManager {
|
|||||||
debugLog(`命中本地缓存: ${key}`);
|
debugLog(`命中本地缓存: ${key}`);
|
||||||
setupAudio(localPath);
|
setupAudio(localPath);
|
||||||
} else {
|
} else {
|
||||||
console.log("download");
|
|
||||||
// 下载并尝试保存
|
// 下载并尝试保存
|
||||||
uni.downloadFile({
|
uni.downloadFile({
|
||||||
url: src,
|
url: src,
|
||||||
@@ -382,7 +382,7 @@ class AudioManager {
|
|||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (res.tempFilePath) {
|
if (res.tempFilePath) {
|
||||||
// 尝试保存文件到本地存储(持久化)
|
// 尝试保存文件到本地存储(持久化)
|
||||||
uni.saveFile({
|
uni.getFileSystemManager().saveFile({
|
||||||
tempFilePath: res.tempFilePath,
|
tempFilePath: res.tempFilePath,
|
||||||
success: (saveRes) => {
|
success: (saveRes) => {
|
||||||
const savedPath = saveRes.savedFilePath;
|
const savedPath = saveRes.savedFilePath;
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, watch, onMounted, onBeforeUnmount } from "vue";
|
import { ref, watch, onMounted, onBeforeUnmount } from "vue";
|
||||||
import { onShow } from "@dcloudio/uni-app";
|
import { onShow } from "@dcloudio/uni-app";
|
||||||
|
|
||||||
import { isGamingAPI, getCurrentGameAPI } from "@/apis";
|
import { isGamingAPI, getCurrentGameAPI } from "@/apis";
|
||||||
import { debounce } from "@/util";
|
import { debounce } from "@/util";
|
||||||
|
|
||||||
import useStore from "@/store";
|
import useStore from "@/store";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
const store = useStore();
|
const { user } = storeToRefs(useStore());
|
||||||
const { user } = storeToRefs(store);
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
signin: {
|
signin: {
|
||||||
type: Function,
|
type: Function,
|
||||||
@@ -14,12 +16,15 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
const show = ref(false);
|
const show = ref(false);
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
onShow(async () => {
|
onShow(async () => {
|
||||||
if (user.value.id) {
|
if (user.value.id) {
|
||||||
const isGaming = await isGamingAPI();
|
const isGaming = await isGamingAPI();
|
||||||
show.value = isGaming;
|
show.value = isGaming;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => user.value,
|
() => user.value,
|
||||||
async (value) => {
|
async (value) => {
|
||||||
@@ -31,16 +36,26 @@ watch(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const onClick = debounce(async () => {
|
const onClick = debounce(async () => {
|
||||||
const isGaming = await isGamingAPI();
|
if (loading.value) return;
|
||||||
show.value = isGaming;
|
try {
|
||||||
if (isGaming) {
|
const isGaming = await isGamingAPI();
|
||||||
const result = await getCurrentGameAPI();
|
show.value = isGaming;
|
||||||
} else {
|
|
||||||
uni.showToast({
|
if (isGaming) {
|
||||||
title: "比赛已结束",
|
loading.value = true;
|
||||||
icon: "none",
|
await uni.$checkAudio();
|
||||||
});
|
const result = await getCurrentGameAPI();
|
||||||
|
loading.value = false;
|
||||||
|
} else {
|
||||||
|
uni.showToast({
|
||||||
|
title: "比赛已结束",
|
||||||
|
icon: "none",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const gameOver = () => {
|
const gameOver = () => {
|
||||||
|
|||||||
@@ -245,7 +245,10 @@ onBeforeUnmount(() => {
|
|||||||
<image src="../static/bow-target.png" mode="widthFix" />
|
<image src="../static/bow-target.png" mode="widthFix" />
|
||||||
</view>
|
</view>
|
||||||
<view class="footer">
|
<view class="footer">
|
||||||
<PointSwitcher :onChange="(val) => (pMode = val)" />
|
<PointSwitcher
|
||||||
|
:onChange="(val) => (pMode = val)"
|
||||||
|
:style="{ zIndex: 999 }"
|
||||||
|
/>
|
||||||
</view>
|
</view>
|
||||||
<view class="simul" v-if="env !== 'release'">
|
<view class="simul" v-if="env !== 'release'">
|
||||||
<button @click="simulShoot">模拟</button>
|
<button @click="simulShoot">模拟</button>
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ watch(
|
|||||||
? "请红方射箭"
|
? "请红方射箭"
|
||||||
: "请蓝方射箭"
|
: "请蓝方射箭"
|
||||||
);
|
);
|
||||||
audioManager.play(key);
|
audioManager.play(key, false);
|
||||||
currentRoundEnded.value = false;
|
currentRoundEnded.value = false;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user