修改日志显示

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