@@ -77,10 +77,13 @@ export class PlayModeManager {
7777
7878 /**
7979 * 计算下一个随机模式
80+ * 注意:心跳模式只能通过菜单开启,不能通过点击随机按钮进入
8081 */
8182 public calculateNextShuffleMode ( currentMode : ShuffleModeType ) : ShuffleModeType {
8283 if ( currentMode === "off" ) return "on" ;
83- if ( currentMode === "on" ) return "heartbeat" ;
84+ if ( currentMode === "on" ) return "off" ;
85+ // 如果是心跳模式,点击随机按钮时退出心跳模式
86+ if ( currentMode === "heartbeat" ) return "off" ;
8487 return "off" ;
8588 }
8689
@@ -127,31 +130,36 @@ export class PlayModeManager {
127130 }
128131
129132 this . loadingMessage = window . $message . loading ( "心动模式开启中..." , {
130- duration : 0 , // 不自动关闭,必须手动 destroy
133+ duration : 0 ,
131134 } ) ;
132135
133- const pid =
134- musicStore . playPlaylistId || ( await dataStore . getUserLikePlaylist ( ) ) ?. detail ?. id || 0 ;
135- const currentSongId = musicStore . playSong ?. id || 0 ;
136-
137- if ( ! currentSongId ) throw new Error ( "无播放歌曲" ) ;
136+ try {
137+ const pid =
138+ musicStore . playPlaylistId || ( await dataStore . getUserLikePlaylist ( ) ) ?. detail ?. id || 0 ;
139+ if ( ! musicStore . playSong ) throw new Error ( "无播放歌曲" ) ;
140+ // 获取当前歌曲ID,如果不是纯数字则生成随机10位数
141+ let currentSongId = musicStore . playSong . id ;
142+ if ( ! Number . isInteger ( currentSongId ) || currentSongId <= 0 ) {
143+ currentSongId = Math . floor ( Math . random ( ) * 9000000000 ) + 1000000000 ;
144+ }
138145
139- const res = await heartRateList ( currentSongId , pid , undefined , signal ) ;
140- if ( res . code !== 200 ) throw new Error ( "获取推荐失败" ) ;
146+ const res = await heartRateList ( currentSongId , pid , undefined , signal ) ;
147+ if ( res . code !== 200 ) throw new Error ( "获取推荐失败" ) ;
141148
142- const recList = formatSongsList ( res . data ) ;
149+ const recList = formatSongsList ( res . data ) ;
143150
144- // 混合列表
145- const currentList = [ ...dataStore . playList ] ;
146- const mixedList = interleaveLists ( currentList , recList ) ;
151+ // 混合列表
152+ const currentList = [ ...dataStore . playList ] ;
153+ const mixedList = interleaveLists ( currentList , recList ) ;
147154
148- await dataStore . setPlayList ( mixedList ) ;
155+ await dataStore . setPlayList ( mixedList ) ;
149156
150- const idx = mixedList . findIndex ( ( s ) => s . id === currentSongId ) ;
151- if ( idx !== - 1 ) statusStore . playIndex = idx ;
152-
153- this . clearLoadingMessage ( ) ;
154- window . $message . success ( "心动模式已开启" ) ;
157+ const idx = mixedList . findIndex ( ( s ) => s . id === currentSongId ) ;
158+ if ( idx !== - 1 ) statusStore . playIndex = idx ;
159+ window . $message . success ( "心动模式已开启" ) ;
160+ } finally {
161+ this . clearLoadingMessage ( ) ;
162+ }
155163 }
156164
157165 /**
0 commit comments