更新 歌曲换源 机制
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
// import { updateListMusicsPosition } from '@renderer/store/list/action'
|
||||
import { ref, nextTick } from '@common/utils/vueTools'
|
||||
import { updateListMusics } from '@renderer/store/list/listManage'
|
||||
import { playList } from '@renderer/core/player'
|
||||
import { getListMusicsFromCache } from '@renderer/store/list/action'
|
||||
import { removeListMusics } from '@renderer/store/list/listManage'
|
||||
import { playListById } from '@renderer/core/player'
|
||||
import { addListMusics, updateListMusicsPosition } from '@renderer/store/list/action'
|
||||
import { playMusicInfo } from '@renderer/store/player/state'
|
||||
import { dialog } from '@renderer/plugins/Dialog'
|
||||
import { useI18n } from '@renderer/plugins/i18n'
|
||||
|
||||
export default (props, list) => {
|
||||
const isShowMusicToggleModal = ref(false)
|
||||
const musicInfo = ref(null)
|
||||
const t = useI18n()
|
||||
|
||||
const handleShowMusicToggleModal = (index) => {
|
||||
musicInfo.value = list.value[index]
|
||||
@@ -16,30 +19,32 @@ export default (props, list) => {
|
||||
})
|
||||
}
|
||||
|
||||
const toggleSource = (toggleMusicInfo) => {
|
||||
const id = musicInfo.value.id
|
||||
const index = list.value.findIndex(m => m.id == id)
|
||||
if (index < 0) {
|
||||
const toggleSource = async(toggleMusicInfo) => {
|
||||
const oldId = musicInfo.value.id
|
||||
let oldIdx = list.value.findIndex(m => m.id == oldId)
|
||||
if (oldIdx < 0) {
|
||||
isShowMusicToggleModal.value = false
|
||||
await addListMusics(props.listId, [toggleMusicInfo])
|
||||
return
|
||||
}
|
||||
musicInfo.value.meta.toggleMusicInfo = toggleMusicInfo
|
||||
updateListMusics([
|
||||
{
|
||||
id: props.listId,
|
||||
musicInfo: {
|
||||
...musicInfo.value,
|
||||
meta: {
|
||||
...musicInfo.value.meta,
|
||||
toggleMusicInfo,
|
||||
},
|
||||
},
|
||||
},
|
||||
])
|
||||
const rawInfo = getListMusicsFromCache(props.listId)[index]
|
||||
rawInfo.meta.toggleMusicInfo = toggleMusicInfo
|
||||
if (toggleMusicInfo || (playMusicInfo.listId == props.listId && playMusicInfo.musicInfo?.id == rawInfo.id)) {
|
||||
playList(props.listId, index)
|
||||
const id = toggleMusicInfo.id
|
||||
const index = list.value.findIndex(m => m.id == id)
|
||||
const removeIds = [oldId]
|
||||
if (index > -1) {
|
||||
if (!await dialog.confirm({
|
||||
message: t('music_toggle_duplicate_tip'),
|
||||
cancelButtonText: t('cancel_button_text'),
|
||||
confirmButtonText: t('confirm_button_text'),
|
||||
})) return
|
||||
removeIds.push(id)
|
||||
}
|
||||
isShowMusicToggleModal.value = false
|
||||
await removeListMusics({ listId: props.listId, ids: removeIds })
|
||||
await addListMusics(props.listId, [toggleMusicInfo], 'bottom')
|
||||
if (index != -1 && index < oldIdx) oldIdx--
|
||||
await updateListMusicsPosition({ listId: props.listId, ids: [id], position: oldIdx })
|
||||
if (playMusicInfo.listId == props.listId && playMusicInfo.musicInfo?.id == oldId) {
|
||||
playListById(props.listId, toggleMusicInfo.id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user