This repository was archived by the owner on May 11, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +40
-28
lines changed
Expand file tree Collapse file tree 4 files changed +40
-28
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,22 @@ export const playlistMixin = {
3636
3737export const playerMixin = {
3838 methods : {
39+ toggleIsFavorite ( song ) {
40+ if ( this . isFavoriteSong ( song ) ) {
41+ this . deleteMyFavoriteSong ( song )
42+ } else {
43+ this . saveMyFavoriteSong ( song )
44+ }
45+ } ,
46+
47+ getFavoriteIcon ( song ) {
48+ return this . isFavoriteSong ( song ) ? 'icon-like' : 'icon-not-like'
49+ } ,
50+
51+ isFavoriteSong ( song ) {
52+ return this . myFavoriteSongs . findIndex ( item => item . id === song . id ) > - 1
53+ } ,
54+
3955 togglePlayMode ( ) {
4056 const mode = ( this . mode + 1 ) % 3
4157 this . setPlayMode ( mode )
@@ -68,7 +84,12 @@ export const playerMixin = {
6884 setCurrentIndex : 'SET_CURRENT_INDEX' ,
6985 setPlayMode : 'SET_PLAY_MODE' ,
7086 setPlaylist : 'SET_PLAYLIST'
71- } )
87+ } ) ,
88+
89+ ...mapActions ( [
90+ 'saveMyFavoriteSong' ,
91+ 'deleteMyFavoriteSong'
92+ ] )
7293 } ,
7394
7495 computed : {
@@ -80,7 +101,8 @@ export const playerMixin = {
80101 'playlist' ,
81102 'mode' ,
82103 'sequenceList' ,
83- 'currentSong'
104+ 'currentSong' ,
105+ 'myFavoriteSongs'
84106 ] )
85107 }
86108}
Original file line number Diff line number Diff line change 9898 <i class =" icon-next" @click =" nextSong" ></i >
9999 </div >
100100 <div class =" icon icon-right" >
101- <i :class =" ['icon', hasFavorite ]" @click =" toggleFavorite " ></i >
101+ <i :class =" ['icon', getFavoriteIcon(currentSong) ]" @click =" toggleIsFavorite(currentSong) " ></i >
102102 </div >
103103 </div >
104104 </div >
@@ -174,8 +174,7 @@ export default {
174174 currentLyric: null ,
175175 currentLineNum: 0 ,
176176 currentShow: ' cd' ,
177- playingLyric: ' ' ,
178- hasFavoriteSong: false
177+ playingLyric: ' '
179178 }
180179 },
181180
@@ -215,16 +214,6 @@ export default {
215214 this .setFullScreen (true )
216215 },
217216
218- toggleFavorite () {
219- this .hasFavoriteSong = ! this .hasFavoriteSong
220-
221- if (this .hasFavoriteSong ) {
222- this .saveMyFavoriteSong (this .currentSong )
223- } else {
224- this .deleteMyFavoriteSong (this .currentSong )
225- }
226- },
227-
228217 showPlaylist () {
229218 this .$refs .playlist .showPlaylist ()
230219 },
@@ -460,9 +449,7 @@ export default {
460449 }),
461450
462451 ... mapActions ([
463- ' savePlayedHistory' ,
464- ' saveMyFavoriteSong' ,
465- ' deleteMyFavoriteSong'
452+ ' savePlayedHistory'
466453 ])
467454 },
468455
@@ -501,10 +488,6 @@ export default {
501488 },
502489
503490 computed: {
504- hasFavorite () {
505- return this .hasFavoriteSong ? ' icon-like' : ' icon-not-like'
506- },
507-
508491 rotateCD () {
509492 return this .playing ? ' play' : ' play pause'
510493 },
Original file line number Diff line number Diff line change 3030 >
3131 <i :class =" ['current', getCurrentIcon(song)]" ></i >
3232 <span class =" item-text" >{{ song.name }}</span >
33- <span class =" like-btn" >
34- <i class =" icon-not-like " ></i >
33+ <span class =" like-btn" @click.stop = " toggleIsFavorite(song) " >
34+ <i : class =" getFavoriteIcon(song) " ></i >
3535 </span >
3636 <span class =" delete-btn" @click.stop =" deleteSong(song, index)" >
3737 <i class =" icon-close" ></i >
@@ -262,6 +262,9 @@ export default {
262262 }
263263 .like-btn {
264264 margin-right : 15px ;
265+ .icon-like {
266+ color : $color-sub-theme ;
267+ }
265268 }
266269 }
267270 }
Original file line number Diff line number Diff line change @@ -65,15 +65,19 @@ export default {
6565
6666 methods: {
6767 addAllSongsToList () {
68- if ( this . switchIndex === 0 ) {
68+ let list = []
6969
70+ if (this .switchIndex === 0 ) {
71+ list = this .myFavoriteSongs .map (song => {
72+ return new Song (song)
73+ })
7074 } else {
71- const list = this .playedHistory .map (song => {
75+ list = this .playedHistory .map (song => {
7276 return new Song (song)
7377 })
74-
75- this .randomPlay ({ list })
7678 }
79+
80+ this .randomPlay ({ list })
7781 },
7882
7983 addSongToList (song , index ) {
You can’t perform that action at this time.
0 commit comments