2025-05-07 22:36:52 +08:00
|
|
|
|
import { Router } from 'vue-router';
|
2025-07-23 23:54:35 +08:00
|
|
|
|
|
2025-05-07 22:36:52 +08:00
|
|
|
|
import { useMusicStore } from '@/store/modules/music';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 导航到音乐列表页面的通用方法
|
|
|
|
|
|
* @param router Vue路由实例
|
|
|
|
|
|
* @param options 导航选项
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function navigateToMusicList(
|
|
|
|
|
|
router: Router,
|
|
|
|
|
|
options: {
|
|
|
|
|
|
id?: string | number;
|
|
|
|
|
|
type?: 'album' | 'playlist' | 'dailyRecommend' | string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
songList: any[];
|
|
|
|
|
|
listInfo?: any;
|
|
|
|
|
|
canRemove?: boolean;
|
|
|
|
|
|
}
|
|
|
|
|
|
) {
|
2025-09-10 00:29:50 +08:00
|
|
|
|
const musicStore = useMusicStore();
|
|
|
|
|
|
const { id, type, name, songList, listInfo, canRemove = false } = options;
|
2025-05-07 22:36:52 +08:00
|
|
|
|
|
2025-09-10 00:29:50 +08:00
|
|
|
|
// 如果是每日推荐,不需要设置 musicStore,直接从 recommendStore 获取
|
|
|
|
|
|
if (type !== 'dailyRecommend') {
|
|
|
|
|
|
musicStore.setCurrentMusicList(songList, name, listInfo, canRemove);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 确保 musicStore 的数据被清空,避免显示旧的列表
|
|
|
|
|
|
musicStore.clearCurrentMusicList();
|
|
|
|
|
|
}
|
2025-05-07 22:36:52 +08:00
|
|
|
|
|
2025-09-10 00:29:50 +08:00
|
|
|
|
// 路由跳转
|
|
|
|
|
|
if (id) {
|
2025-05-07 22:36:52 +08:00
|
|
|
|
router.push({
|
|
|
|
|
|
name: 'musicList',
|
|
|
|
|
|
params: { id },
|
|
|
|
|
|
query: { type }
|
|
|
|
|
|
});
|
2025-09-10 00:29:50 +08:00
|
|
|
|
} else {
|
2025-05-07 22:36:52 +08:00
|
|
|
|
router.push({
|
2025-09-10 00:29:50 +08:00
|
|
|
|
name: 'musicList',
|
|
|
|
|
|
query: { type: 'dailyRecommend' }
|
2025-05-07 22:36:52 +08:00
|
|
|
|
});
|
2025-09-10 00:29:50 +08:00
|
|
|
|
}
|
2025-07-23 23:54:35 +08:00
|
|
|
|
}
|