Files
AlgerMusicPlayer/src/store/index.ts
T

44 lines
959 B
TypeScript
Raw Normal View History

import { createStore } from "vuex";
2021-07-20 22:46:18 +08:00
import { SongResult } from "@/type/music";
2021-07-21 17:45:21 +08:00
import { getMusicUrl } from "@/api/music";
2021-09-29 15:26:13 +08:00
import homeRouter from "@/router/home";
let 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,
playMusic: {} as SongResult,
2021-07-21 17:45:21 +08:00
playMusicUrl: "",
2021-09-29 17:24:03 +08:00
user: null as any,
};
2021-07-20 22:46:18 +08:00
let mutations = {
setMenus(state: any, menus: any[]) {
state.menus = menus;
},
2021-07-21 22:30:55 +08:00
async setPlay(state: any, playMusic: SongResult) {
2021-07-20 22:46:18 +08:00
state.playMusic = playMusic;
2021-07-21 22:30:55 +08:00
state.playMusicUrl = await getSongUrl(playMusic.id);
state.play = true;
2021-07-20 22:46:18 +08:00
},
setIsPlay(state: any, isPlay: boolean) {
state.isPlay = isPlay;
},
2021-07-21 22:30:55 +08:00
setPlayMusic(state: any, play: boolean) {
state.play = play;
},
2021-07-20 22:46:18 +08:00
};
2021-07-21 17:45:21 +08:00
const getSongUrl = async (id: number) => {
const { data } = await getMusicUrl(id);
console.log(data.data[0].url);
return data.data[0].url;
};
const store = createStore({
state: state,
mutations: mutations,
});
export default store;