This commit is contained in:
lyswhut
2022-10-29 11:36:35 +08:00
parent 66b965d9f7
commit e45cee6596
715 changed files with 57096 additions and 31771 deletions
@@ -1,66 +0,0 @@
import { useAction, useCommit } from '@renderer/utils/vueTools'
import { tempList } from '@renderer/core/share/list'
const getListPlayIndex = (list, index) => {
if (index == null) {
index = 1
} else {
index = parseInt(index)
if (Number.isNaN(index)) {
index = 1
} else {
if (index < 1) index = 1
else if (index > list.length) index = list.length
}
}
return index - 1
}
export default () => {
const getListDetail = useAction('songList', 'getListDetail')
const getListDetailAll = useAction('songList', 'getListDetailAll')
const setTempList = useCommit('player', 'setTempList')
const updateTempList = useCommit('player', 'updateTempList')
const playSongListDetail = async(source, link, playIndex) => {
console.log(source, link, playIndex)
if (link == null) return
let isPlayingList = false
const id = decodeURIComponent(link)
const playListId = `${source}__${decodeURIComponent(link)}`
let list
try {
list = await getListDetail({ source, id, page: 1 })
} catch (err) {
console.log(err)
}
if (list.length > playIndex) {
isPlayingList = true
setTempList({
list,
index: getListPlayIndex(list, playIndex),
id: playListId,
})
}
getListDetailAll({ source, id }).then(list => {
if (isPlayingList) {
if (tempList.meta.id == id) {
updateTempList({
list,
id: playListId,
})
}
} else {
setTempList({
list,
index: getListPlayIndex(list, playIndex),
id: playListId,
})
}
})
}
return (source, link, playIndex) => {
playSongListDetail(source, link, playIndex)
}
}
@@ -0,0 +1,46 @@
import { playList } from '@renderer/core/player'
import { setTempList } from '@renderer/store/list/action'
import { tempList, tempListMeta } from '@renderer/store/list/state'
import { getListDetail, getListDetailAll } from '@renderer/store/songList/action'
const getListPlayIndex = (list: LX.Music.MusicInfoOnline[], index?: number) => {
if (index == null) {
index = 1
} else {
if (index < 1) index = 1
else if (index > list.length) index = list.length
}
return index - 1
}
export default () => {
const playSongListDetail = async(source: LX.OnlineSource, link: string, playIndex?: number) => {
// console.log(source, link, playIndex)
if (link == null) return
let isPlayingList = false
const id = decodeURIComponent(link)
const playListId = `${source}__${decodeURIComponent(link)}`
let list = (await getListDetail(id, source, 1)).list
if (playIndex != null && list.length > playIndex) {
isPlayingList = true
await setTempList(playListId, list)
playList(tempList.id, getListPlayIndex(list, playIndex))
}
list = await getListDetailAll(id, source)
if (isPlayingList) {
if (tempListMeta.id == id) await setTempList(playListId, list)
} else {
await setTempList(playListId, list)
playList(tempList.id, getListPlayIndex(list, playIndex))
}
}
return async(source: LX.OnlineSource, link: string, playIndex?: number) => {
try {
await playSongListDetail(source, link, playIndex)
} catch (err) {
console.error(err)
throw new Error('Get play list failed.')
}
}
}