diff --git a/src/audioManager.js b/src/audioManager.js
index 35f66f4..d8d2fe8 100644
--- a/src/audioManager.js
+++ b/src/audioManager.js
@@ -88,6 +88,20 @@ class AudioManager {
this.isLoading = false;
this.loadingPromise = null;
+ // 网络状态相关
+ this.networkOnline = true;
+ this.pendingPlayKey = null;
+ try {
+ uni.onNetworkStatusChange(({ isConnected }) => {
+ this.networkOnline = !!isConnected;
+ if (this.networkOnline) {
+ this.onNetworkRestored();
+ } else {
+ this.onNetworkLost();
+ }
+ });
+ } catch (_) {}
+
this.initAudios();
}
@@ -210,6 +224,11 @@ class AudioManager {
// 处理音频加载错误
handleAudioError(key) {
+ // 网络不可用时不重试,等重连后统一重建
+ if (!this.networkOnline) {
+ debugLog(`网络不可用,暂不重试音频: ${key}`);
+ return;
+ }
const currentRetries = this.retryCount.get(key) || 0;
if (currentRetries < this.maxRetries) {
@@ -233,6 +252,10 @@ class AudioManager {
// 重新加载音频
retryLoadAudio(key) {
+ if (!this.networkOnline) {
+ debugLog(`网络不可用,稍后再重载音频: ${key}`);
+ return;
+ }
const oldAudio = this.audioMap.get(key);
if (oldAudio) {
oldAudio.destroy();
@@ -242,6 +265,12 @@ class AudioManager {
// 播放指定音频
play(key) {
+ // 离线:缓存播放意图,待网络恢复后自动播放
+ if (!this.networkOnline) {
+ this.pendingPlayKey = key;
+ debugLog(`网络不可用,记录播放意图: ${key}`);
+ return;
+ }
// 覆盖播放:若当前播放且不是同一音频,先停止当前播放
if (this.currentPlayingKey && this.currentPlayingKey !== key) {
this.stop(this.currentPlayingKey);
@@ -314,6 +343,32 @@ class AudioManager {
this.currentPlayingKey = null;
}
+ // 断网回调:停止当前播放,避免误状态
+ onNetworkLost() {
+ try {
+ this.stopAll();
+ } catch (_) {}
+ }
+
+ // 重连回调:重建全部音频后,重放上一次的播放意图
+ onNetworkRestored() {
+ this.reinitializeOnReconnect();
+ if (this.pendingPlayKey) {
+ const key = this.pendingPlayKey;
+ this.pendingPlayKey = null;
+ // 避免与初始化竞态,轻微延迟后播放
+ setTimeout(() => {
+ this.play(key);
+ }, 20);
+ }
+ }
+
+ // 重连后统一重建音频实例
+ reinitializeOnReconnect() {
+ this.destroyAll();
+ this.initAudios();
+ }
+
// 手动重新加载指定音频
reloadAudio(key) {
if (audioFils[key]) {
diff --git a/src/components/BowTarget.vue b/src/components/BowTarget.vue
index 03dba11..d7d7e73 100644
--- a/src/components/BowTarget.vue
+++ b/src/components/BowTarget.vue
@@ -140,8 +140,27 @@ onBeforeUnmount(() => {
left: calcRealX(latestOne.ring ? latestOne.x : 0, 28),
top: calcRealY(latestOne.ring ? latestOne.y : 0, 28),
}"
- >{{ latestOne.ring || "未上靶"
- }}环{{ latestOne.ring || "未上靶" }}环
+
+
+ 经验 +1
+
+ {{ bluelatestOne.ring || "未上靶"
+ }}环