feat: 优化播放器样式 添加单曲循环 优化桌面歌词效果

This commit is contained in:
alger
2024-12-15 01:40:13 +08:00
parent f2f5d3ac15
commit 7be126cf5f
7 changed files with 316 additions and 86 deletions
+13 -2
View File
@@ -13,6 +13,11 @@ const defaultSettings = {
authorUrl: 'https://github.com/algerkong',
};
function getLocalStorageItem<T>(key: string, defaultValue: T): T {
const item = localStorage.getItem(key);
return item ? JSON.parse(item) : defaultValue;
}
interface State {
menus: any[];
play: boolean;
@@ -28,6 +33,7 @@ interface State {
searchValue: string;
searchType: number;
favoriteList: number[];
playMode: number;
}
const state: State = {
@@ -36,7 +42,7 @@ const state: State = {
isPlay: false,
playMusic: {} as SongResult,
playMusicUrl: '',
user: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user') as string) : null,
user: getLocalStorageItem('user', null),
playList: [],
playListIndex: 0,
setData: defaultSettings,
@@ -44,7 +50,8 @@ const state: State = {
isMobile: false,
searchValue: '',
searchType: 1,
favoriteList: localStorage.getItem('favoriteList') ? JSON.parse(localStorage.getItem('favoriteList') || '[]') : [],
favoriteList: getLocalStorageItem('favoriteList', []),
playMode: getLocalStorageItem('playMode', 0),
};
const { handlePlayMusic, nextPlay, prevPlay } = useMusicListHook();
@@ -91,6 +98,10 @@ const mutations = {
state.favoriteList = state.favoriteList.filter((id) => id !== songId);
localStorage.setItem('favoriteList', JSON.stringify(state.favoriteList));
},
togglePlayMode(state: State) {
state.playMode = state.playMode === 0 ? 1 : 0;
localStorage.setItem('playMode', JSON.stringify(state.playMode));
},
};
const actions = {