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

182 lines
3.9 KiB
Vue
Raw Normal View History

2015-12-13 04:42:28 +00:00
<template>
2016-06-25 16:05:24 +00:00
<tr
class="song-item"
draggable="true"
:data-song-id="song.id"
2017-01-14 13:09:38 +00:00
@click="clicked"
2016-06-25 16:05:24 +00:00
@dblclick.prevent="playRightAwayyyyyyy"
2017-01-14 13:09:38 +00:00
@dragstart="dragStart"
2017-01-14 13:55:27 +00:00
@dragleave="dragLeave"
2017-01-17 08:19:00 +00:00
@dragenter.prevent="dragEnter"
@dragover.prevent
2017-01-17 07:02:19 +00:00
@drop.stop.prevent="drop"
2017-01-14 13:55:27 +00:00
@contextmenu.prevent="contextMenu"
2017-01-14 13:09:38 +00:00
:class="{ selected: item.selected, playing: playing }"
2016-06-25 16:05:24 +00:00
>
<td class="track-number">{{ song.track || '' }}</td>
<td class="title">{{ song.title }}</td>
<td class="artist">{{ song.artist.name }}</td>
<td class="album">{{ song.album.name }}</td>
2016-09-10 07:41:44 +00:00
<td class="time">{{ song.fmtLength }}</td>
2016-06-25 16:05:24 +00:00
<td class="play" @click.stop="doPlayback">
2016-10-31 04:28:12 +00:00
<i class="fa fa-pause-circle" v-if="song.playbackState === 'playing'"/>
<i class="fa fa-play-circle" v-else/>
2016-06-25 16:05:24 +00:00
</td>
</tr>
2015-12-13 04:42:28 +00:00
</template>
<script>
2016-11-26 03:25:35 +00:00
import { playback } from '../../services'
import { queueStore } from '../../stores'
2017-01-14 13:09:38 +00:00
import $v from 'vuequery'
2016-06-25 16:05:24 +00:00
export default {
2017-01-14 13:09:38 +00:00
props: ['item'],
name: 'song-item',
2016-06-25 16:05:24 +00:00
2016-11-26 03:25:35 +00:00
data () {
2016-06-25 16:05:24 +00:00
return {
2017-01-14 13:09:38 +00:00
parentSongList: null
2016-11-26 03:25:35 +00:00
}
2016-06-25 16:05:24 +00:00
},
2016-11-15 07:54:41 +00:00
computed: {
2017-01-14 13:09:38 +00:00
/**
* A shortcut to access the current vm's song (instead of this.item.song).
* @return {Object}
*/
song () {
return this.item.song
},
2017-01-14 13:55:27 +00:00
/**
* Determine if the current song is being played (or paused).
* @return {Bool}
*/
2016-11-26 03:25:35 +00:00
playing () {
return this.song.playbackState === 'playing' || this.song.playbackState === 'paused'
}
2016-11-15 07:54:41 +00:00
},
2017-01-14 13:09:38 +00:00
created () {
this.parentSongList = $v(this).closest('song-list').vm
},
2016-06-25 16:05:24 +00:00
methods: {
2017-01-17 08:19:00 +00:00
noop () {},
2016-06-25 16:05:24 +00:00
/**
* Play the song right away.
*/
2016-11-26 03:25:35 +00:00
playRightAwayyyyyyy () {
2017-01-17 07:02:19 +00:00
queueStore.contains(this.song) || queueStore.queueAfterCurrent(this.song)
2016-11-26 03:25:35 +00:00
playback.play(this.song)
2016-06-25 16:05:24 +00:00
},
/**
* Take the right playback action based on the current playback state.
*/
2016-11-26 03:25:35 +00:00
doPlayback () {
2016-06-25 16:05:24 +00:00
switch (this.song.playbackState) {
case 'playing':
2016-11-26 03:25:35 +00:00
playback.pause()
break
2016-06-25 16:05:24 +00:00
case 'paused':
2016-11-26 03:25:35 +00:00
playback.resume()
break
2016-06-25 16:05:24 +00:00
default:
2016-11-26 03:25:35 +00:00
this.playRightAwayyyyyyy()
break
2016-06-25 16:05:24 +00:00
}
},
2017-01-14 13:55:27 +00:00
/**
* Proxy the click event to the parent song list component.
* @param {Event} event
*/
2017-01-14 13:09:38 +00:00
clicked (event) {
this.parentSongList.rowClicked(this, event)
2016-06-25 16:05:24 +00:00
},
2017-01-14 13:55:27 +00:00
/**
* Proxy the dragstart event to the parent song list component.
* @param {Event} event
*/
2017-01-14 13:09:38 +00:00
dragStart (event) {
this.parentSongList.dragStart(this, event)
2016-06-25 16:05:24 +00:00
},
2017-01-14 13:55:27 +00:00
/**
* Proxy the dragleave event to the parent song list component.
* @param {Event} event
*/
dragLeave (event) {
2017-01-14 13:09:38 +00:00
this.parentSongList.removeDroppableState(event)
2016-06-25 16:05:24 +00:00
},
2016-11-15 07:54:41 +00:00
/**
2017-01-14 13:55:27 +00:00
* Proxy the dragover event to the parent song list component.
* @param {Event} event The dragover event.
2016-11-15 07:54:41 +00:00
*/
2017-01-17 08:19:00 +00:00
dragEnter (event) {
2017-01-14 13:09:38 +00:00
this.parentSongList.allowDrop(event)
},
2017-01-14 13:55:27 +00:00
/**
* Proxy the dropstop event to the parent song list component.
* @param {Event} event
*/
2017-01-17 07:02:19 +00:00
drop (event) {
2017-01-14 13:09:38 +00:00
this.parentSongList.handleDrop(this, event)
},
2017-01-14 13:55:27 +00:00
/**
* Proxy the contextmenu event to the parent song list component.
* @param {Event} event
*/
contextMenu (event) {
2017-01-14 13:09:38 +00:00
this.parentSongList.openContextMenu(this, event)
2016-11-26 03:25:35 +00:00
}
}
}
2015-12-13 04:42:28 +00:00
</script>
2017-02-14 06:53:02 +00:00
<style lang="scss">
2016-06-25 16:05:24 +00:00
@import "../../../sass/partials/_vars.scss";
@import "../../../sass/partials/_mixins.scss";
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
.song-item {
border-bottom: 1px solid $color2ndBgr;
2017-01-14 13:09:38 +00:00
height: 35px;
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
html.no-touchevents &:hover {
background: rgba(255, 255, 255, .05);
}
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
.time, .track-number {
color: $color2ndText;
}
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
.title {
min-width: 192px;
}
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
.play {
max-width: 32px;
opacity: .5;
2016-01-07 04:22:02 +00:00
2016-06-25 16:05:24 +00:00
i {
font-size: 1.5rem;
}
}
2016-01-06 16:41:59 +00:00
2016-06-25 16:05:24 +00:00
&.selected {
background-color: rgba(255, 255, 255, .08);
}
2015-12-13 04:42:28 +00:00
&.playing td {
2016-06-25 16:05:24 +00:00
color: $colorHighlight;
}
}
2015-12-13 04:42:28 +00:00
</style>