mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-25 08:47:22 +08:00
🐞 fix: 类型问题修复
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
// musicHistoryHooks
|
// musicHistoryHooks
|
||||||
import { useLocalStorage } from '@vueuse/core';
|
import { useLocalStorage } from '@vueuse/core';
|
||||||
|
|
||||||
import type { Song } from '@/type/music';
|
import type { SongResult } from '@/type/music';
|
||||||
|
|
||||||
export const useMusicHistory = () => {
|
export const useMusicHistory = () => {
|
||||||
const musicHistory = useLocalStorage<Song[]>('musicHistory', []);
|
const musicHistory = useLocalStorage<SongResult[]>('musicHistory', []);
|
||||||
|
|
||||||
const addMusic = (music: Song) => {
|
const addMusic = (music: SongResult) => {
|
||||||
const index = musicHistory.value.findIndex((item) => item.id === music.id);
|
const index = musicHistory.value.findIndex((item) => item.id === music.id);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
musicHistory.value[index].count = (musicHistory.value[index].count || 0) + 1;
|
musicHistory.value[index].count = (musicHistory.value[index].count || 0) + 1;
|
||||||
@@ -16,7 +16,7 @@ export const useMusicHistory = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const delMusic = (music: Song) => {
|
const delMusic = (music: SongResult) => {
|
||||||
const index = musicHistory.value.findIndex((item) => item.id === music.id);
|
const index = musicHistory.value.findIndex((item) => item.id === music.id);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
musicHistory.value.splice(index, 1);
|
musicHistory.value.splice(index, 1);
|
||||||
|
|||||||
+6
-6
@@ -3,17 +3,17 @@ import { createStore } from 'vuex';
|
|||||||
import { getMusicUrl, getParsingMusicUrl } from '@/api/music';
|
import { getMusicUrl, getParsingMusicUrl } from '@/api/music';
|
||||||
import { useMusicHistory } from '@/hooks/MusicHistoryHook';
|
import { useMusicHistory } from '@/hooks/MusicHistoryHook';
|
||||||
import homeRouter from '@/router/home';
|
import homeRouter from '@/router/home';
|
||||||
import type { Song } from '@/type/music';
|
import type { SongResult } from '@/type/music';
|
||||||
import { getMusicProxyUrl } from '@/utils';
|
import { getMusicProxyUrl } from '@/utils';
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
menus: any[];
|
menus: any[];
|
||||||
play: boolean;
|
play: boolean;
|
||||||
isPlay: boolean;
|
isPlay: boolean;
|
||||||
playMusic: Song;
|
playMusic: SongResult;
|
||||||
playMusicUrl: string;
|
playMusicUrl: string;
|
||||||
user: any;
|
user: any;
|
||||||
playList: Song[];
|
playList: SongResult[];
|
||||||
playListIndex: number;
|
playListIndex: number;
|
||||||
setData: any;
|
setData: any;
|
||||||
lyric: any;
|
lyric: any;
|
||||||
@@ -26,7 +26,7 @@ const state: State = {
|
|||||||
menus: homeRouter,
|
menus: homeRouter,
|
||||||
play: false,
|
play: false,
|
||||||
isPlay: false,
|
isPlay: false,
|
||||||
playMusic: {} as Song,
|
playMusic: {} as SongResult,
|
||||||
playMusicUrl: '',
|
playMusicUrl: '',
|
||||||
user: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user') as string) : null,
|
user: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user') as string) : null,
|
||||||
playList: [],
|
playList: [],
|
||||||
@@ -46,7 +46,7 @@ const mutations = {
|
|||||||
setMenus(state: State, menus: any[]) {
|
setMenus(state: State, menus: any[]) {
|
||||||
state.menus = menus;
|
state.menus = menus;
|
||||||
},
|
},
|
||||||
async setPlay(state: State, playMusic: Song) {
|
async setPlay(state: State, playMusic: SongResult) {
|
||||||
state.playMusic = { ...playMusic, playLoading: true };
|
state.playMusic = { ...playMusic, playLoading: true };
|
||||||
state.playMusicUrl = await getSongUrl(playMusic.id);
|
state.playMusicUrl = await getSongUrl(playMusic.id);
|
||||||
state.play = true;
|
state.play = true;
|
||||||
@@ -59,7 +59,7 @@ const mutations = {
|
|||||||
setPlayMusic(state: State, play: boolean) {
|
setPlayMusic(state: State, play: boolean) {
|
||||||
state.play = play;
|
state.play = play;
|
||||||
},
|
},
|
||||||
setPlayList(state: State, playList: Song[]) {
|
setPlayList(state: State, playList: SongResult[]) {
|
||||||
state.playListIndex = playList.findIndex((item) => item.id === state.playMusic.id);
|
state.playListIndex = playList.findIndex((item) => item.id === state.playMusic.id);
|
||||||
state.playList = playList;
|
state.playList = playList;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user