Pārlūkot izejas kodu

fix(player): 修复Feature 13专辑信息展示和播放列表加载

问题修复:
1. Feature 13 - 专辑信息展示不正确
   - 之前显示: "0:01 · 2字"
   - 现在显示: "默认专辑 · 1/7" (专辑名 + 集数/总数)

2. 播放列表加载失败
   - 修复ID类型比较问题 (string vs number)
   - 添加兜底逻辑:未找到匹配时使用第一项
   - 现在正确加载7个音频到播放列表

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
MyFramework User 5 mēneši atpakaļ
vecāks
revīzija
486db6103c
1 mainītis faili ar 23 papildinājumiem un 3 dzēšanām
  1. 23 3
      my-uniapp-vue3/src/pages/player/index.vue

+ 23 - 3
my-uniapp-vue3/src/pages/player/index.vue

@@ -15,7 +15,10 @@
         <text class="cover-icon">🎵</text>
       </view>
       <text class="title">{{ audio?.title || '未知标题' }}</text>
-      <text class="meta">{{ formatDuration(audio?.audioDuration || 0) }} · {{ audio?.wordCount || 0 }}字</text>
+      <text class="meta">
+        {{ albumName || '默认专辑' }}
+        <text v-if="playlist.length > 1"> · {{ currentIndex + 1 }}/{{ playlist.length }}</text>
+      </text>
     </view>
 
     <!-- 文本预览 -->
@@ -235,6 +238,7 @@ const audioStore = useAudioStore();
 // 状态
 const audioId = ref('');
 const audio = ref<AudioItem | null>(null);
+const albumName = ref(''); // 专辑名称
 const showRatePicker = ref(false);
 const showTimerPicker = ref(false);
 const showSharePanel = ref(false);
@@ -416,6 +420,18 @@ async function fetchAudio() {
     const result = await get<AudioItem>(`/audio/${audioId.value}`);
     audio.value = result;
 
+    // 获取专辑信息
+    if (result.albumId) {
+      try {
+        const album = await get<any>(`/albums/${result.albumId}`);
+        albumName.value = album.name || '默认专辑';
+      } catch {
+        albumName.value = '默认专辑';
+      }
+    } else {
+      albumName.value = '默认专辑';
+    }
+
     // 开始播放(store 中已初始化 audioContext)
     audioStore.play(result);
   } catch (error: any) {
@@ -431,11 +447,15 @@ async function fetchPlaylist() {
       page: 1,
       pageSize: 100,
     });
-    
+
     // 设置播放列表(不自动播放,因为已经在 fetchAudio 中播放了当前音频)
-    const index = result.list.findIndex(item => (item.id || item._id) === audioId.value);
+    const audioIdNum = parseInt(audioId.value);
+    const index = result.list.findIndex(item => (item.id || item._id) === audioIdNum);
     if (index >= 0) {
       audioStore.setPlaylist(result.list, index, false);
+    } else if (result.list.length > 0) {
+      // 如果没找到匹配的,使用第一个
+      audioStore.setPlaylist(result.list, 0, false);
     }
   } catch (error) {
     console.error('获取播放列表失败:', error);