Files
AlgerMusicPlayer/src/renderer/components/common/MusicListNavigator.ts
2025-09-10 13:13:17 +08:00

46 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Router } from 'vue-router';
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;
}
) {
const musicStore = useMusicStore();
const { id, type, name, songList, listInfo, canRemove = false } = options;
// 如果是每日推荐,不需要设置 musicStore直接从 recommendStore 获取
if (type !== 'dailyRecommend') {
musicStore.setCurrentMusicList(songList, name, listInfo, canRemove);
} else {
// 确保 musicStore 的数据被清空,避免显示旧的列表
musicStore.clearCurrentMusicList();
}
// 路由跳转
if (id) {
router.push({
name: 'musicList',
params: { id },
query: { type }
});
} else {
router.push({
name: 'musicList',
query: { type: 'dailyRecommend' }
});
}
}