修改日志显示

This commit is contained in:
kron
2025-09-18 10:01:10 +08:00
parent 72ab9c3757
commit 890867586b

View File

@@ -59,6 +59,18 @@ const audioFils = {
"https://static.shelingxingqiu.com/attachment/2025-09-17/dcutxinnvsx0tt7ksa.mp3", "https://static.shelingxingqiu.com/attachment/2025-09-17/dcutxinnvsx0tt7ksa.mp3",
}; };
// 版本控制日志函数
function debugLog(...args) {
// 获取当前环境信息
const accountInfo = uni.getAccountInfoSync();
const envVersion = accountInfo.miniProgram.envVersion;
// 只在体验版打印日志,正式版(release)和开发版(develop)不打印
if (envVersion === 'trial') {
console.log(...args);
}
}
class AudioManager { class AudioManager {
constructor() { constructor() {
this.audioMap = new Map(); this.audioMap = new Map();
@@ -78,11 +90,11 @@ class AudioManager {
// 初始化音频 // 初始化音频
initAudios() { initAudios() {
if (this.isLoading) { if (this.isLoading) {
console.log("音频正在加载中,跳过重复初始化"); debugLog("音频正在加载中,跳过重复初始化");
return this.loadingPromise; return this.loadingPromise;
} }
console.log("开始串行加载音频..."); debugLog("开始串行加载音频...");
this.isLoading = true; this.isLoading = true;
this.audioKeys = Object.keys(audioFils); this.audioKeys = Object.keys(audioFils);
this.currentLoadingIndex = 0; this.currentLoadingIndex = 0;
@@ -97,14 +109,14 @@ class AudioManager {
// 串行加载下一个音频 // 串行加载下一个音频
loadNextAudio(onComplete) { loadNextAudio(onComplete) {
if (this.currentLoadingIndex >= this.audioKeys.length) { if (this.currentLoadingIndex >= this.audioKeys.length) {
console.log("所有音频加载完成"); debugLog("所有音频加载完成");
this.isLoading = false; this.isLoading = false;
if (onComplete) onComplete(); if (onComplete) onComplete();
return; return;
} }
const key = this.audioKeys[this.currentLoadingIndex]; const key = this.audioKeys[this.currentLoadingIndex];
console.log(`开始加载音频 ${this.currentLoadingIndex + 1}/${this.audioKeys.length}: ${key}`); debugLog(`开始加载音频 ${this.currentLoadingIndex + 1}/${this.audioKeys.length}: ${key}`);
this.createAudio(key, () => { this.createAudio(key, () => {
this.currentLoadingIndex++; this.currentLoadingIndex++;
@@ -123,7 +135,7 @@ class AudioManager {
// 设置加载超时 // 设置加载超时
const loadTimeout = setTimeout(() => { const loadTimeout = setTimeout(() => {
console.log(`音频 ${key} 加载超时`); debugLog(`音频 ${key} 加载超时`);
audio.destroy(); audio.destroy();
if (callback) callback(); if (callback) callback();
}, 10000); }, 10000);
@@ -131,14 +143,14 @@ class AudioManager {
// 监听加载状态 // 监听加载状态
audio.onCanplay(() => { audio.onCanplay(() => {
clearTimeout(loadTimeout); clearTimeout(loadTimeout);
console.log(`音频 ${key} 已加载完成`); debugLog(`音频 ${key} 已加载完成`);
this.retryCount.set(key, 0); this.retryCount.set(key, 0);
if (callback) callback(); if (callback) callback();
}); });
audio.onError((res) => { audio.onError((res) => {
clearTimeout(loadTimeout); clearTimeout(loadTimeout);
console.log(`音频 ${key} 加载失败:`, res.errMsg); debugLog(`音频 ${key} 加载失败:`, res.errMsg);
this.handleAudioError(key); this.handleAudioError(key);
if (callback) callback(); if (callback) callback();
}); });
@@ -169,7 +181,7 @@ class AudioManager {
if (currentRetries < this.maxRetries) { if (currentRetries < this.maxRetries) {
this.retryCount.set(key, currentRetries + 1); this.retryCount.set(key, currentRetries + 1);
console.log(`音频 ${key} 开始第 ${currentRetries + 1} 次重试...`); debugLog(`音频 ${key} 开始第 ${currentRetries + 1} 次重试...`);
setTimeout(() => { setTimeout(() => {
this.retryLoadAudio(key); this.retryLoadAudio(key);
@@ -205,7 +217,7 @@ class AudioManager {
audio.play(); audio.play();
this.currentPlayingKey = key; this.currentPlayingKey = key;
} else { } else {
console.log(`音频 ${key} 不存在,尝试重新加载...`); debugLog(`音频 ${key} 不存在,尝试重新加载...`);
this.reloadAudio(key); this.reloadAudio(key);
} }
} }
@@ -224,7 +236,7 @@ class AudioManager {
// 手动重新加载指定音频 // 手动重新加载指定音频
reloadAudio(key) { reloadAudio(key) {
if (audioFils[key]) { if (audioFils[key]) {
console.log(`手动重新加载音频: ${key}`); debugLog(`手动重新加载音频: ${key}`);
this.retryCount.set(key, 0); this.retryCount.set(key, 0);
this.retryLoadAudio(key); this.retryLoadAudio(key);
} }