播放列表增加localStorage本地缓存
This commit is contained in:
1 parent
efac22e672
commit
85e43baf63
3 files changed
+40
-13
No files matched your search
+1
-1
@@ -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 = '';
|
||||
|
||||
+33
-8
@@ -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;
|
||||
});
|
||||
|
||||
|
||||
@@ -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 }
|
||||
Reference in new issue
Block a user