Skip to content

Commit

Permalink
fix: 搜索加入歌曲逻辑优化
Browse files Browse the repository at this point in the history
  • Loading branch information
sl1673495 committed Jul 30, 2019
1 parent 49166cb commit 282d721
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/components/search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default {
}
},
methods: {
onInput: debounce(function(value) {
onInput: debounce(function (value) {
if (!value.trim()) {
return
}
Expand Down Expand Up @@ -153,15 +153,15 @@ export default {
img: picUrl
})
this.startSong(song)
this.setPlaylist({ data: [song] })
this.addToPlaylist(song)
},
onClickPlaylist(item) {
const { id } = item
this.$router.push(`/playlist/${id}`)
this.searchPanelShow = false
},
...mapMutations(["setPlaylist"]),
...mapActions(["startSong"])
...mapActions(["startSong", 'addToPlaylist'])
},
computed: {
suggestShow() {
Expand Down
6 changes: 4 additions & 2 deletions src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export default {
addToPlaylist({ commit, state }, song) {
const { playlist } = state
const copy = playlist.slice()
copy.unshift(song)
commit('setPlaylist', { data: copy })
if (!copy.find(({ id }) => id === song.id)) {
copy.unshift(song)
commit('setPlaylist', { data: copy })
}
}
}

0 comments on commit 282d721

Please sign in to comment.