Skip to content

Commit

Permalink
fix: 未播放歌曲请求封面导致undefined请求
Browse files Browse the repository at this point in the history
  • Loading branch information
sl1673495 committed Mar 3, 2020
1 parent 2787cae commit 60935fb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "3.3.0",
"private": true,
"scripts": {
"dev": "concurrently \"npm run serve\" \"cd node_modules/NeteaseCloudMusicApi && node app.js\"",
"dev": "npm run serve",
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"publish": "npm run build && cd music && now",
Expand Down Expand Up @@ -36,7 +36,6 @@
"@vue/cli-plugin-babel": "^3.9.0",
"@vue/cli-plugin-eslint": "^3.9.0",
"@vue/cli-service": "^3.9.0",
"NeteaseCloudMusicApi": "git+https://github.com/Binaryify/NeteaseCloudMusicApi.git",
"babel-eslint": "^10.0.1",
"babel-plugin-component": "^1.1.1",
"commitizen": "^4.0.3",
Expand Down
1 change: 1 addition & 0 deletions src/components/mini-player.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export default {
},
onProgressChange(percent) {
this.audio.currentTime = this.currentSong.durationSecond * percent
this.setPlayingState(true)
},
onVolumeChange(percent) {
this.audio.volume = percent
Expand Down
6 changes: 4 additions & 2 deletions src/components/player.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template >
<transition name="slide">
<div
v-if="hasCurrentSong"
:class="getPlayerShowCls()"
class="player"
>
Expand Down Expand Up @@ -153,7 +154,7 @@ import { getLyric, getSimiSongs, getSimiPlaylists } from "@/api"
import lyricParser from "@/utils/lrcparse"
import { debounce, isDef, createSong, goMvWithCheck } from "@/utils"
import Comments from "@/components/comments"
import { mapState, mapMutations, mapActions } from "@/store/helper/music"
import { mapState, mapMutations, mapActions, mapGetters } from "@/store/helper/music"
const WHEEL_TYPE = "wheel"
const SCROLL_TYPE = "scroll"
Expand Down Expand Up @@ -331,7 +332,8 @@ export default {
}
return ret
},
...mapState(["currentSong", "currentTime", "playing", "isPlayerShow"])
...mapState(["currentSong", "currentTime", "playing", "isPlayerShow"]),
...mapGetters(["hasCurrentSong"])
},
watch: {
isPlayerShow(show) {
Expand Down
7 changes: 7 additions & 0 deletions src/store/modules/music/getters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { playModeMap } from '@/utils/config'
import { isDef } from '../../../utils'

export const currentIndex = (state) => {
const { currentSong, playlist } = state
Expand Down Expand Up @@ -37,6 +38,7 @@ export const nextSong = (state, getters) => {
}
}

// 上一首歌
export const prevSong = (state, getters) => {
const { playlist, playMode } = state
const prevStratMap = {
Expand Down Expand Up @@ -66,6 +68,11 @@ export const prevSong = (state, getters) => {
}
}

// 当前是否有歌曲在播放
export const hasCurrentSong = (state) => {
return isDef(state.currentSong.id)
}

function getRandomIndex(playlist, currentIndex) {
// 防止无限循环
if (playlist.length === 1) {
Expand Down
3 changes: 1 addition & 2 deletions src/utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,4 @@ export function scrollInto(dom) {
dom.scrollIntoView({ behavior: "smooth" })
}

export const EMPTY_IMG =
"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
export const EMPTY_IMG = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"

0 comments on commit 60935fb

Please sign in to comment.