mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-23 23:57:22 +08:00
✨ feat: 添加eslint 和 桌面歌词(未完成)
This commit is contained in:
+56
-61
@@ -1,20 +1,21 @@
|
||||
import { createStore } from 'vuex'
|
||||
import { SongResult } from '@/type/music'
|
||||
import { getMusicUrl, getParsingMusicUrl } from '@/api/music'
|
||||
import homeRouter from '@/router/home'
|
||||
import { getMusicProxyUrl } from '@/utils'
|
||||
import { useMusicHistory } from '@/hooks/MusicHistoryHook'
|
||||
import { createStore } from 'vuex';
|
||||
|
||||
import { getMusicUrl, getParsingMusicUrl } from '@/api/music';
|
||||
import { useMusicHistory } from '@/hooks/MusicHistoryHook';
|
||||
import homeRouter from '@/router/home';
|
||||
import { SongResult } from '@/type/music';
|
||||
import { getMusicProxyUrl } from '@/utils';
|
||||
|
||||
interface State {
|
||||
menus: any[]
|
||||
play: boolean
|
||||
isPlay: boolean
|
||||
playMusic: SongResult
|
||||
playMusicUrl: string
|
||||
user: any
|
||||
playList: SongResult[]
|
||||
playListIndex: number
|
||||
setData: any
|
||||
menus: any[];
|
||||
play: boolean;
|
||||
isPlay: boolean;
|
||||
playMusic: SongResult;
|
||||
playMusicUrl: string;
|
||||
user: any;
|
||||
playList: SongResult[];
|
||||
playListIndex: number;
|
||||
setData: any;
|
||||
}
|
||||
|
||||
const state: State = {
|
||||
@@ -27,85 +28,79 @@ const state: State = {
|
||||
playList: [],
|
||||
playListIndex: 0,
|
||||
setData: null,
|
||||
}
|
||||
};
|
||||
|
||||
const windowData = window as any
|
||||
const windowData = window as any;
|
||||
|
||||
const musicHistory = useMusicHistory()
|
||||
const musicHistory = useMusicHistory();
|
||||
|
||||
const mutations = {
|
||||
setMenus(state: State, menus: any[]) {
|
||||
state.menus = menus
|
||||
state.menus = menus;
|
||||
},
|
||||
async setPlay(state: State, playMusic: SongResult) {
|
||||
state.playMusic = playMusic
|
||||
state.playMusicUrl = await getSongUrl(playMusic.id)
|
||||
state.play = true
|
||||
musicHistory.addMusic(playMusic)
|
||||
state.playMusic = playMusic;
|
||||
state.playMusicUrl = await getSongUrl(playMusic.id);
|
||||
state.play = true;
|
||||
musicHistory.addMusic(playMusic);
|
||||
},
|
||||
setIsPlay(state: State, isPlay: boolean) {
|
||||
state.isPlay = isPlay
|
||||
state.isPlay = isPlay;
|
||||
},
|
||||
setPlayMusic(state: State, play: boolean) {
|
||||
state.play = play
|
||||
state.play = play;
|
||||
},
|
||||
setPlayList(state: State, playList: SongResult[]) {
|
||||
state.playListIndex = playList.findIndex(
|
||||
(item) => item.id === state.playMusic.id
|
||||
)
|
||||
state.playList = playList
|
||||
state.playListIndex = playList.findIndex((item) => item.id === state.playMusic.id);
|
||||
state.playList = playList;
|
||||
},
|
||||
async nextPlay(state: State) {
|
||||
if (state.playList.length === 0) {
|
||||
state.play = true
|
||||
return
|
||||
state.play = true;
|
||||
return;
|
||||
}
|
||||
state.playListIndex = (state.playListIndex + 1) % state.playList.length
|
||||
await updatePlayMusic(state)
|
||||
state.playListIndex = (state.playListIndex + 1) % state.playList.length;
|
||||
await updatePlayMusic(state);
|
||||
},
|
||||
async prevPlay(state: State) {
|
||||
if (state.playList.length === 0) {
|
||||
state.play = true
|
||||
return
|
||||
state.play = true;
|
||||
return;
|
||||
}
|
||||
state.playListIndex =
|
||||
(state.playListIndex - 1 + state.playList.length) % state.playList.length
|
||||
await updatePlayMusic(state)
|
||||
state.playListIndex = (state.playListIndex - 1 + state.playList.length) % state.playList.length;
|
||||
await updatePlayMusic(state);
|
||||
},
|
||||
async setSetData(state: State, setData: any) {
|
||||
state.setData = setData
|
||||
windowData.electron.ipcRenderer.setStoreValue(
|
||||
'set',
|
||||
JSON.parse(JSON.stringify(setData))
|
||||
)
|
||||
state.setData = setData;
|
||||
windowData.electron.ipcRenderer.setStoreValue('set', JSON.parse(JSON.stringify(setData)));
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
const getSongUrl = async (id: number) => {
|
||||
const { data } = await getMusicUrl(id)
|
||||
let url = ''
|
||||
const { data } = await getMusicUrl(id);
|
||||
let url = '';
|
||||
try {
|
||||
if (data.data[0].freeTrialInfo || !data.data[0].url) {
|
||||
const res = await getParsingMusicUrl(id)
|
||||
url = res.data.data.url
|
||||
const res = await getParsingMusicUrl(id);
|
||||
url = res.data.data.url;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('error', error)
|
||||
console.error('error', error);
|
||||
}
|
||||
url = url ? url : data.data[0].url
|
||||
return getMusicProxyUrl(url)
|
||||
}
|
||||
url = url || data.data[0].url;
|
||||
return getMusicProxyUrl(url);
|
||||
};
|
||||
|
||||
const updatePlayMusic = async (state: State) => {
|
||||
state.playMusic = state.playList[state.playListIndex]
|
||||
state.playMusicUrl = await getSongUrl(state.playMusic.id)
|
||||
state.play = true
|
||||
musicHistory.addMusic(state.playMusic)
|
||||
}
|
||||
state.playMusic = state.playList[state.playListIndex];
|
||||
state.playMusicUrl = await getSongUrl(state.playMusic.id);
|
||||
state.play = true;
|
||||
musicHistory.addMusic(state.playMusic);
|
||||
};
|
||||
|
||||
const store = createStore({
|
||||
state: state,
|
||||
mutations: mutations,
|
||||
})
|
||||
state,
|
||||
mutations,
|
||||
});
|
||||
|
||||
export default store
|
||||
export default store;
|
||||
|
||||
Reference in New Issue
Block a user