@@ -40,8 +40,8 @@ interface ListState {
4040 song : SongType ;
4141 /** 音质 */
4242 quality : SongLevelType ;
43- /** 状态:下载中 / 失败 */
44- status : "downloading" | "failed" ;
43+ /** 状态:下载中 / 等待中 / 失败 */
44+ status : "downloading" | "waiting" | " failed";
4545 /** 下载进度 */
4646 progress : number ;
4747 /** 已传输大小 */
@@ -350,14 +350,23 @@ export const useDataStore = defineStore("data", {
350350 this . downloadingSongs . push ( {
351351 song : cloneDeep ( song ) ,
352352 quality,
353- status : "downloading " ,
353+ status : "waiting " ,
354354 progress : 0 ,
355355 transferred : "0MB" ,
356356 totalSize : "0MB" ,
357357 } ) ;
358358 // 保存到本地存储
359359 musicDB . setItem ( "downloadingSongs" , cloneDeep ( this . downloadingSongs ) ) ;
360360 } ,
361+ // 更新下载状态
362+ updateDownloadStatus ( songId : number , status : "downloading" | "waiting" | "failed" ) {
363+ const index = this . downloadingSongs . findIndex ( ( item ) => item . song . id === songId ) ;
364+ if ( index !== - 1 ) {
365+ this . downloadingSongs [ index ] . status = status ;
366+ // 强制触发响应式更新 (Fix: 下一首歌曲状态更新UI不变化的问题)
367+ this . downloadingSongs = [ ...this . downloadingSongs ] ;
368+ }
369+ } ,
361370 // 更新下载进度
362371 updateDownloadProgress (
363372 songId : number ,
@@ -370,7 +379,7 @@ export const useDataStore = defineStore("data", {
370379 item . progress = progress ;
371380 item . transferred = transferred ;
372381 item . totalSize = totalSize ;
373- // 进度更新过于频繁,不再实时保存到本地存储,仅在添加/删除时保存
382+ // 进度更新过于频繁,不需要强制更新整个数组,以免影响性能
374383 }
375384 } ,
376385 // 移除正在下载的歌曲(下载失败时)
@@ -383,23 +392,25 @@ export const useDataStore = defineStore("data", {
383392 } ,
384393 // 标记下载失败(保留在列表中)
385394 markDownloadFailed ( songId : number ) {
386- const item = this . downloadingSongs . find ( ( item ) => item . song . id === songId ) ;
387- if ( item ) {
388- item . status = "failed" ;
389- item . progress = 0 ;
390- item . transferred = "0MB" ;
391- item . totalSize = "0MB" ;
395+ const index = this . downloadingSongs . findIndex ( ( item ) => item . song . id === songId ) ;
396+ if ( index !== - 1 ) {
397+ this . downloadingSongs [ index ] . status = "failed" ;
398+ this . downloadingSongs [ index ] . progress = 0 ;
399+ this . downloadingSongs [ index ] . transferred = "0MB" ;
400+ this . downloadingSongs [ index ] . totalSize = "0MB" ;
401+ this . downloadingSongs = [ ...this . downloadingSongs ] ;
392402 musicDB . setItem ( "downloadingSongs" , cloneDeep ( this . downloadingSongs ) ) ;
393403 }
394404 } ,
395405 // 重置下载任务状态(用于重试)
396406 resetDownloadingSong ( songId : number ) {
397- const item = this . downloadingSongs . find ( ( item ) => item . song . id === songId ) ;
398- if ( item ) {
399- item . status = "downloading" ;
400- item . progress = 0 ;
401- item . transferred = "0MB" ;
402- item . totalSize = "0MB" ;
407+ const index = this . downloadingSongs . findIndex ( ( item ) => item . song . id === songId ) ;
408+ if ( index !== - 1 ) {
409+ this . downloadingSongs [ index ] . status = "waiting" ;
410+ this . downloadingSongs [ index ] . progress = 0 ;
411+ this . downloadingSongs [ index ] . transferred = "0MB" ;
412+ this . downloadingSongs [ index ] . totalSize = "0MB" ;
413+ this . downloadingSongs = [ ...this . downloadingSongs ] ;
403414 }
404415 } ,
405416 } ,
0 commit comments