Files
AlgerMusicPlayer/src/store/index.ts
T

78 lines
1.8 KiB
TypeScript
Raw Normal View History

import { createStore } from 'vuex';
import { useMusicListHook } from '@/hooks/MusicListHook';
import homeRouter from '@/router/home';
2024-09-13 14:11:02 +08:00
import type { SongResult } from '@/type/music';
interface State {
menus: any[];
play: boolean;
isPlay: boolean;
2024-09-13 14:11:02 +08:00
playMusic: SongResult;
playMusicUrl: string;
user: any;
2024-09-13 14:11:02 +08:00
playList: SongResult[];
playListIndex: number;
setData: any;
2024-05-20 19:54:00 +08:00
lyric: any;
2024-05-23 17:12:35 +08:00
isMobile: boolean;
2024-09-12 17:28:51 +08:00
searchValue: string;
searchType: number;
}
const state: State = {
2021-09-29 15:26:13 +08:00
menus: homeRouter,
2021-07-21 22:30:55 +08:00
play: false,
2021-07-20 22:46:18 +08:00
isPlay: false,
2024-09-13 14:11:02 +08:00
playMusic: {} as SongResult,
playMusicUrl: '',
2024-05-22 15:14:26 +08:00
user: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user') as string) : null,
playList: [],
playListIndex: 0,
2023-12-28 10:45:11 +08:00
setData: null,
2024-05-20 19:54:00 +08:00
lyric: {},
2024-05-23 17:12:35 +08:00
isMobile: false,
2024-09-12 17:28:51 +08:00
searchValue: '',
searchType: 1,
};
2023-12-28 10:45:11 +08:00
const { handlePlayMusic, nextPlay, prevPlay } = useMusicListHook();
const mutations = {
setMenus(state: State, menus: any[]) {
state.menus = menus;
2021-07-20 22:46:18 +08:00
},
2024-09-13 14:11:02 +08:00
async setPlay(state: State, playMusic: SongResult) {
await handlePlayMusic(state, playMusic);
2021-07-20 22:46:18 +08:00
},
setIsPlay(state: State, isPlay: boolean) {
state.isPlay = isPlay;
2021-07-20 22:46:18 +08:00
},
setPlayMusic(state: State, play: boolean) {
state.play = play;
2021-07-21 22:30:55 +08:00
},
2024-09-13 14:11:02 +08:00
setPlayList(state: State, playList: SongResult[]) {
state.playListIndex = playList.findIndex((item) => item.id === state.playMusic.id);
state.playList = playList;
},
async nextPlay(state: State) {
await nextPlay(state);
},
async prevPlay(state: State) {
await prevPlay(state);
},
2023-12-28 10:45:11 +08:00
async setSetData(state: State, setData: any) {
state.setData = setData;
if ((window as any).electron) {
(window as any).electron.ipcRenderer.setStoreValue('set', JSON.parse(JSON.stringify(setData)));
}
2023-12-28 10:45:11 +08:00
},
};
const store = createStore({
state,
mutations,
});
export default store;