koel/resources/assets/js/components/shared/home-song-item.vue

168 lines
3.3 KiB
Vue
Raw Normal View History

<template>
2016-06-25 16:05:24 +00:00
<li class="song-item-home"
:class="{ playing: song.playbackState === 'playing' || song.playbackState === 'paused' }"
@dblclick.prevent="play"
>
<span class="cover" :style="{ backgroundImage: 'url('+song.album.cover+')' }">
2016-06-25 16:05:24 +00:00
<a class="control" @click.prevent="changeSongState">
<i class="fa fa-play" v-if="song.playbackState !== 'playing'"></i>
<i class="fa fa-pause" v-else></i>
</a>
</span>
<span class="details">
<span v-if="showPlayCount" :style="{ width: song.playCount*100/topPlayCount+'%' }" class="play-count"/>
2016-06-25 16:05:24 +00:00
{{ song.title }}
<span class="by">
<a :href="'/#!/artist/'+song.artist.id">{{ song.artist.name }}</a>
2016-10-31 04:28:12 +00:00
<template v-if="showPlayCount">- {{ song.playCount | pluralize('play') }}</template>
2016-06-25 16:05:24 +00:00
</span>
</span>
</li>
</template>
<script>
2016-11-26 03:25:35 +00:00
import { pluralize } from '../../utils'
import { queueStore } from '../../stores'
import { playback } from '../../services'
2016-06-25 16:05:24 +00:00
export default {
name: 'shared--home-song-item',
props: ['song', 'topPlayCount'],
filters: { pluralize },
computed: {
2016-11-26 03:25:35 +00:00
showPlayCount () {
return this.topPlayCount && this.song.playCount
}
},
2016-06-25 16:05:24 +00:00
methods: {
2016-11-26 03:25:35 +00:00
play () {
2016-06-25 16:05:24 +00:00
if (!queueStore.contains(this.song)) {
2016-11-26 03:25:35 +00:00
queueStore.queueAfterCurrent(this.song)
2016-06-25 16:05:24 +00:00
}
2016-11-26 03:25:35 +00:00
playback.play(this.song)
2016-06-25 16:05:24 +00:00
},
2016-11-26 03:25:35 +00:00
changeSongState () {
2016-06-25 16:05:24 +00:00
if (this.song.playbackState === 'stopped') {
2016-11-26 03:25:35 +00:00
this.play(this.song)
2016-06-25 16:05:24 +00:00
} else if (this.song.playbackState === 'paused') {
2016-11-26 03:25:35 +00:00
playback.resume()
2016-06-25 16:05:24 +00:00
} else {
2016-11-26 03:25:35 +00:00
playback.pause()
2016-06-25 16:05:24 +00:00
}
2016-11-26 03:25:35 +00:00
}
}
}
</script>
<style lang="sass" scoped>
2016-06-25 16:05:24 +00:00
@import "../../../sass/partials/_vars.scss";
@import "../../../sass/partials/_mixins.scss";
2016-06-25 16:05:24 +00:00
.song-item-home {
display: flex;
2016-06-25 16:05:24 +00:00
&.playing {
color: $colorHighlight;
}
2016-06-25 16:05:24 +00:00
&:hover .cover {
.control {
display: block;
}
2016-06-25 16:05:24 +00:00
&::before {
opacity: .7;
}
}
.cover {
flex: 0 0 48px;
height: 48px;
background-size: cover;
position: relative;
@include vertical-center();
&::before {
content: " ";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
background: #000;
opacity: 0;
html.touchevents & {
opacity: .7;
}
}
2016-06-25 16:05:24 +00:00
.control {
border-radius: 50%;
width: 28px;
height: 28px;
background: rgba(0, 0, 0, .7);
border: 1px solid transparent;
line-height: 2rem;
font-size: 1rem;
text-align: center;
z-index: 1;
display: none;
color: #fff;
transition: .3s;
&:hover {
transform: scale(1.2);
border-color: #fff;
}
html.touchevents & {
display: block;
}
}
}
.details {
flex: 1;
padding: 4px 8px;
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
.play-count {
background: rgba(255, 255, 255, 0.08);
position: absolute;
height: 100%;
top: 0;
left: 0;
pointer-events: none;
}
2016-06-25 16:05:24 +00:00
.by {
display: block;
font-size: .9rem;
margin-top: 2px;
color: $color2ndText;
opacity: .8;
2016-06-25 16:05:24 +00:00
a {
color: #fff;
&:hover {
color: $colorHighlight;
}
}
}
2016-06-25 16:05:24 +00:00
}
margin-bottom: 8px;
}
</style>