diff --git a/src/App.js b/src/App.js index fbaaa21..dac9d5f 100644 --- a/src/App.js +++ b/src/App.js @@ -26,7 +26,7 @@ class App extends Component { } componentDidUpdate() { - console.log(DataStore.errMassge); + //console.log(DataStore.errMassge); if(DataStore.errMassge) { dialog.piece(DataStore.errMassge, 3000); DataStore.errMassge = ''; diff --git a/src/DataStore.js b/src/DataStore.js index 4302fbb..25da4a7 100644 --- a/src/DataStore.js +++ b/src/DataStore.js @@ -11,7 +11,7 @@ class DataPageStore { @observable _searchSongList = []; - @observable _playSongList = []; + @observable _playSongList = this.getLocalStore() || []; @observable _count = 0; @@ -76,11 +76,12 @@ class DataPageStore { set playSongList(value) { this._playSongList = value; - if(this.playSongList.length === 1) { + if(this._playSongList.length === 1) { this.loop = true; }else{ this.loop = false; } + this.setLocalStore(this._playSongList); } get count() { @@ -241,8 +242,27 @@ class DataPageStore { return this.windowHeight - 200; } + setLocalStore(data) { + let storage = localStorage || window.localStorage; + if(storage) { + storage.setItem('playList', JSON.stringify(data)); + //console.log(storage.getItem('playList')); + } + } + + getLocalStore() { + let data = null; + let storage = localStorage || window.localStorage; + if(storage) { + data = JSON.parse(storage.getItem('playList')); + } + return data; + } + addPlaySongList(value) { - this.playSongList.push(value); + let tempList = this.playSongList; + tempList.push(value); + this.playSongList = tempList; if(this.playSongList.length === 1) { this.loop = true; @@ -252,8 +272,8 @@ class DataPageStore { } get coutSongMassge() { - if(this._playSongList.length > 0) { - return this._playSongList[this._count]; + if(this.playSongList.length > 0) { + return this.playSongList[this._count]; }else{ return { SongName: '未知歌曲', @@ -376,15 +396,20 @@ class DataPageStore { } findInPlayList(hash) { - return this.playSongList.findIndex((item, index, arr) => { + let tempList = this.playSongList; + tempList.findIndex((item, index, arr) => { + return hash === item.Hash; + }) + this.playSongList = tempList; + return tempList.findIndex((item, index, arr) => { return hash === item.Hash; }) } removeInSongList(hash) { let curHash = this.coutSongMassge.Hash; - - this.playSongList = this.playSongList.filter((item, index, arr) => { + let tempList = this.playSongList; + this.playSongList = tempList.filter((item, index, arr) => { return hash !== item.Hash; }); diff --git a/src/datasrc/Netease.js b/src/datasrc/Netease.js index e249077..1abd8e8 100644 --- a/src/datasrc/Netease.js +++ b/src/datasrc/Netease.js @@ -121,6 +121,8 @@ let getNeteaseSongMassge = async function(hash) { } if(!songMassge.PlayUrl) { return Promise.reject('该歌曲已经下架!'); + }else{ + songMassge.PlayUrl = getPlayUrl(hash); } } catch(err) { console.error(err); @@ -139,9 +141,9 @@ let singersName = function(arr) { return singers; } -// let getPlayUrl = function(id) { -// let playUrl = 'http://music.163.com/song/media/outer/url?id=' + id + '.mp3'; -// return playUrl; -// } +let getPlayUrl = function(id) { + let playUrl = 'http://music.163.com/song/media/outer/url?id=' + id + '.mp3'; + return playUrl; +} export { getNeteaseHotSongList, getNeteaseSongMassge, getNeteaseSearchSongList } \ No newline at end of file