2024-05-16 18:54:30 +08:00
|
|
|
import { createStore } from 'vuex';
|
|
|
|
|
|
2024-10-18 18:37:53 +08:00
|
|
|
import { useMusicListHook } from '@/hooks/MusicListHook';
|
2024-05-16 18:54:30 +08:00
|
|
|
import homeRouter from '@/router/home';
|
2024-09-13 14:11:02 +08:00
|
|
|
import type { SongResult } from '@/type/music';
|
2023-12-11 16:22:05 +08:00
|
|
|
|
|
|
|
|
interface State {
|
2024-05-16 18:54:30 +08:00
|
|
|
menus: any[];
|
|
|
|
|
play: boolean;
|
|
|
|
|
isPlay: boolean;
|
2024-09-13 14:11:02 +08:00
|
|
|
playMusic: SongResult;
|
2024-05-16 18:54:30 +08:00
|
|
|
playMusicUrl: string;
|
|
|
|
|
user: any;
|
2024-09-13 14:11:02 +08:00
|
|
|
playList: SongResult[];
|
2024-05-16 18:54:30 +08:00
|
|
|
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;
|
2023-12-11 16:22:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
2023-12-11 16:22:05 +08:00
|
|
|
playMusicUrl: '',
|
2024-05-22 15:14:26 +08:00
|
|
|
user: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user') as string) : null,
|
2023-12-11 16:22:05 +08:00
|
|
|
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,
|
2024-05-16 18:54:30 +08:00
|
|
|
};
|
|
|
|
|
const windowData = window as any;
|
2023-12-28 10:45:11 +08:00
|
|
|
|
2024-10-18 18:37:53 +08:00
|
|
|
const { handlePlayMusic, nextPlay, prevPlay } = useMusicListHook();
|
2024-01-02 11:08:02 +08:00
|
|
|
|
2023-12-11 16:22:05 +08:00
|
|
|
const mutations = {
|
|
|
|
|
setMenus(state: State, menus: any[]) {
|
2024-05-16 18:54:30 +08:00
|
|
|
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) {
|
2024-10-18 18:37:53 +08:00
|
|
|
await handlePlayMusic(state, playMusic);
|
2021-07-20 22:46:18 +08:00
|
|
|
},
|
2023-12-11 16:22:05 +08:00
|
|
|
setIsPlay(state: State, isPlay: boolean) {
|
2024-05-16 18:54:30 +08:00
|
|
|
state.isPlay = isPlay;
|
2021-07-20 22:46:18 +08:00
|
|
|
},
|
2023-12-11 16:22:05 +08:00
|
|
|
setPlayMusic(state: State, play: boolean) {
|
2024-05-16 18:54:30 +08:00
|
|
|
state.play = play;
|
2021-07-21 22:30:55 +08:00
|
|
|
},
|
2024-09-13 14:11:02 +08:00
|
|
|
setPlayList(state: State, playList: SongResult[]) {
|
2024-05-16 18:54:30 +08:00
|
|
|
state.playListIndex = playList.findIndex((item) => item.id === state.playMusic.id);
|
|
|
|
|
state.playList = playList;
|
2023-12-11 16:22:05 +08:00
|
|
|
},
|
|
|
|
|
async nextPlay(state: State) {
|
2024-10-18 18:37:53 +08:00
|
|
|
await nextPlay(state);
|
2023-12-11 16:22:05 +08:00
|
|
|
},
|
|
|
|
|
async prevPlay(state: State) {
|
2024-10-18 18:37:53 +08:00
|
|
|
await prevPlay(state);
|
2023-12-11 16:22:05 +08:00
|
|
|
},
|
2023-12-28 10:45:11 +08:00
|
|
|
async setSetData(state: State, setData: any) {
|
2024-05-16 18:54:30 +08:00
|
|
|
state.setData = setData;
|
2024-10-18 18:37:53 +08:00
|
|
|
window.electron && window.electron.ipcRenderer.setStoreValue('set', JSON.parse(JSON.stringify(setData)));
|
2023-12-28 10:45:11 +08:00
|
|
|
},
|
2024-05-16 18:54:30 +08:00
|
|
|
};
|
2021-07-20 15:29:20 +08:00
|
|
|
|
|
|
|
|
const store = createStore({
|
2024-05-16 18:54:30 +08:00
|
|
|
state,
|
|
|
|
|
mutations,
|
|
|
|
|
});
|
2021-07-20 15:29:20 +08:00
|
|
|
|
2024-05-16 18:54:30 +08:00
|
|
|
export default store;
|