播放列表增加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() {
|
componentDidUpdate() {
|
||||||
console.log(DataStore.errMassge);
|
//console.log(DataStore.errMassge);
|
||||||
if(DataStore.errMassge) {
|
if(DataStore.errMassge) {
|
||||||
dialog.piece(DataStore.errMassge, 3000);
|
dialog.piece(DataStore.errMassge, 3000);
|
||||||
DataStore.errMassge = '';
|
DataStore.errMassge = '';
|
||||||
|
|||||||
+33
-8
@@ -11,7 +11,7 @@ class DataPageStore {
|
|||||||
|
|
||||||
@observable _searchSongList = [];
|
@observable _searchSongList = [];
|
||||||
|
|
||||||
@observable _playSongList = [];
|
@observable _playSongList = this.getLocalStore() || [];
|
||||||
|
|
||||||
@observable _count = 0;
|
@observable _count = 0;
|
||||||
|
|
||||||
@@ -76,11 +76,12 @@ class DataPageStore {
|
|||||||
|
|
||||||
set playSongList(value) {
|
set playSongList(value) {
|
||||||
this._playSongList = value;
|
this._playSongList = value;
|
||||||
if(this.playSongList.length === 1) {
|
if(this._playSongList.length === 1) {
|
||||||
this.loop = true;
|
this.loop = true;
|
||||||
}else{
|
}else{
|
||||||
this.loop = false;
|
this.loop = false;
|
||||||
}
|
}
|
||||||
|
this.setLocalStore(this._playSongList);
|
||||||
}
|
}
|
||||||
|
|
||||||
get count() {
|
get count() {
|
||||||
@@ -241,8 +242,27 @@ class DataPageStore {
|
|||||||
return this.windowHeight - 200;
|
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) {
|
addPlaySongList(value) {
|
||||||
this.playSongList.push(value);
|
let tempList = this.playSongList;
|
||||||
|
tempList.push(value);
|
||||||
|
this.playSongList = tempList;
|
||||||
|
|
||||||
if(this.playSongList.length === 1) {
|
if(this.playSongList.length === 1) {
|
||||||
this.loop = true;
|
this.loop = true;
|
||||||
@@ -252,8 +272,8 @@ class DataPageStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get coutSongMassge() {
|
get coutSongMassge() {
|
||||||
if(this._playSongList.length > 0) {
|
if(this.playSongList.length > 0) {
|
||||||
return this._playSongList[this._count];
|
return this.playSongList[this._count];
|
||||||
}else{
|
}else{
|
||||||
return {
|
return {
|
||||||
SongName: '未知歌曲',
|
SongName: '未知歌曲',
|
||||||
@@ -376,15 +396,20 @@ class DataPageStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
findInPlayList(hash) {
|
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;
|
return hash === item.Hash;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
removeInSongList(hash) {
|
removeInSongList(hash) {
|
||||||
let curHash = this.coutSongMassge.Hash;
|
let curHash = this.coutSongMassge.Hash;
|
||||||
|
let tempList = this.playSongList;
|
||||||
this.playSongList = this.playSongList.filter((item, index, arr) => {
|
this.playSongList = tempList.filter((item, index, arr) => {
|
||||||
return hash !== item.Hash;
|
return hash !== item.Hash;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -121,6 +121,8 @@ let getNeteaseSongMassge = async function(hash) {
|
|||||||
}
|
}
|
||||||
if(!songMassge.PlayUrl) {
|
if(!songMassge.PlayUrl) {
|
||||||
return Promise.reject('该歌曲已经下架!');
|
return Promise.reject('该歌曲已经下架!');
|
||||||
|
}else{
|
||||||
|
songMassge.PlayUrl = getPlayUrl(hash);
|
||||||
}
|
}
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@@ -139,9 +141,9 @@ let singersName = function(arr) {
|
|||||||
return singers;
|
return singers;
|
||||||
}
|
}
|
||||||
|
|
||||||
// let getPlayUrl = function(id) {
|
let getPlayUrl = function(id) {
|
||||||
// let playUrl = 'http://music.163.com/song/media/outer/url?id=' + id + '.mp3';
|
let playUrl = 'http://music.163.com/song/media/outer/url?id=' + id + '.mp3';
|
||||||
// return playUrl;
|
return playUrl;
|
||||||
// }
|
}
|
||||||
|
|
||||||
export { getNeteaseHotSongList, getNeteaseSongMassge, getNeteaseSearchSongList }
|
export { getNeteaseHotSongList, getNeteaseSongMassge, getNeteaseSearchSongList }
|
||||||
Reference in new issue
Block a user