124 lines
2.7 KiB
JavaScript
124 lines
2.7 KiB
JavaScript
import { computed, ref, reactive, nextTick } from '@common/utils/vueTools'
|
|
import musicSdk from '@renderer/utils/musicSdk'
|
|
import { useI18n } from '@renderer/plugins/i18n'
|
|
|
|
export default ({
|
|
props,
|
|
assertApiSupport,
|
|
emit,
|
|
|
|
handleShowDownloadModal,
|
|
handlePlayMusic,
|
|
handlePlayMusicLater,
|
|
handleSearch,
|
|
handleShowMusicAddModal,
|
|
handleOpenMusicDetail,
|
|
}) => {
|
|
const itemMenuControl = reactive({
|
|
play: true,
|
|
addTo: true,
|
|
playLater: true,
|
|
download: true,
|
|
search: true,
|
|
sourceDetail: true,
|
|
})
|
|
const t = useI18n()
|
|
const menuLocation = reactive({ x: 0, y: 0 })
|
|
const isShowItemMenu = ref(false)
|
|
|
|
const menus = computed(() => {
|
|
return [
|
|
{
|
|
name: t('list__play'),
|
|
action: 'play',
|
|
disabled: !itemMenuControl.play,
|
|
},
|
|
{
|
|
name: t('list__download'),
|
|
action: 'download',
|
|
disabled: !itemMenuControl.download,
|
|
},
|
|
{
|
|
name: t('list__play_later'),
|
|
action: 'playLater',
|
|
disabled: !itemMenuControl.playLater,
|
|
},
|
|
{
|
|
name: t('list__search'),
|
|
action: 'search',
|
|
disabled: !itemMenuControl.search,
|
|
},
|
|
{
|
|
name: t('list__add_to'),
|
|
action: 'addTo',
|
|
disabled: !itemMenuControl.addTo,
|
|
},
|
|
{
|
|
name: t('list__source_detail'),
|
|
action: 'sourceDetail',
|
|
disabled: !itemMenuControl.sourceDetail,
|
|
},
|
|
]
|
|
})
|
|
|
|
const showMenu = (event, musicInfo) => {
|
|
itemMenuControl.sourceDetail = !!musicSdk[musicInfo.source].getMusicDetailPageUrl
|
|
// this.listMenu.itemMenuControl.play =
|
|
// this.listMenu.itemMenuControl.playLater =
|
|
itemMenuControl.download = assertApiSupport(musicInfo.source)
|
|
|
|
if (props.checkApiSource) {
|
|
itemMenuControl.playLater =
|
|
itemMenuControl.play =
|
|
itemMenuControl.download
|
|
}
|
|
|
|
menuLocation.x = event.pageX
|
|
menuLocation.y = event.pageY
|
|
|
|
if (isShowItemMenu.value) return
|
|
emit('show-menu')
|
|
nextTick(() => {
|
|
isShowItemMenu.value = true
|
|
})
|
|
}
|
|
|
|
const hideMenu = () => {
|
|
isShowItemMenu.value = false
|
|
}
|
|
|
|
const menuClick = (action, index) => {
|
|
// console.log(action)
|
|
hideMenu()
|
|
if (!action) return
|
|
|
|
switch (action.action) {
|
|
case 'download':
|
|
handleShowDownloadModal(index)
|
|
break
|
|
case 'play':
|
|
handlePlayMusic(index)
|
|
break
|
|
case 'playLater':
|
|
handlePlayMusicLater(index)
|
|
break
|
|
case 'search':
|
|
handleSearch(index)
|
|
break
|
|
case 'addTo':
|
|
handleShowMusicAddModal(index)
|
|
break
|
|
case 'sourceDetail':
|
|
handleOpenMusicDetail(index)
|
|
}
|
|
}
|
|
|
|
return {
|
|
menus,
|
|
menuLocation,
|
|
isShowItemMenu,
|
|
showMenu,
|
|
menuClick,
|
|
}
|
|
}
|