From 60740274b728914aad3848ff20ee6432ab141e52 Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Tue, 19 Aug 2025 13:24:39 +1000 Subject: [PATCH] refactor: replace console statements with debug instances MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace all console.log/error/warn statements with appropriate debug instances - Add debug utils with modular debug instances for different components - Use debugUI for UI components (pages and components) - Use debugStore for store files - Use debugUtils for utility functions - Use debugPlayroom for Playroom specific debugging - Use debugLyrics for lyrics-related debugging - Use debugVisualizer for audio visualization debugging - Use debugResource for resource checking debugging - Maintain original message content with Chinese descriptions - Preserve Tab indentation throughout all files 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- package-lock.json | 24 ++++++++++++++++++++++ package.json | 3 ++- src/App.vue | 3 ++- src/components/AlbumDetailDialog.vue | 5 +++-- src/components/Player.vue | 2 +- src/components/ScrollingLyrics.vue | 9 +++++---- src/components/TrackItem.vue | 5 +++-- src/pages/AlbumDetail.vue | 7 ++++--- src/pages/Library.vue | 3 ++- src/pages/Playroom.vue | 21 +++++++++---------- src/stores/useFavourites.ts | 3 ++- src/stores/useUpdatePopup.ts | 7 ++++--- src/utils/audioVisualizer.ts | 5 +++-- src/utils/browserDetection.ts | 3 ++- src/utils/debug.ts | 30 ++++++++++++++++++++++++++++ src/utils/songResourceChecker.ts | 11 +++++----- 16 files changed, 104 insertions(+), 37 deletions(-) create mode 100644 src/utils/debug.ts diff --git a/package-lock.json b/package-lock.json index 5db5feb..ab0b0b7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@tailwindcss/vite": "^4.1.7", "axios": "^1.9.0", + "debug": "^4.4.1", "gsap": "^3.13.0", "pinia": "^3.0.2", "tailwindcss": "^4.1.7", @@ -1613,6 +1614,23 @@ "dev": true, "license": "MIT" }, + "node_modules/debug": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz", + "integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, "node_modules/delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -2295,6 +2313,12 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, "node_modules/muggle-string": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/muggle-string/-/muggle-string-0.4.1.tgz", diff --git a/package.json b/package.json index c215a13..5d701a5 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "dependencies": { "@tailwindcss/vite": "^4.1.7", "axios": "^1.9.0", + "debug": "^4.4.1", "gsap": "^3.13.0", "pinia": "^3.0.2", "tailwindcss": "^4.1.7", @@ -40,4 +41,4 @@ "vite": "^6.0.1", "vue-tsc": "^2.1.10" } -} \ No newline at end of file +} diff --git a/src/App.vue b/src/App.vue index 5dd9be0..62f0bce 100644 --- a/src/App.vue +++ b/src/App.vue @@ -8,6 +8,7 @@ import LeftArrowIcon from './assets/icons/leftarrow.vue' // import SearchIcon from './assets/icons/search.vue' import CorgIcon from './assets/icons/corg.vue' import { watch } from 'vue' +import { debug } from './utils/debug' import UpdatePopup from './components/UpdatePopup.vue' @@ -17,7 +18,7 @@ const route = useRoute() const router = useRouter() watch(() => presentPreferencePanel, (value) => { - console.log(value) + debug('偏好设置面板显示状态', value) }) diff --git a/src/components/AlbumDetailDialog.vue b/src/components/AlbumDetailDialog.vue index c9b8fc8..a0abd65 100644 --- a/src/components/AlbumDetailDialog.vue +++ b/src/components/AlbumDetailDialog.vue @@ -11,6 +11,7 @@ import { artistsOrganize } from '../utils' import { usePlayQueueStore } from '../stores/usePlayQueueStore' import TrackItem from './TrackItem.vue' import LoadingIndicator from '../assets/icons/loadingindicator.vue' +import { debugUI } from '../utils/debug' const props = defineProps<{ albumCid: string @@ -97,7 +98,7 @@ watch(() => props.present, async (newVal) => { }) watch(() => props.albumCid, async () => { - console.log("AlbumDetailDialog mounted with albumCid:", props.albumCid) + debugUI('专辑详情对话框加载', props.albumCid) album.value = undefined // Reset album when cid changes try { let res = await apis.getAlbum(props.albumCid) @@ -106,7 +107,7 @@ watch(() => props.albumCid, async () => { } album.value = res } catch (error) { - console.error(error) + debugUI('专辑详情加载失败', error) } }) diff --git a/src/components/Player.vue b/src/components/Player.vue index 147d1e2..61828a2 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -291,7 +291,7 @@ if (isAudioVisualizationSupported) { isAnalyzing = visualizer.isAnalyzing error = visualizer.error - console.log('[Player] audioVisualizer 返回值:', { + debugPlayer('audioVisualizer 返回值:', { barHeights: barHeights.value, isAnalyzing: isAnalyzing.value, }) diff --git a/src/components/ScrollingLyrics.vue b/src/components/ScrollingLyrics.vue index 05f762e..8f36266 100644 --- a/src/components/ScrollingLyrics.vue +++ b/src/components/ScrollingLyrics.vue @@ -90,6 +90,7 @@ import { onMounted, ref, watch, nextTick, computed, onUnmounted } from 'vue' import axios from 'axios' import gsap from 'gsap' import { usePlayQueueStore } from '../stores/usePlayQueueStore' +import { debugLyrics } from '../utils/debug' // 类型定义 interface LyricsLine { @@ -367,7 +368,7 @@ function handleWheel(event: WheelEvent) { // 处理歌词行点击 function handleLineClick(line: LyricsLine | GapLine, index: number) { if (line.type === 'lyric') { - console.log('Jump to time:', line.time) + debugLyrics('跳转到时间点', line.time) // 这里可以发出事件让父组件处理音频跳转 // emit('seek', line.time) } @@ -494,7 +495,7 @@ watch(() => playQueueStore.currentTime, (time) => { // 监听歌词源变化 watch(() => props.lrcSrc, async (newSrc) => { - console.log('Loading new lyrics from:', newSrc) + debugLyrics('加载新歌词', newSrc) // 重置状态 currentLineIndex.value = -1 lineRefs.value = [] @@ -517,7 +518,7 @@ watch(() => props.lrcSrc, async (newSrc) => { try { const response = await axios.get(newSrc) parsedLyrics.value = parseLyrics(response.data) - console.log('Parsed lyrics:', parsedLyrics.value) + debugLyrics('歌词解析完成', parsedLyrics.value) autoScroll.value = true userScrolling.value = false @@ -528,7 +529,7 @@ watch(() => props.lrcSrc, async (newSrc) => { } } catch (error) { - console.error('Failed to load lyrics:', error) + debugLyrics('歌词加载失败', error) parsedLyrics.value = [] } finally { loading.value = false diff --git a/src/components/TrackItem.vue b/src/components/TrackItem.vue index f43ae90..8080300 100644 --- a/src/components/TrackItem.vue +++ b/src/components/TrackItem.vue @@ -4,6 +4,7 @@ import { ref } from 'vue' import { usePlayQueueStore } from '../stores/usePlayQueueStore' import { useToast } from 'vue-toast-notification' import { useFavourites } from '../stores/useFavourites' +import { debugUI } from '../utils/debug' import QueueAddIcon from '../assets/icons/queueadd.vue' import StarEmptyIcon from '../assets/icons/starempty.vue' @@ -23,7 +24,7 @@ const toast = useToast() const favourites = useFavourites() function appendToQueue() { - console.log('aaa') + debugUI('添加歌曲到队列') let queue = playQueueStore.list queue.push({ song: props.track, @@ -41,7 +42,7 @@ function appendToQueue() {