升级到 vue3
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import music from '../utils/music'
|
||||
import { themes, windowSizeList } from '@renderer/core/share'
|
||||
|
||||
export default {
|
||||
theme(state) {
|
||||
let theme = state.themes.find(theme => theme.id == state.setting.themeId)
|
||||
return (theme && theme.class) || ''
|
||||
let theme = themes.find(theme => theme.id == state.setting.themeId)
|
||||
return (theme && theme.className) || ''
|
||||
},
|
||||
themes(state) {
|
||||
return {
|
||||
active: state.setting.themeId,
|
||||
list: state.themes,
|
||||
list: themes,
|
||||
}
|
||||
},
|
||||
source(state) {
|
||||
@@ -22,7 +23,7 @@ export default {
|
||||
}
|
||||
},
|
||||
sourceNames(state) {
|
||||
let prefix = 'store.state.source_'
|
||||
let prefix = 'source_'
|
||||
if (state.setting.sourceNameType == 'alias') prefix += 'alias_'
|
||||
const sources = {}
|
||||
for (const source of music.sources) {
|
||||
@@ -46,10 +47,16 @@ export default {
|
||||
route(state) {
|
||||
return state.route
|
||||
},
|
||||
windowSizeList(state) {
|
||||
return state.windowSizeList
|
||||
windowSizeList() {
|
||||
return windowSizeList
|
||||
},
|
||||
windowSizeActive(state) {
|
||||
return state.windowSizeList.find(i => i.id === state.setting.windowSizeId) || state.windowSizeList[0]
|
||||
return windowSizeList.find(i => i.id === state.setting.windowSizeId) || windowSizeList[0]
|
||||
},
|
||||
versionModalVisible(state) {
|
||||
return state.version.showModal
|
||||
},
|
||||
pactModalVisible(state) {
|
||||
return !state.setting.isAgreePact
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import { createStore } from 'vuex'
|
||||
// import { createPersistedState, createSharedMutations } from 'vuex-electron'
|
||||
|
||||
import defaultState from './state'
|
||||
@@ -8,11 +7,9 @@ import modules from './modules'
|
||||
import getters from './getters'
|
||||
import actions from './actions'
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development'
|
||||
|
||||
const store = new Vuex.Store({
|
||||
const store = createStore({
|
||||
strict: isDev,
|
||||
state: defaultState,
|
||||
modules,
|
||||
|
||||
@@ -14,21 +14,23 @@ import {
|
||||
filterFileName,
|
||||
} from '../../utils'
|
||||
import { NAMES, rendererInvoke } from '@common/ipc'
|
||||
import { initDownloadList, downloadList, downloadListMap, downloadStatus } from '@renderer/core/share/download'
|
||||
import { markRaw } from '@renderer/utils/vueTools'
|
||||
import { download as eventDownloadNames } from '@renderer/event/names'
|
||||
|
||||
window.downloadList = []
|
||||
window.downloadListFull = []
|
||||
window.downloadListFullMap = new Map()
|
||||
// state
|
||||
const state = {
|
||||
list: window.downloadList,
|
||||
waitingList: [],
|
||||
downloadStatus: {
|
||||
RUN: 'run',
|
||||
WAITING: 'waiting',
|
||||
PAUSE: 'pause',
|
||||
ERROR: 'error',
|
||||
COMPLETED: 'completed',
|
||||
},
|
||||
// list: window.downloadList,
|
||||
// downloadStatus: {
|
||||
// RUN: 'run',
|
||||
// WAITING: 'waiting',
|
||||
// PAUSE: 'pause',
|
||||
// ERROR: 'error',
|
||||
// COMPLETED: 'completed',
|
||||
// },
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +40,8 @@ const tryNum = {}
|
||||
|
||||
// getters
|
||||
const getters = {
|
||||
list: state => state.list || [],
|
||||
downloadStatus: state => state.downloadStatus,
|
||||
// list: state => downloadList || [],
|
||||
// downloadStatus: state => downloadStatus,
|
||||
}
|
||||
|
||||
const checkPath = path => new Promise((resolve, reject) => {
|
||||
@@ -73,7 +75,7 @@ const getExt = type => {
|
||||
}
|
||||
}
|
||||
|
||||
const checkList = (list, musicInfo, type, ext) => list.some(s => s.songmid === musicInfo.songmid && (s.type === type || s.ext === ext))
|
||||
const checkList = (list, musicInfo, type, ext) => list.some(s => s.songmid === musicInfo.songmid && (s.metadata.type === type || s.metadata.ext === ext))
|
||||
|
||||
const getStartTask = (list, downloadStatus, maxDownloadNum) => {
|
||||
let downloadCount = 0
|
||||
@@ -108,11 +110,10 @@ const handleGetMusicUrl = function(musicInfo, type, retryedSource = [], originMu
|
||||
}
|
||||
|
||||
const getMusicUrl = async function(downloadInfo, isUseOtherSource, isRefresh) {
|
||||
downloadInfo = window.downloadListFullMap.get(downloadInfo.key)
|
||||
const cachedUrl = await getMusicUrlFormStorage(downloadInfo.musicInfo, downloadInfo.type)
|
||||
if (!downloadInfo.musicInfo._types[downloadInfo.type]) {
|
||||
const cachedUrl = await getMusicUrlFormStorage(downloadInfo.metadata.musicInfo, downloadInfo.metadata.type)
|
||||
if (!downloadInfo.metadata.musicInfo._types[downloadInfo.metadata.type]) {
|
||||
// 兼容旧版酷我源搜索列表过滤128k音质的bug
|
||||
if (!(downloadInfo.musicInfo.source == 'kw' && downloadInfo.type == '128k')) throw new Error('该歌曲没有可下载的音频')
|
||||
if (!(downloadInfo.metadata.musicInfo.source == 'kw' && downloadInfo.metadata.type == '128k')) throw new Error('该歌曲没有可下载的音频')
|
||||
|
||||
// return Promise.reject(new Error('该歌曲没有可下载的音频'))
|
||||
}
|
||||
@@ -120,10 +121,10 @@ const getMusicUrl = async function(downloadInfo, isUseOtherSource, isRefresh) {
|
||||
? cachedUrl
|
||||
: (
|
||||
isUseOtherSource
|
||||
? handleGetMusicUrl.call(this, downloadInfo.musicInfo, downloadInfo.type)
|
||||
: music[downloadInfo.musicInfo.source].getMusicUrl(downloadInfo.musicInfo, downloadInfo.type).promise
|
||||
? handleGetMusicUrl.call(this, downloadInfo.metadata.musicInfo, downloadInfo.metadata.type)
|
||||
: music[downloadInfo.metadata.musicInfo.source].getMusicUrl(downloadInfo.metadata.musicInfo, downloadInfo.metadata.type).promise
|
||||
).then(({ url }) => {
|
||||
setMusicUrl(downloadInfo.musicInfo, downloadInfo.type, url)
|
||||
setMusicUrl(downloadInfo.metadata.musicInfo, downloadInfo.metadata.type, url)
|
||||
return url
|
||||
})
|
||||
}
|
||||
@@ -213,31 +214,30 @@ const fixKgLyric = lrc => /\[00:\d\d:\d\d.\d+\]/.test(lrc) ? lrc.replace(/(?:\[0
|
||||
* @param {*} isEmbedPic // 是否嵌入图片
|
||||
*/
|
||||
const saveMeta = function(downloadInfo, filePath, isUseOtherSource, isEmbedPic, isEmbedLyric) {
|
||||
if (downloadInfo.type === 'ape') return
|
||||
downloadInfo = window.downloadListFullMap.get(downloadInfo.key)
|
||||
if (downloadInfo.metadata.type === 'ape') return
|
||||
const tasks = [
|
||||
isEmbedPic
|
||||
? downloadInfo.musicInfo.img
|
||||
? Promise.resolve(downloadInfo.musicInfo.img)
|
||||
? downloadInfo.metadata.musicInfo.img
|
||||
? Promise.resolve(downloadInfo.metadata.musicInfo.img)
|
||||
: (
|
||||
isUseOtherSource
|
||||
? getPic.call(this, downloadInfo.musicInfo)
|
||||
: music[downloadInfo.musicInfo.source].getPic(downloadInfo.musicInfo).promise
|
||||
? getPic.call(this, downloadInfo.metadata.musicInfo)
|
||||
: music[downloadInfo.metadata.musicInfo.source].getPic(downloadInfo.metadata.musicInfo).promise
|
||||
).catch(err => {
|
||||
console.log(err)
|
||||
return null
|
||||
})
|
||||
: Promise.resolve(),
|
||||
isEmbedLyric
|
||||
? getLyric.call(this, downloadInfo.musicInfo, isUseOtherSource)
|
||||
? getLyric.call(this, downloadInfo.metadata.musicInfo, isUseOtherSource)
|
||||
: Promise.resolve(),
|
||||
]
|
||||
Promise.all(tasks).then(([imgUrl, lyrics = {}]) => {
|
||||
if (lyrics.lyric) lyrics.lyric = fixKgLyric(lyrics.lyric)
|
||||
setMeta(filePath, {
|
||||
title: downloadInfo.musicInfo.name,
|
||||
artist: downloadInfo.musicInfo.singer,
|
||||
album: downloadInfo.musicInfo.albumName,
|
||||
title: downloadInfo.metadata.musicInfo.name,
|
||||
artist: downloadInfo.metadata.musicInfo.singer,
|
||||
album: downloadInfo.metadata.musicInfo.albumName,
|
||||
APIC: imgUrl,
|
||||
lyrics: lyrics.lyric,
|
||||
})
|
||||
@@ -250,8 +250,7 @@ const saveMeta = function(downloadInfo, filePath, isUseOtherSource, isEmbedPic,
|
||||
* @param {*} filePath
|
||||
*/
|
||||
const downloadLyric = function(downloadInfo, isUseOtherSource, filePath, lrcFormat) {
|
||||
downloadInfo = window.downloadListFullMap.get(downloadInfo.key)
|
||||
getLyric.call(this, downloadInfo.musicInfo, isUseOtherSource).then(lrcs => {
|
||||
getLyric.call(this, downloadInfo.metadata.musicInfo, isUseOtherSource).then(lrcs => {
|
||||
if (lrcs?.lyric) {
|
||||
lrcs.lyric = fixKgLyric(lrcs.lyric)
|
||||
saveLrc(filePath.replace(/(mp3|flac|ape|wav)$/, 'lrc'), lrcs.lyric, lrcFormat)
|
||||
@@ -301,28 +300,31 @@ const createDownloadInfo = ({ musicInfo, type, list, fileName, savePath }) => {
|
||||
if (checkList(list, musicInfo, type, ext)) return null
|
||||
const downloadInfo = {
|
||||
isComplate: false,
|
||||
status: state.downloadStatus.WAITING,
|
||||
status: downloadStatus.WAITING,
|
||||
statusText: '待下载',
|
||||
url: null,
|
||||
songmid: musicInfo.songmid,
|
||||
fileName: filterFileName(`${fileName
|
||||
.replace('歌名', musicInfo.name)
|
||||
.replace('歌手', musicInfo.singer)}.${ext}`),
|
||||
progress: {
|
||||
downloaded: 0,
|
||||
total: 0,
|
||||
progress: 0,
|
||||
},
|
||||
type,
|
||||
ext,
|
||||
name: `${musicInfo.name} - ${musicInfo.singer}`,
|
||||
key,
|
||||
metadata: {
|
||||
musicInfo,
|
||||
url: null,
|
||||
type,
|
||||
ext,
|
||||
fileName: filterFileName(`${fileName
|
||||
.replace('歌名', musicInfo.name)
|
||||
.replace('歌手', musicInfo.singer)}.${ext}`),
|
||||
},
|
||||
}
|
||||
downloadInfo.filePath = path.join(savePath, downloadInfo.fileName)
|
||||
downloadInfo.metadata.filePath = path.join(savePath, downloadInfo.metadata.fileName)
|
||||
// commit('addTask', downloadInfo)
|
||||
|
||||
// 删除同路径下的同名文件
|
||||
deleteFile(downloadInfo.filePath)
|
||||
deleteFile(downloadInfo.metadata.filePath)
|
||||
// .catch(err => {
|
||||
// if (err.code !== 'ENOENT') return commit('setStatusText', { downloadInfo, text: '文件删除失败' })
|
||||
// })
|
||||
@@ -350,34 +352,33 @@ const actions = {
|
||||
type,
|
||||
fileName: rootState.setting.download.fileName,
|
||||
savePath: rootState.setting.download.savePath,
|
||||
list: state.list,
|
||||
list: downloadList,
|
||||
})
|
||||
if (!downloadInfo) return
|
||||
commit('addTask', { downloadInfo, musicInfo, addMusicLocationType: rootState.setting.list.addMusicLocationType })
|
||||
let result = getStartTask(state.list, state.downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
commit('addTask', { downloadInfo, addMusicLocationType: rootState.setting.list.addMusicLocationType })
|
||||
let result = getStartTask(downloadList, downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
console.log(result)
|
||||
while (result) {
|
||||
dispatch('startTask', result)
|
||||
result = getStartTask(state.list, state.downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
result = getStartTask(downloadList, downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
}
|
||||
},
|
||||
createDownloadMultiple({ state, rootState, commit, dispatch }, { list, type }) {
|
||||
if (!list.length) return
|
||||
const downloadList = []
|
||||
for (const musicInfo of list) {
|
||||
const downloadInfo = createDownloadInfo({
|
||||
const downloadList = list.map(musicInfo => {
|
||||
return createDownloadInfo({
|
||||
musicInfo,
|
||||
type,
|
||||
fileName: rootState.setting.download.fileName,
|
||||
savePath: rootState.setting.download.savePath,
|
||||
list: state.list,
|
||||
list: downloadList,
|
||||
})
|
||||
if (downloadInfo) downloadList.push({ downloadInfo, musicInfo })
|
||||
}
|
||||
})
|
||||
commit('addTasks', { list: downloadList, addMusicLocationType: rootState.setting.list.addMusicLocationType })
|
||||
let result = getStartTask(state.list, state.downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
let result = getStartTask(downloadList, downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
while (result) {
|
||||
dispatch('startTask', result)
|
||||
result = getStartTask(state.list, state.downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
result = getStartTask(downloadList, downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
}
|
||||
},
|
||||
async handleStartTask({ commit, dispatch, rootState }, downloadInfo) {
|
||||
@@ -394,9 +395,9 @@ const actions = {
|
||||
}
|
||||
const _this = this
|
||||
const options = {
|
||||
url: downloadInfo.url,
|
||||
url: downloadInfo.metadata.url,
|
||||
path: rootState.setting.download.savePath,
|
||||
fileName: downloadInfo.fileName,
|
||||
fileName: downloadInfo.metadata.fileName,
|
||||
method: 'get',
|
||||
override: true,
|
||||
onCompleted() {
|
||||
@@ -407,8 +408,8 @@ const actions = {
|
||||
commit('onCompleted', downloadInfo)
|
||||
dispatch('startTask')
|
||||
|
||||
saveMeta.call(_this, downloadInfo, downloadInfo.filePath, rootState.setting.download.isUseOtherSource, rootState.setting.download.isEmbedPic, rootState.setting.download.isEmbedLyric)
|
||||
if (rootState.setting.download.isDownloadLrc) downloadLyric.call(_this, downloadInfo, rootState.setting.download.isUseOtherSource, downloadInfo.filePath, rootState.setting.download.lrcFormat)
|
||||
saveMeta.call(_this, downloadInfo, downloadInfo.metadata.filePath, rootState.setting.download.isUseOtherSource, rootState.setting.download.isEmbedPic, rootState.setting.download.isEmbedLyric)
|
||||
if (rootState.setting.download.isDownloadLrc) downloadLyric.call(_this, downloadInfo, rootState.setting.download.isUseOtherSource, downloadInfo.metadata.filePath, rootState.setting.download.lrcFormat)
|
||||
console.log('on complate')
|
||||
},
|
||||
onError(err) {
|
||||
@@ -484,7 +485,7 @@ const actions = {
|
||||
},
|
||||
async removeTask({ commit, state, dispatch }, item) {
|
||||
if (dls[item.key]) {
|
||||
if (item.status == state.downloadStatus.RUN) {
|
||||
if (item.status == downloadStatus.RUN) {
|
||||
try {
|
||||
await dls[item.key].stop()
|
||||
} catch (_) {}
|
||||
@@ -492,21 +493,21 @@ const actions = {
|
||||
delete dls[item.key]
|
||||
}
|
||||
commit('removeTask', item)
|
||||
if (item.status != state.downloadStatus.COMPLETED) {
|
||||
if (item.status != downloadStatus.COMPLETED) {
|
||||
try {
|
||||
await deleteFile(item.filePath)
|
||||
await deleteFile(item.metadata.filePath)
|
||||
} catch (_) {}
|
||||
}
|
||||
switch (item.status) {
|
||||
case state.downloadStatus.RUN:
|
||||
case state.downloadStatus.WAITING:
|
||||
case downloadStatus.RUN:
|
||||
case downloadStatus.WAITING:
|
||||
await dispatch('startTask')
|
||||
}
|
||||
},
|
||||
removeTasks({ rootState, commit, dispatch }, list) {
|
||||
for (const item of list) {
|
||||
if (dls[item.key]) {
|
||||
if (item.status == state.downloadStatus.RUN) {
|
||||
if (item.status == downloadStatus.RUN) {
|
||||
dls[item.key].stop().finally(() => {
|
||||
delete dls[item.key]
|
||||
})
|
||||
@@ -514,27 +515,27 @@ const actions = {
|
||||
delete dls[item.key]
|
||||
}
|
||||
}
|
||||
if (item.status != state.downloadStatus.COMPLETED) {
|
||||
deleteFile(item.filePath).catch(_ => _)
|
||||
if (item.status != downloadStatus.COMPLETED) {
|
||||
deleteFile(item.metadata.filePath).catch(_ => _)
|
||||
}
|
||||
}
|
||||
commit('removeTasks', list)
|
||||
let result = getStartTask(state.list, state.downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
let result = getStartTask(downloadList, downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
while (result) {
|
||||
dispatch('startTask', result)
|
||||
result = getStartTask(state.list, state.downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
result = getStartTask(downloadList, downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
}
|
||||
},
|
||||
async startTask({ state, rootState, commit, dispatch }, downloadInfo) {
|
||||
// 检查是否可以开始任务
|
||||
if (downloadInfo && !downloadInfo.isComplate && downloadInfo.status != state.downloadStatus.RUN) {
|
||||
const result = getStartTask(state.list, state.downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
if (downloadInfo && !downloadInfo.isComplate && downloadInfo.status != downloadStatus.RUN) {
|
||||
const result = getStartTask(downloadList, downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
if (result === false) {
|
||||
commit('setStatus', { downloadInfo, status: state.downloadStatus.WAITING })
|
||||
commit('setStatus', { downloadInfo, status: downloadStatus.WAITING })
|
||||
return
|
||||
}
|
||||
} else {
|
||||
const result = getStartTask(state.list, state.downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
const result = getStartTask(downloadList, downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
if (!result) return
|
||||
downloadInfo = result
|
||||
}
|
||||
@@ -543,9 +544,9 @@ const actions = {
|
||||
if (dl) {
|
||||
commit('updateFilePath', {
|
||||
downloadInfo,
|
||||
filePath: path.join(rootState.setting.download.savePath, downloadInfo.fileName),
|
||||
filePath: path.join(rootState.setting.download.savePath, downloadInfo.metadata.fileName),
|
||||
})
|
||||
dl.updateSaveInfo(rootState.setting.download.savePath, downloadInfo.fileName)
|
||||
dl.updateSaveInfo(rootState.setting.download.savePath, downloadInfo.metadata.fileName)
|
||||
try {
|
||||
await dl.start()
|
||||
} catch (error) {
|
||||
@@ -558,271 +559,214 @@ const actions = {
|
||||
}
|
||||
},
|
||||
startTasks({ commit, rootState, dispatch }, list) {
|
||||
list = list.filter(item => !(item.isComplate || item.status == state.downloadStatus.RUN || item.status == state.downloadStatus.WAITING))
|
||||
commit('setStatus', { list, status: state.downloadStatus.WAITING })
|
||||
let result = getStartTask(state.list, state.downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
list = list.filter(item => !(item.isComplate || item.status == downloadStatus.RUN || item.status == downloadStatus.WAITING))
|
||||
commit('setStatus', { list, status: downloadStatus.WAITING })
|
||||
let result = getStartTask(downloadList, downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
while (result) {
|
||||
dispatch('startTask', result)
|
||||
result = getStartTask(state.list, state.downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
result = getStartTask(downloadList, downloadStatus, rootState.setting.download.maxDownloadNum)
|
||||
}
|
||||
},
|
||||
async pauseTask({ commit }, item) {
|
||||
if (item.isComplate) return
|
||||
let dl = dls[item.key]
|
||||
if (dl) dl.stop()
|
||||
commit('setStatus', { downloadInfo: item, status: state.downloadStatus.PAUSE })
|
||||
commit('setStatus', { downloadInfo: item, status: downloadStatus.PAUSE })
|
||||
},
|
||||
pauseTasks({ commit, rootState, dispatch }, list) {
|
||||
const waitingTasks = list.filter(item => item.status == state.downloadStatus.WAITING)
|
||||
commit('setStatus', { list: waitingTasks, status: state.downloadStatus.PAUSE })
|
||||
const runningTasks = list.filter(item => item.status == state.downloadStatus.RUN)
|
||||
const waitingTasks = list.filter(item => item.status == downloadStatus.WAITING)
|
||||
commit('setStatus', { list: waitingTasks, status: downloadStatus.PAUSE })
|
||||
const runningTasks = list.filter(item => item.status == downloadStatus.RUN)
|
||||
for (const item of runningTasks) {
|
||||
if (item.isComplate) return
|
||||
let dl = dls[item.key]
|
||||
if (dl) dl.stop()
|
||||
}
|
||||
commit('setStatus', { list: runningTasks, status: state.downloadStatus.PAUSE })
|
||||
commit('setStatus', { list: runningTasks, status: downloadStatus.PAUSE })
|
||||
},
|
||||
}
|
||||
|
||||
// mitations
|
||||
const mutations = {
|
||||
addTask(state, { downloadInfo, musicInfo, addMusicLocationType }) {
|
||||
const downloadInfoFull = { ...downloadInfo, musicInfo }
|
||||
window.downloadListFullMap.set(downloadInfo.key, downloadInfoFull)
|
||||
addTask(state, { downloadInfo, addMusicLocationType }) {
|
||||
downloadListMap.set(downloadInfo.key, downloadInfo)
|
||||
switch (addMusicLocationType) {
|
||||
case 'top':
|
||||
window.downloadListFull.unshift(downloadInfoFull)
|
||||
state.list.unshift(downloadInfo)
|
||||
downloadList.unshift(downloadInfo)
|
||||
break
|
||||
case 'bottom':
|
||||
default:
|
||||
window.downloadListFull.push(downloadInfoFull)
|
||||
state.list.push(downloadInfo)
|
||||
downloadList.push(downloadInfo)
|
||||
break
|
||||
}
|
||||
window.eventHub.emit(eventDownloadNames.listChange)
|
||||
},
|
||||
addTasks(state, { list, addMusicLocationType }) {
|
||||
const downloadInfoList = []
|
||||
const curDownloadListFull = []
|
||||
for (const { downloadInfo, musicInfo } of list) {
|
||||
downloadInfoList.push(downloadInfo)
|
||||
curDownloadListFull.push({ ...downloadInfo, musicInfo })
|
||||
}
|
||||
let newList
|
||||
let newListFull
|
||||
const map = {}
|
||||
const fullMap = {}
|
||||
const ids = []
|
||||
switch (addMusicLocationType) {
|
||||
case 'top':
|
||||
newList = [...downloadInfoList, ...state.list]
|
||||
newListFull = [...curDownloadListFull, ...window.downloadListFull]
|
||||
newList = [...list, ...downloadList]
|
||||
for (let i = newList.length - 1; i > -1; i--) {
|
||||
const item = newList[i]
|
||||
if (map[item.key]) continue
|
||||
ids.unshift(item.key)
|
||||
map[item.key] = item
|
||||
fullMap[item.key] = newListFull[i]
|
||||
fullMap[item.key] = newList[i]
|
||||
}
|
||||
break
|
||||
case 'bottom':
|
||||
default:
|
||||
newList = [...state.list, ...downloadInfoList]
|
||||
newListFull = [...window.downloadListFull, ...curDownloadListFull]
|
||||
newList = [...downloadList, ...list]
|
||||
newList.forEach((item, index) => {
|
||||
if (map[item.key]) return
|
||||
ids.push(item.key)
|
||||
map[item.key] = item
|
||||
fullMap[item.key] = newListFull[index]
|
||||
fullMap[item.key] = newList[index]
|
||||
})
|
||||
break
|
||||
}
|
||||
window.downloadListFullMap.clear()
|
||||
window.downloadListFull = ids.map(id => {
|
||||
const info = fullMap[id]
|
||||
window.downloadListFullMap.set(info.key, info)
|
||||
return info
|
||||
})
|
||||
state.list.splice(0, state.list.length, ...ids.map(id => map[id]))
|
||||
initDownloadList(ids.map(id => map[id]))
|
||||
window.eventHub.emit(eventDownloadNames.listChange)
|
||||
},
|
||||
removeTask({ list }, downloadInfo) {
|
||||
const index = list.findIndex(m => m.key == downloadInfo.key)
|
||||
removeTask(state, downloadInfo) {
|
||||
const index = downloadList.findIndex(m => m.key == downloadInfo.key)
|
||||
if (index < 0) return
|
||||
window.downloadListFull.splice(index, 1)
|
||||
window.downloadListFullMap.delete(downloadInfo.key)
|
||||
list.splice(index, 1)
|
||||
downloadListMap.delete(downloadInfo.key)
|
||||
downloadList.splice(index, 1)
|
||||
window.eventHub.emit(eventDownloadNames.listChange)
|
||||
},
|
||||
removeTasks(state, list) {
|
||||
let map = {}
|
||||
let set = new Set()
|
||||
let ids = []
|
||||
for (const item of state.list) {
|
||||
for (const item of downloadList) {
|
||||
ids.push(item.key)
|
||||
map[item.key] = item
|
||||
set.add(item.key)
|
||||
}
|
||||
for (const { key } of list) {
|
||||
if (map[key]) delete map[key]
|
||||
if (set.has(key)) delete set.delete(key)
|
||||
}
|
||||
let newList = []
|
||||
let newListFull = []
|
||||
for (const id of ids) {
|
||||
if (map[id]) {
|
||||
newList.push(map[id])
|
||||
newListFull.push(window.downloadListFullMap.get(id))
|
||||
if (set.has(id)) {
|
||||
newList.push(downloadListMap.get(id))
|
||||
}
|
||||
}
|
||||
|
||||
window.downloadListFull = newListFull
|
||||
window.downloadListFullMap.clear()
|
||||
for (const item of newListFull) {
|
||||
window.downloadListFullMap.set(item.key, item)
|
||||
}
|
||||
state.list.splice(0, state.list.length, ...newList)
|
||||
initDownloadList(newList)
|
||||
window.eventHub.emit(eventDownloadNames.listChange)
|
||||
},
|
||||
pauseTask(state, downloadInfo) {
|
||||
const index = state.list.findIndex(m => m.key == downloadInfo.key)
|
||||
const index = downloadList.findIndex(m => m.key == downloadInfo.key)
|
||||
if (index < 0) return
|
||||
const downloadInfoFull = window.downloadListFull[index]
|
||||
downloadInfoFull.status = state.downloadStatus.PAUSE
|
||||
downloadInfoFull.statusText = '暂停下载'
|
||||
|
||||
downloadInfo.status = state.downloadStatus.PAUSE
|
||||
downloadInfo = downloadList[index]
|
||||
downloadInfo.status = downloadStatus.PAUSE
|
||||
downloadInfo.statusText = '暂停下载'
|
||||
window.eventHub.emit(eventDownloadNames.listChange)
|
||||
},
|
||||
setStatusText(state, { downloadInfo, index, text }) { // 设置状态文本
|
||||
if (downloadInfo) {
|
||||
const index = state.list.findIndex(m => m.key == downloadInfo.key)
|
||||
if (index < 0) return
|
||||
const downloadInfoFull = window.downloadListFull[index]
|
||||
if (downloadInfoFull) downloadInfoFull.statusText = text
|
||||
downloadInfo.statusText = text
|
||||
} else {
|
||||
state.list[index].statusText = text
|
||||
const downloadInfoFull = window.downloadListFull[index]
|
||||
if (downloadInfoFull) downloadInfoFull.statusText = text
|
||||
index = downloadList.findIndex(m => m.key == downloadInfo.key)
|
||||
}
|
||||
if (index < 0) return
|
||||
downloadInfo = downloadList[index]
|
||||
downloadInfo.statusText = text
|
||||
window.eventHub.emit(eventDownloadNames.listChange)
|
||||
},
|
||||
setStatus(state, { downloadInfo, index, status, list }) { // 设置状态及状态文本
|
||||
let text
|
||||
switch (status) {
|
||||
case state.downloadStatus.RUN:
|
||||
case downloadStatus.RUN:
|
||||
text = '正在下载'
|
||||
break
|
||||
case state.downloadStatus.WAITING:
|
||||
case downloadStatus.WAITING:
|
||||
text = '等待下载'
|
||||
break
|
||||
case state.downloadStatus.PAUSE:
|
||||
case downloadStatus.PAUSE:
|
||||
text = '暂停下载'
|
||||
break
|
||||
case state.downloadStatus.ERROR:
|
||||
case downloadStatus.ERROR:
|
||||
text = '任务出错'
|
||||
break
|
||||
case state.downloadStatus.COMPLETED:
|
||||
case downloadStatus.COMPLETED:
|
||||
text = '下载完成'
|
||||
break
|
||||
}
|
||||
if (list) {
|
||||
for (const downloadInfo of list) {
|
||||
const index = state.list.findIndex(m => m.key == downloadInfo.key)
|
||||
for (let downloadInfo of list) {
|
||||
const index = downloadList.findIndex(m => m.key == downloadInfo.key)
|
||||
if (index < 0) return
|
||||
const downloadInfoFull = window.downloadListFull[index]
|
||||
downloadInfoFull.statusText = text
|
||||
downloadInfoFull.status = status
|
||||
|
||||
downloadInfo = downloadList[index]
|
||||
downloadInfo.statusText = text
|
||||
downloadInfo.status = status
|
||||
}
|
||||
} else {
|
||||
if (downloadInfo) {
|
||||
const index = state.list.findIndex(m => m.key == downloadInfo.key)
|
||||
if (index < 0) return
|
||||
const downloadInfoFull = window.downloadListFull[index]
|
||||
downloadInfoFull.statusText = text
|
||||
downloadInfoFull.status = status
|
||||
|
||||
downloadInfo.statusText = text
|
||||
downloadInfo.status = status
|
||||
} else {
|
||||
const downloadInfoFull = window.downloadListFull[index]
|
||||
downloadInfoFull.statusText = text
|
||||
downloadInfoFull.status = status
|
||||
|
||||
state.list[index].statusText = text
|
||||
state.list[index].status = status
|
||||
index = downloadList.findIndex(m => m.key == downloadInfo.key)
|
||||
}
|
||||
if (index < 0) return
|
||||
downloadInfo = downloadList[index]
|
||||
downloadInfo.statusText = text
|
||||
downloadInfo.status = status
|
||||
}
|
||||
window.eventHub.emit(eventDownloadNames.listChange)
|
||||
},
|
||||
onCompleted(state, downloadInfo) {
|
||||
const index = state.list.findIndex(m => m.key == downloadInfo.key)
|
||||
console.log(index)
|
||||
const index = downloadList.findIndex(m => m.key == downloadInfo.key)
|
||||
// console.log(index)
|
||||
if (index < 0) return
|
||||
const downloadInfoFull = window.downloadListFull[index]
|
||||
downloadInfoFull.isComplate = true
|
||||
downloadInfoFull.status = state.downloadStatus.COMPLETED
|
||||
downloadInfoFull.statusText = '下载完成'
|
||||
|
||||
|
||||
downloadInfo = downloadList[index]
|
||||
downloadInfo.isComplate = true
|
||||
downloadInfo.status = state.downloadStatus.COMPLETED
|
||||
downloadInfo.status = downloadStatus.COMPLETED
|
||||
downloadInfo.statusText = '下载完成'
|
||||
window.eventHub.emit(eventDownloadNames.listChange)
|
||||
},
|
||||
onError(state, { downloadInfo, errorMsg }) {
|
||||
const index = state.list.findIndex(m => m.key == downloadInfo.key)
|
||||
const index = downloadList.findIndex(m => m.key == downloadInfo.key)
|
||||
if (index < 0) return
|
||||
const downloadInfoFull = window.downloadListFull[index]
|
||||
downloadInfoFull.status = state.downloadStatus.ERROR
|
||||
downloadInfoFull.statusText = errorMsg || '任务出错'
|
||||
|
||||
downloadInfo.status = state.downloadStatus.ERROR
|
||||
downloadInfo = downloadList[index]
|
||||
downloadInfo.status = downloadStatus.ERROR
|
||||
downloadInfo.statusText = errorMsg || '任务出错'
|
||||
window.eventHub.emit(eventDownloadNames.listChange)
|
||||
},
|
||||
onStart(state, downloadInfo) {
|
||||
const index = state.list.findIndex(m => m.key == downloadInfo.key)
|
||||
const index = downloadList.findIndex(m => m.key == downloadInfo.key)
|
||||
if (index < 0) return
|
||||
const downloadInfoFull = window.downloadListFull[index]
|
||||
downloadInfoFull.status = state.downloadStatus.RUN
|
||||
downloadInfoFull.statusText = '正在下载'
|
||||
|
||||
downloadInfo.status = state.downloadStatus.RUN
|
||||
downloadInfo = downloadList[index]
|
||||
downloadInfo.status = downloadStatus.RUN
|
||||
downloadInfo.statusText = '正在下载'
|
||||
window.eventHub.emit(eventDownloadNames.listChange)
|
||||
},
|
||||
onProgress(state, { downloadInfo, status }) {
|
||||
const index = state.list.findIndex(m => m.key == downloadInfo.key)
|
||||
const index = downloadList.findIndex(m => m.key == downloadInfo.key)
|
||||
if (index < 0) return
|
||||
const downloadInfoFull = window.downloadListFull[index]
|
||||
downloadInfoFull.progress.progress = status.progress
|
||||
downloadInfoFull.progress.downloaded = status.downloaded
|
||||
downloadInfoFull.progress.total = status.total
|
||||
|
||||
downloadInfo = downloadList[index]
|
||||
downloadInfo.progress.progress = status.progress
|
||||
downloadInfo.progress.downloaded = status.downloaded
|
||||
downloadInfo.progress.total = status.total
|
||||
},
|
||||
updateDownloadList(state, list) {
|
||||
window.downloadListFullMap.clear()
|
||||
const stateList = list.map(downloadInfoFull => {
|
||||
window.downloadListFullMap.set(downloadInfoFull.key, downloadInfoFull)
|
||||
const downloadInfo = { ...downloadInfoFull }
|
||||
delete downloadInfo.musicInfo
|
||||
return downloadInfo
|
||||
})
|
||||
window.downloadListFull = list
|
||||
state.list = window.downloadList = stateList
|
||||
initDownloadList(state, list) {
|
||||
for (const task of list) {
|
||||
markRaw(task.metadata)
|
||||
}
|
||||
initDownloadList(list)
|
||||
window.eventHub.emit(eventDownloadNames.listChange)
|
||||
},
|
||||
updateUrl(state, { downloadInfo, url }) {
|
||||
const index = state.list.findIndex(m => m.key == downloadInfo.key)
|
||||
const index = downloadList.findIndex(m => m.key == downloadInfo.key)
|
||||
if (index < 0) return
|
||||
const downloadInfoFull = window.downloadListFull[index]
|
||||
downloadInfoFull.url = url
|
||||
downloadInfo.url = url
|
||||
downloadInfo = downloadList[index]
|
||||
downloadInfo.metadata.url = url
|
||||
window.eventHub.emit(eventDownloadNames.listChange)
|
||||
},
|
||||
updateFilePath(state, { downloadInfo, filePath }) {
|
||||
if (downloadInfo.filePath === filePath) return
|
||||
const index = state.list.findIndex(m => m.key == downloadInfo.key)
|
||||
if (downloadInfo.metadata.filePath === filePath) return
|
||||
const index = downloadList.findIndex(m => m.key == downloadInfo.key)
|
||||
if (index < 0) return
|
||||
const downloadInfoFull = window.downloadListFull[index]
|
||||
downloadInfoFull.filePath = filePath
|
||||
downloadInfo.filePath = filePath
|
||||
downloadInfo = downloadList[index]
|
||||
downloadInfo.metadata.filePath = filePath
|
||||
window.eventHub.emit(eventDownloadNames.listChange)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
+117
-115
@@ -1,54 +1,24 @@
|
||||
import musicSdk from '../../utils/music'
|
||||
import { clearLyric, clearMusicUrl } from '../../utils'
|
||||
import { sync as eventSyncName } from '@renderer/event/names'
|
||||
import { sync as eventSyncName, list as eventListNames } from '@renderer/event/names'
|
||||
import { removeListPosition, setListPrevSelectId } from '@renderer/utils/data'
|
||||
import { markRawList, toRaw, markRaw } from '@renderer/utils/vueTools'
|
||||
import { allList, allListInit, setInited, removeUserList, addUserList, updateList, defaultList, loveList, userLists } from '@renderer/core/share/list'
|
||||
|
||||
let allList = {}
|
||||
window.allList = allList
|
||||
|
||||
const allListInit = (defaultList, loveList, userList) => {
|
||||
for (const id of Object.keys(allList)) {
|
||||
delete allList[id]
|
||||
}
|
||||
allList[defaultList.id] = defaultList
|
||||
allList[loveList.id] = loveList
|
||||
for (const list of userList) allList[list.id] = list
|
||||
}
|
||||
const allListUpdate = list => {
|
||||
allList[list.id] = list
|
||||
}
|
||||
const allListRemove = list => {
|
||||
delete allList[list.id]
|
||||
}
|
||||
// import { allListInit } from '@renderer/core/share/list'
|
||||
|
||||
// state
|
||||
const state = {
|
||||
isInitedList: false,
|
||||
defaultList: {
|
||||
id: 'default',
|
||||
name: '试听列表',
|
||||
list: [],
|
||||
},
|
||||
loveList: {
|
||||
id: 'love',
|
||||
name: '我的收藏',
|
||||
list: [],
|
||||
},
|
||||
tempList: {
|
||||
id: 'temp',
|
||||
name: '临时列表',
|
||||
list: [],
|
||||
},
|
||||
userList: [],
|
||||
const state = window.lists = {
|
||||
// isInitedList: false,
|
||||
}
|
||||
|
||||
// getters
|
||||
const getters = {
|
||||
isInitedList: state => state.isInitedList,
|
||||
defaultList: state => state.defaultList || {},
|
||||
loveList: state => state.loveList || {},
|
||||
userList: state => state.userList,
|
||||
allList: () => allList,
|
||||
// isInitedList: state => state.isInitedList,
|
||||
// defaultList: state => state.defaultList || {},
|
||||
// loveList: state => state.loveList || {},
|
||||
// userList: state => state.userList,
|
||||
// allList: () => allList,
|
||||
}
|
||||
|
||||
const getOtherSourcePromises = new Map()
|
||||
@@ -71,56 +41,70 @@ const actions = {
|
||||
|
||||
// mitations
|
||||
const mutations = {
|
||||
initList(state, { defaultList, loveList, userList }) {
|
||||
if (defaultList != null) Object.assign(state.defaultList, { list: defaultList.list })
|
||||
if (loveList != null) Object.assign(state.loveList, { list: loveList.list })
|
||||
if (userList != null) state.userList = userList
|
||||
allListInit(state.defaultList, state.loveList, state.userList)
|
||||
state.isInitedList = true
|
||||
initList(state, { defaultList, loveList, userList, tempList }) {
|
||||
if (defaultList != null) {
|
||||
markRawList(defaultList.list)
|
||||
}
|
||||
if (loveList != null) {
|
||||
markRawList(loveList.list)
|
||||
}
|
||||
if (tempList != null) {
|
||||
markRawList(tempList.list)
|
||||
}
|
||||
if (userList != null) {
|
||||
for (const list of userList) if (list.list) markRawList(list.list)
|
||||
}
|
||||
allListInit(defaultList, loveList, tempList, userList)
|
||||
window.eventHub.emit(eventListNames.listChange, [defaultList.id, loveList.id, tempList.id, ...userList.map(l => l.id)])
|
||||
// state.isInitedList = true
|
||||
setInited()
|
||||
|
||||
// if (!isSync) {
|
||||
// window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
// window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
// action: 'init_list',
|
||||
// data: { defaultList, loveList, userList },
|
||||
// })
|
||||
// }
|
||||
},
|
||||
setSyncListData(state, { defaultList, loveList, userList }) {
|
||||
state.defaultList.list.splice(0, state.defaultList.list.length, ...defaultList.list)
|
||||
state.loveList.list.splice(0, state.loveList.list.length, ...loveList.list)
|
||||
for (let index = 0; index < userList.length; index++) {
|
||||
const list = userList[index]
|
||||
const targetList = allList[list.id]
|
||||
if (targetList) {
|
||||
userList.splice(index, 1, targetList)
|
||||
targetList.name = list.name
|
||||
targetList.list.splice(0, targetList.list.length, ...list.list)
|
||||
}
|
||||
}
|
||||
console.log()
|
||||
state.userList = userList
|
||||
allListInit(state.defaultList, state.loveList, state.userList)
|
||||
if (defaultList != null) markRawList(defaultList.list)
|
||||
if (loveList != null) markRawList(loveList.list)
|
||||
if (userList != null) for (const list of userList) markRawList(list.list)
|
||||
allListInit(defaultList, loveList, userList)
|
||||
window.eventHub.emit(eventListNames.listChange, [defaultList.id, loveList.id, ...userList.map(l => l.id)])
|
||||
},
|
||||
setList(state, { id, list, name, source, sourceListId, isSync }) {
|
||||
const targetList = allList[id]
|
||||
markRawList(list)
|
||||
const targetList = id == defaultList.id
|
||||
? defaultList
|
||||
: id == loveList.id
|
||||
? loveList
|
||||
: userLists.find(l => l.id == id)
|
||||
if (targetList) {
|
||||
if (name && targetList.name === name) {
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'set_list',
|
||||
data: { id, list, name, source, sourceListId },
|
||||
data: { id, list: toRaw(list), name, source, sourceListId },
|
||||
})
|
||||
}
|
||||
targetList.list.splice(0, targetList.list.length, ...list)
|
||||
updateList({
|
||||
id,
|
||||
list,
|
||||
name,
|
||||
source,
|
||||
sourceListId,
|
||||
})
|
||||
window.eventHub.emit(eventListNames.listChange, [id])
|
||||
return
|
||||
}
|
||||
|
||||
id += '_' + Math.random()
|
||||
}
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'set_list',
|
||||
data: { id, list, name, source, sourceListId },
|
||||
data: { id, list: toRaw(list), name, source, sourceListId },
|
||||
})
|
||||
}
|
||||
let newList = {
|
||||
@@ -130,37 +114,39 @@ const mutations = {
|
||||
source,
|
||||
sourceListId,
|
||||
}
|
||||
state.userList.push(newList)
|
||||
allListUpdate(newList)
|
||||
addUserList(newList)
|
||||
window.eventHub.emit(eventListNames.listChange, [id])
|
||||
},
|
||||
listAdd(state, { id, musicInfo, addMusicLocationType, isSync }) {
|
||||
if (!addMusicLocationType) addMusicLocationType = this.state.setting.list.addMusicLocationType
|
||||
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'list_add',
|
||||
data: { id, musicInfo, addMusicLocationType },
|
||||
data: { id, musicInfo: toRaw(musicInfo), addMusicLocationType },
|
||||
})
|
||||
}
|
||||
|
||||
const targetList = allList[id]
|
||||
markRaw(musicInfo)
|
||||
if (!targetList) return
|
||||
if (targetList.list.some(s => s.songmid === musicInfo.songmid)) return
|
||||
if (targetList.some(s => s.songmid === musicInfo.songmid)) return
|
||||
switch (addMusicLocationType) {
|
||||
case 'top':
|
||||
targetList.list.unshift(musicInfo)
|
||||
targetList.unshift(musicInfo)
|
||||
break
|
||||
case 'bottom':
|
||||
default:
|
||||
targetList.list.push(musicInfo)
|
||||
targetList.push(musicInfo)
|
||||
break
|
||||
}
|
||||
window.eventHub.emit(eventListNames.listChange, [id])
|
||||
},
|
||||
listMove(state, { fromId, musicInfo, toId, isSync }) {
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'list_move',
|
||||
data: { fromId, musicInfo, toId },
|
||||
data: { fromId, musicInfo: toRaw(musicInfo), toId },
|
||||
})
|
||||
}
|
||||
|
||||
@@ -180,25 +166,27 @@ const mutations = {
|
||||
break
|
||||
}
|
||||
}
|
||||
window.eventHub.emit(eventListNames.listChange, [fromId, toList])
|
||||
},
|
||||
listAddMultiple(state, { id, list, addMusicLocationType, isSync }) {
|
||||
if (!addMusicLocationType) addMusicLocationType = this.state.setting.list.addMusicLocationType
|
||||
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'list_add_multiple',
|
||||
data: { id, list, addMusicLocationType },
|
||||
data: { id, list: toRaw(list), addMusicLocationType },
|
||||
})
|
||||
}
|
||||
|
||||
let targetList = allList[id]
|
||||
if (!targetList) return
|
||||
markRawList(list)
|
||||
let newList
|
||||
const map = {}
|
||||
const ids = []
|
||||
switch (addMusicLocationType) {
|
||||
case 'top':
|
||||
newList = [...list, ...targetList.list]
|
||||
newList = [...list, ...targetList]
|
||||
for (let i = newList.length - 1; i > -1; i--) {
|
||||
const item = newList[i]
|
||||
if (map[item.songmid]) continue
|
||||
@@ -208,7 +196,7 @@ const mutations = {
|
||||
break
|
||||
case 'bottom':
|
||||
default:
|
||||
newList = [...targetList.list, ...list]
|
||||
newList = [...targetList, ...list]
|
||||
for (const item of newList) {
|
||||
if (map[item.songmid]) continue
|
||||
ids.push(item.songmid)
|
||||
@@ -216,14 +204,15 @@ const mutations = {
|
||||
}
|
||||
break
|
||||
}
|
||||
targetList.list.splice(0, targetList.list.length, ...ids.map(id => map[id]))
|
||||
targetList.splice(0, targetList.length, ...ids.map(id => map[id]))
|
||||
window.eventHub.emit(eventListNames.listChange, [id])
|
||||
},
|
||||
// { fromId, toId, list }
|
||||
listMoveMultiple(state, { fromId, toId, list, isSync }) {
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'list_move_multiple',
|
||||
data: { fromId, toId, list },
|
||||
data: { fromId, toId, list: toRaw(list) },
|
||||
})
|
||||
}
|
||||
|
||||
@@ -233,7 +222,7 @@ const mutations = {
|
||||
},
|
||||
listRemove(state, { listId, id, isSync }) {
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'list_remove',
|
||||
data: { listId, id },
|
||||
})
|
||||
@@ -241,13 +230,14 @@ const mutations = {
|
||||
|
||||
let targetList = allList[listId]
|
||||
if (!targetList) return
|
||||
const index = targetList.list.findIndex(item => item.songmid == id)
|
||||
const index = targetList.findIndex(item => item.songmid == id)
|
||||
if (index < 0) return
|
||||
targetList.list.splice(index, 1)
|
||||
targetList.splice(index, 1)
|
||||
window.eventHub.emit(eventListNames.listChange, [listId])
|
||||
},
|
||||
listRemoveMultiple(state, { listId, ids: musicIds, isSync }) {
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'list_remove_multiple',
|
||||
data: { listId, ids: musicIds },
|
||||
})
|
||||
@@ -257,7 +247,7 @@ const mutations = {
|
||||
if (!targetList) return
|
||||
let map = {}
|
||||
let ids = []
|
||||
for (const item of targetList.list) {
|
||||
for (const item of targetList) {
|
||||
ids.push(item.songmid)
|
||||
map[item.songmid] = item
|
||||
}
|
||||
@@ -267,11 +257,12 @@ const mutations = {
|
||||
let newList = []
|
||||
for (const id of ids) if (map[id]) newList.push(map[id])
|
||||
|
||||
targetList.list.splice(0, targetList.list.length, ...newList)
|
||||
targetList.splice(0, targetList.length, ...newList)
|
||||
window.eventHub.emit(eventListNames.listChange, [listId])
|
||||
},
|
||||
listClear(state, { id, isSync }) {
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'list_clear',
|
||||
data: { id },
|
||||
})
|
||||
@@ -279,13 +270,14 @@ const mutations = {
|
||||
|
||||
let targetList = allList[id]
|
||||
if (!targetList) return
|
||||
targetList.list.splice(0, targetList.list.length)
|
||||
targetList.splice(0, targetList.length)
|
||||
window.eventHub.emit(eventListNames.listChange, [id])
|
||||
},
|
||||
updateMusicInfo(state, { listId, id, data, musicInfo, isSync }) {
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'update_music_info',
|
||||
data: { listId, id, data, musicInfo },
|
||||
data: { listId, id, data, musicInfo: toRaw(musicInfo) },
|
||||
})
|
||||
}
|
||||
|
||||
@@ -294,18 +286,31 @@ const mutations = {
|
||||
if (musicInfo) Object.assign(musicInfo, data)
|
||||
return
|
||||
}
|
||||
const targetMusicInfo = targetList.list.find(item => item.songmid == id)
|
||||
const targetMusicInfo = targetList.find(item => item.songmid == id)
|
||||
if (targetMusicInfo) Object.assign(targetMusicInfo, data)
|
||||
|
||||
switch (listId) {
|
||||
case defaultList.id:
|
||||
window.eventHub.emit(eventListNames.musicInfoChange, { list: targetList, ...defaultList })
|
||||
break
|
||||
case loveList.id:
|
||||
window.eventHub.emit(eventListNames.musicInfoChange, { list: targetList, ...loveList })
|
||||
break
|
||||
default:
|
||||
window.eventHub.emit(eventListNames.musicInfoChange, userLists.map(l => ({ list: allList[l.id], ...l })))
|
||||
break
|
||||
}
|
||||
},
|
||||
createUserList(state, { name, id = `userlist_${Date.now()}`, list = [], source, sourceListId, position, isSync }) {
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'create_user_list',
|
||||
data: { name, id, list, source, sourceListId, position },
|
||||
data: { name, id, list: toRaw(list), source, sourceListId, position },
|
||||
})
|
||||
}
|
||||
|
||||
let newList = state.userList.find(item => item.id === id)
|
||||
markRawList(list)
|
||||
let newList = userLists.find(item => item.id === id)
|
||||
if (!newList) {
|
||||
newList = {
|
||||
name,
|
||||
@@ -314,32 +319,27 @@ const mutations = {
|
||||
source,
|
||||
sourceListId,
|
||||
}
|
||||
if (position == null) {
|
||||
state.userList.push(newList)
|
||||
} else {
|
||||
state.userList.splice(position + 1, 0, newList)
|
||||
}
|
||||
allListUpdate(newList)
|
||||
addUserList(newList)
|
||||
}
|
||||
this.commit('list/listAddMultiple', { id, list, isSync: true })
|
||||
},
|
||||
removeUserList(state, { id, isSync }) {
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'remove_user_list',
|
||||
data: { id },
|
||||
})
|
||||
}
|
||||
|
||||
const index = state.userList.findIndex(l => l.id === id)
|
||||
const index = userLists.findIndex(l => l.id === id)
|
||||
if (index < 0) return
|
||||
let list = state.userList.splice(index, 1)[0]
|
||||
allListRemove(list)
|
||||
removeUserList(id)
|
||||
removeListPosition(id)
|
||||
window.eventHub.emit(eventListNames.listChange, [id])
|
||||
},
|
||||
setUserListName(state, { id, name, isSync }) {
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'set_user_list_name',
|
||||
data: { id, name },
|
||||
})
|
||||
@@ -351,7 +351,7 @@ const mutations = {
|
||||
},
|
||||
moveupUserList(state, { id, isSync }) {
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'moveup_user_list',
|
||||
data: { id },
|
||||
})
|
||||
@@ -365,7 +365,7 @@ const mutations = {
|
||||
},
|
||||
movedownUserList(state, { id, isSync }) {
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'movedown_user_list',
|
||||
data: { id },
|
||||
})
|
||||
@@ -378,19 +378,20 @@ const mutations = {
|
||||
},
|
||||
setMusicPosition(state, { id, position, list, isSync }) {
|
||||
if (!isSync) {
|
||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||
window.eventHub.emit(eventSyncName.send_action_list, {
|
||||
action: 'set_music_position',
|
||||
data: { id, position, list },
|
||||
data: { id, position, list: toRaw(list) },
|
||||
})
|
||||
}
|
||||
|
||||
let targetList = allList[id]
|
||||
this.commit('list/listRemoveMultiple', { listId: id, ids: list.map(m => m.songmid), isSync: true })
|
||||
|
||||
targetList.list.splice(position - 1, 0, ...list)
|
||||
targetList.splice(position - 1, 0, ...list)
|
||||
window.eventHub.emit(eventListNames.listChange, [id])
|
||||
},
|
||||
clearCache() {
|
||||
const lists = Object.values(allList)
|
||||
const [listIds, lists] = Object.entries(allList)
|
||||
for (const { list } of lists) {
|
||||
for (const item of list) {
|
||||
if (item.otherSource) item.otherSource = null
|
||||
@@ -407,6 +408,7 @@ const mutations = {
|
||||
}
|
||||
clearMusicUrl()
|
||||
clearLyric()
|
||||
window.eventHub.emit(eventListNames.listChange, listIds)
|
||||
},
|
||||
setOtherSource(state, { musicInfo, otherSource }) {
|
||||
musicInfo.otherSource = otherSource
|
||||
|
||||
@@ -8,22 +8,32 @@ import {
|
||||
setMusicUrl,
|
||||
getMusicUrl as getStoreMusicUrl,
|
||||
assertApiSupport,
|
||||
} from '../../utils'
|
||||
} from '@renderer/utils'
|
||||
import { player as eventPlayerNames, list as eventListNames } from '@renderer/event/names'
|
||||
import {
|
||||
setPlayList,
|
||||
setPlayMusicInfo,
|
||||
playedList,
|
||||
addPlayedList,
|
||||
removePlayedList,
|
||||
clearPlayedList,
|
||||
tempPlayList,
|
||||
addTempPlayList,
|
||||
removeTempPlayList,
|
||||
clearTempPlayeList,
|
||||
playInfo,
|
||||
playMusicInfo,
|
||||
} from '@renderer/core/share/player'
|
||||
import { tempList, updateList } from '@renderer/core/share/list'
|
||||
import { getList } from '@renderer/core/share/utils'
|
||||
|
||||
// state
|
||||
const state = {
|
||||
listInfo: {
|
||||
list: [],
|
||||
id: null,
|
||||
},
|
||||
playIndex: -1,
|
||||
changePlay: false,
|
||||
playedList: [],
|
||||
|
||||
playMusicInfo: null,
|
||||
tempPlayList: [],
|
||||
}
|
||||
|
||||
const playMusic = () => {
|
||||
window.eventHub.emit(eventPlayerNames.playMusic)
|
||||
}
|
||||
|
||||
const filterList = async({ playedList, listInfo, savePath, commit }) => {
|
||||
// if (this.list.listName === null) return
|
||||
@@ -33,7 +43,7 @@ const filterList = async({ playedList, listInfo, savePath, commit }) => {
|
||||
if (listInfo.id == 'download') {
|
||||
list = []
|
||||
for (const item of listInfo.list) {
|
||||
const filePath = path.join(savePath, item.fileName)
|
||||
const filePath = path.join(savePath, item.metadata.fileName)
|
||||
if (!await checkPath(filePath) || !item.isComplate || /\.ape$/.test(filePath)) continue
|
||||
|
||||
canPlayList.push(item)
|
||||
@@ -140,75 +150,9 @@ const getLyric = function(musicInfo, retryedSource = [], originMusic) {
|
||||
})
|
||||
}
|
||||
|
||||
let prevListPlayIndex
|
||||
// getters
|
||||
const getters = {
|
||||
list: state => state.listInfo.list,
|
||||
changePlay: satte => satte.changePlay,
|
||||
playInfo(state) {
|
||||
if (state.playMusicInfo == null) return { listId: null, playIndex: -1, playListId: null, listPlayIndex: -1, isPlayList: false, musicInfo: null }
|
||||
const playListId = state.listInfo.id
|
||||
let listId = state.playMusicInfo.listId
|
||||
const isTempPlay = !!state.playMusicInfo.isTempPlay
|
||||
const isPlayList = listId === playListId
|
||||
let playIndex = -1
|
||||
let listPlayIndex = Math.min(state.playIndex, state.listInfo.list.length - 1)
|
||||
|
||||
if (listId != '__temp__') {
|
||||
if (state.playMusicInfo.musicInfo.key) {
|
||||
const currentKey = state.playMusicInfo.musicInfo.key
|
||||
if (isPlayList) {
|
||||
playIndex = state.listInfo.list.findIndex(m => m.key == currentKey)
|
||||
if (!isTempPlay) listPlayIndex = playIndex
|
||||
} else if (listId == 'download') {
|
||||
playIndex = window.downloadList.findIndex(m => m.key == currentKey)
|
||||
}
|
||||
} else {
|
||||
const currentSongmid = state.playMusicInfo.musicInfo.songmid
|
||||
if (isPlayList) {
|
||||
playIndex = state.listInfo.list.findIndex(m => m.songmid == currentSongmid)
|
||||
if (!isTempPlay) listPlayIndex = playIndex
|
||||
} else {
|
||||
let list = window.allList[listId]
|
||||
if (list) playIndex = list.list.findIndex(m => m.songmid == currentSongmid)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (listPlayIndex >= 0) prevListPlayIndex = listPlayIndex
|
||||
// if (listPlayIndex < 0) {
|
||||
// let length = state.listInfo.list.length
|
||||
// if (length) {
|
||||
// let index = Math.min(prevListPlayIndex, 0)
|
||||
// if (index > length - 1) index = length - 1
|
||||
// listPlayIndex = prevListPlayIndex = index
|
||||
// }
|
||||
// } else {
|
||||
// prevListPlayIndex = listPlayIndex
|
||||
// }
|
||||
// console.log({
|
||||
// listId,
|
||||
// playIndex,
|
||||
// playListId,
|
||||
// listPlayIndex,
|
||||
// isPlayList,
|
||||
// isTempPlay,
|
||||
// musicInfo: state.playMusicInfo.musicInfo,
|
||||
// })
|
||||
|
||||
// console.log(state.playMusicInfo)
|
||||
return {
|
||||
listId,
|
||||
playIndex,
|
||||
playListId,
|
||||
listPlayIndex,
|
||||
isPlayList,
|
||||
isTempPlay,
|
||||
musicInfo: state.playMusicInfo.musicInfo,
|
||||
}
|
||||
},
|
||||
playMusicInfo: state => state.playMusicInfo,
|
||||
playedList: state => state.playedList,
|
||||
tempPlayList: state => state.tempPlayList,
|
||||
}
|
||||
|
||||
// actions
|
||||
@@ -230,12 +174,12 @@ const actions = {
|
||||
return Promise.reject(err)
|
||||
})
|
||||
},
|
||||
getPic({ commit, state }, musicInfo) {
|
||||
getPic({ commit, state }, { musicInfo, listId }) {
|
||||
// if (picRequest && picRequest.cancelHttp) picRequest.cancelHttp()
|
||||
// picRequest = music[musicInfo.source].getPic(musicInfo)
|
||||
return getPic.call(this, musicInfo).then(url => {
|
||||
// picRequest = null
|
||||
commit('setPic', { musicInfo, url })
|
||||
commit('setPic', { musicInfo, url, listId })
|
||||
}).catch(err => {
|
||||
// picRequest = null
|
||||
return Promise.reject(err)
|
||||
@@ -268,21 +212,20 @@ const actions = {
|
||||
},
|
||||
|
||||
async playPrev({ state, rootState, commit, getters }) {
|
||||
const currentListId = state.listInfo.id
|
||||
const currentList = state.listInfo.list
|
||||
const playInfo = getters.playInfo
|
||||
if (state.playedList.length) {
|
||||
const currentListId = playInfo.playListId
|
||||
const currentList = getList(currentListId)
|
||||
if (playedList.length) {
|
||||
let currentSongmid
|
||||
if (state.playMusicInfo.isTempPlay) {
|
||||
if (playMusicInfo.isTempPlay) {
|
||||
const musicInfo = currentList[playInfo.listPlayIndex]
|
||||
if (musicInfo) currentSongmid = musicInfo.songmid
|
||||
} else {
|
||||
currentSongmid = state.playMusicInfo.musicInfo.songmid
|
||||
currentSongmid = playMusicInfo.musicInfo.songmid
|
||||
}
|
||||
// 从已播放列表移除播放列表已删除的歌曲
|
||||
let index
|
||||
for (index = state.playedList.findIndex(m => m.musicInfo.songmid === currentSongmid) - 1; index > -1; index--) {
|
||||
const playMusicInfo = state.playedList[index]
|
||||
for (index = playedList.findIndex(m => m.musicInfo.songmid === currentSongmid) - 1; index > -1; index--) {
|
||||
const playMusicInfo = playedList[index]
|
||||
const currentSongmid = playMusicInfo.musicInfo.songmid
|
||||
if (playMusicInfo.listId == currentListId && !currentList.some(m => m.songmid === currentSongmid)) {
|
||||
commit('removePlayedList', index)
|
||||
@@ -292,28 +235,24 @@ const actions = {
|
||||
}
|
||||
|
||||
if (index > -1) {
|
||||
commit('setPlayMusicInfo', state.playedList[index])
|
||||
commit('setPlayMusicInfo', playedList[index])
|
||||
playMusic()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
let filteredList = await filterList({
|
||||
listInfo: state.listInfo,
|
||||
playedList: state.playedList,
|
||||
listInfo: { id: currentListId, list: currentList },
|
||||
playedList,
|
||||
savePath: rootState.setting.download.savePath,
|
||||
commit,
|
||||
})
|
||||
if (!filteredList.length) return commit('setPlayMusicInfo', null)
|
||||
if (!filteredList.length) return commit('setPlayMusicInfo', { listId: null, musicInfo: null })
|
||||
|
||||
let listPlayIndex = filteredList.indexOf(state.listInfo.list[playInfo.listPlayIndex])
|
||||
const currentListLength = state.listInfo.list.length - 1
|
||||
if (listPlayIndex == -1 && currentListLength) {
|
||||
listPlayIndex = prevListPlayIndex >= currentListLength ? 0 : prevListPlayIndex + 1
|
||||
}
|
||||
let currentIndex = listPlayIndex
|
||||
if (currentIndex < 0) currentIndex = 0
|
||||
let currentIndex = filteredList.indexOf(currentList[playInfo.listPlayIndex])
|
||||
if (currentIndex == -1 && filteredList.length) currentIndex = 0
|
||||
let nextIndex = currentIndex
|
||||
if (!playInfo.isTempPlay) {
|
||||
if (!playMusicInfo.isTempPlay) {
|
||||
switch (rootState.setting.player.togglePlayMethod) {
|
||||
case 'random':
|
||||
nextIndex = getRandom(0, filteredList.length)
|
||||
@@ -335,30 +274,33 @@ const actions = {
|
||||
musicInfo: filteredList[nextIndex],
|
||||
listId: currentListId,
|
||||
})
|
||||
playMusic()
|
||||
},
|
||||
async playNext({ state, rootState, commit, getters }) {
|
||||
if (state.tempPlayList.length) {
|
||||
const playMusicInfo = state.tempPlayList[0]
|
||||
if (tempPlayList.length) {
|
||||
const playMusicInfo = tempPlayList[0]
|
||||
commit('removeTempPlayList', 0)
|
||||
commit('setPlayMusicInfo', playMusicInfo)
|
||||
playMusic()
|
||||
return
|
||||
}
|
||||
const currentListId = state.listInfo.id
|
||||
const currentList = state.listInfo.list
|
||||
const playInfo = getters.playInfo
|
||||
|
||||
if (state.playedList.length) {
|
||||
console.log(playInfo.playListId)
|
||||
const currentListId = playInfo.playListId
|
||||
const currentList = getList(currentListId)
|
||||
|
||||
if (playedList.length) {
|
||||
let currentSongmid
|
||||
if (state.playMusicInfo.isTempPlay) {
|
||||
if (playMusicInfo.isTempPlay) {
|
||||
const musicInfo = currentList[playInfo.listPlayIndex]
|
||||
if (musicInfo) currentSongmid = musicInfo.songmid
|
||||
} else {
|
||||
currentSongmid = state.playMusicInfo.musicInfo.songmid
|
||||
currentSongmid = playMusicInfo.musicInfo.songmid
|
||||
}
|
||||
// 从已播放列表移除播放列表已删除的歌曲
|
||||
let index
|
||||
for (index = state.playedList.findIndex(m => m.musicInfo.songmid === currentSongmid) + 1; index < state.playedList.length; index++) {
|
||||
const playMusicInfo = state.playedList[index]
|
||||
for (index = playedList.findIndex(m => m.musicInfo.songmid === currentSongmid) + 1; index < playedList.length; index++) {
|
||||
const playMusicInfo = playedList[index]
|
||||
const currentSongmid = playMusicInfo.musicInfo.songmid
|
||||
if (playMusicInfo.listId == currentListId && !currentList.some(m => m.songmid === currentSongmid)) {
|
||||
commit('removePlayedList', index)
|
||||
@@ -367,25 +309,22 @@ const actions = {
|
||||
break
|
||||
}
|
||||
|
||||
if (index < state.playedList.length) {
|
||||
commit('setPlayMusicInfo', state.playedList[index])
|
||||
if (index < playedList.length) {
|
||||
commit('setPlayMusicInfo', playedList[index])
|
||||
playMusic()
|
||||
return
|
||||
}
|
||||
}
|
||||
let filteredList = await filterList({
|
||||
listInfo: state.listInfo,
|
||||
playedList: state.playedList,
|
||||
listInfo: { id: currentListId, list: currentList },
|
||||
playedList,
|
||||
savePath: rootState.setting.download.savePath,
|
||||
commit,
|
||||
})
|
||||
|
||||
if (!filteredList.length) return commit('setPlayMusicInfo', null)
|
||||
let listPlayIndex = filteredList.indexOf(state.listInfo.list[playInfo.listPlayIndex])
|
||||
const currentListLength = state.listInfo.list.length - 1
|
||||
if (listPlayIndex == -1 && currentListLength) {
|
||||
listPlayIndex = prevListPlayIndex > currentListLength ? currentListLength : prevListPlayIndex - 1
|
||||
}
|
||||
const currentIndex = listPlayIndex
|
||||
if (!filteredList.length) return commit('setPlayMusicInfo', { listId: null, musicInfo: null })
|
||||
let currentIndex = filteredList.indexOf(currentList[playInfo.listPlayIndex])
|
||||
if (currentIndex == -1 && filteredList.length) currentIndex = 0
|
||||
let nextIndex = currentIndex
|
||||
|
||||
switch (rootState.setting.player.togglePlayMethod) {
|
||||
@@ -410,6 +349,7 @@ const actions = {
|
||||
musicInfo: filteredList[nextIndex],
|
||||
listId: currentListId,
|
||||
})
|
||||
playMusic()
|
||||
},
|
||||
}
|
||||
|
||||
@@ -421,6 +361,12 @@ const mutations = {
|
||||
},
|
||||
setPic(state, datas) {
|
||||
datas.musicInfo.img = datas.url
|
||||
this.commit('list/updateMusicInfo', {
|
||||
listId: datas.listId,
|
||||
id: datas.musicInfo.songmid,
|
||||
data: { img: datas.url },
|
||||
musicInfo: datas.musicInfo,
|
||||
})
|
||||
},
|
||||
setLrc(state, datas) {
|
||||
// datas.musicInfo.lrc = datas.lyric
|
||||
@@ -432,65 +378,50 @@ const mutations = {
|
||||
lxlyric: datas.lxlyric,
|
||||
})
|
||||
},
|
||||
setList(state, { list, index }) {
|
||||
if (!(list && list.list && list.list[index])) return
|
||||
state.playMusicInfo = {
|
||||
musicInfo: list.list[index],
|
||||
listId: list.id,
|
||||
}
|
||||
state.listInfo = list
|
||||
state.playIndex = index
|
||||
state.changePlay = true
|
||||
// console.log(state.playMusicInfo)
|
||||
if (state.playedList.length) this.commit('player/clearPlayedList')
|
||||
if (state.tempPlayList.length) this.commit('player/clearTempPlayeList')
|
||||
setList(state, { listId, index }) {
|
||||
const list = getList(listId)
|
||||
const musicInfo = list[index]
|
||||
if (!musicInfo) return
|
||||
setPlayList(listId)
|
||||
setPlayMusicInfo(listId, musicInfo)
|
||||
if (playedList.length) this.commit('player/clearPlayedList')
|
||||
if (tempPlayList.length) this.commit('player/clearTempPlayeList')
|
||||
playMusic()
|
||||
},
|
||||
setPlayIndex(state, index) {
|
||||
state.playIndex = index
|
||||
},
|
||||
setChangePlay(state) {
|
||||
state.changePlay = true
|
||||
},
|
||||
resetChangePlay(state) {
|
||||
state.changePlay = false
|
||||
setTempList(state, { list, index }) {
|
||||
updateList({ id: tempList.id, list })
|
||||
this.commit('player/setList', {
|
||||
listId: tempList.id,
|
||||
index,
|
||||
})
|
||||
window.eventHub.emit(eventListNames.listChange, [tempList.id])
|
||||
},
|
||||
// setPlayIndex(state, index) {
|
||||
// state.playIndex = index
|
||||
// },
|
||||
setPlayedList(state, item) {
|
||||
// console.log(item)
|
||||
if (state.playedList.includes(item)) return
|
||||
state.playedList.push(item)
|
||||
addPlayedList(item)
|
||||
},
|
||||
removePlayedList(state, index) {
|
||||
state.playedList.splice(index, 1)
|
||||
removePlayedList(index)
|
||||
},
|
||||
clearPlayedList(state) {
|
||||
state.playedList.splice(0, state.playedList.length)
|
||||
clearPlayedList()
|
||||
},
|
||||
setTempPlayList(state, list) {
|
||||
state.tempPlayList.push(...list.map(({ musicInfo, listId }) => ({ musicInfo, listId, isTempPlay: true })))
|
||||
if (!state.playMusicInfo) this.commit('player/playNext')
|
||||
addTempPlayList(list)
|
||||
if (!playMusicInfo.musicInfo) this.commit('player/playNext')
|
||||
},
|
||||
removeTempPlayList(state, index) {
|
||||
state.tempPlayList.splice(index, 1)
|
||||
removeTempPlayList(index)
|
||||
},
|
||||
clearTempPlayeList(state) {
|
||||
state.tempPlayList.splice(0, state.tempPlayList.length)
|
||||
clearTempPlayeList()
|
||||
},
|
||||
|
||||
setPlayMusicInfo(state, playMusicInfo) {
|
||||
let playIndex = state.playIndex
|
||||
if (playMusicInfo == null) {
|
||||
playIndex = -1
|
||||
} else {
|
||||
let listId = playMusicInfo.listId
|
||||
if (listId != '__temp__' && !playMusicInfo.isTempPlay && listId === state.listInfo.id) {
|
||||
const currentSongmid = playMusicInfo.musicInfo.songmid
|
||||
playIndex = state.listInfo.list.findIndex(m => m.songmid == currentSongmid)
|
||||
}
|
||||
}
|
||||
|
||||
state.playMusicInfo = playMusicInfo
|
||||
state.playIndex = playIndex
|
||||
state.changePlay = true
|
||||
setPlayMusicInfo(state, { listId, musicInfo, isTempPlay }) {
|
||||
setPlayMusicInfo(listId, musicInfo, isTempPlay)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,6 @@ const mutations = {
|
||||
cache.set(key, result)
|
||||
},
|
||||
setVisibleListDetail(state, bool) {
|
||||
if (!bool) state.listDetail.list = []
|
||||
state.isVisibleListDetail = bool
|
||||
},
|
||||
setSelectListInfo(state, info) {
|
||||
|
||||
@@ -24,21 +24,6 @@ export default {
|
||||
if (sortId != null) state.setting.songList.sortId = sortId
|
||||
if (source != null) state.setting.songList.source = source
|
||||
},
|
||||
setNewVersion(state, val) {
|
||||
state.version.newVersion = val
|
||||
},
|
||||
setDownloadProgress(state, info) {
|
||||
state.version.downloadProgress = info
|
||||
},
|
||||
setVersionModalVisible(state, { isShow, isError, isDownloaded, isTimeOut, isDownloading, isUnknow, isLatestVer }) {
|
||||
if (isError !== undefined) state.version.isError = isError
|
||||
if (isTimeOut !== undefined) state.version.isTimeOut = isTimeOut
|
||||
if (isDownloading !== undefined) state.version.isDownloading = isDownloading
|
||||
if (isDownloaded !== undefined) state.version.isDownloaded = isDownloaded
|
||||
if (isUnknow !== undefined) state.version.isUnknow = isUnknow
|
||||
if (isLatestVer !== undefined) state.version.isLatestVer = isLatestVer
|
||||
if (isShow !== undefined) state.version.showModal = isShow
|
||||
},
|
||||
setIgnoreVersion(state, version) {
|
||||
state.setting.ignoreVersion = version
|
||||
},
|
||||
@@ -64,4 +49,10 @@ export default {
|
||||
setDesktopLyricConfig(state, config) {
|
||||
state.setting.desktopLyric = Object.assign(state.setting.desktopLyric, config)
|
||||
},
|
||||
setApiSource(state, apiSource) {
|
||||
state.setting.apiSource = apiSource
|
||||
},
|
||||
setProxyEnable(state, val) {
|
||||
state.setting.network.proxy.enable = val
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,98 +1,7 @@
|
||||
// const isDev = process.env.NODE_ENV === 'development'
|
||||
import { windowSizeList } from '../../common/config'
|
||||
import { version } from '../../../package.json'
|
||||
|
||||
process.versions.app = version
|
||||
|
||||
|
||||
export default {
|
||||
themes: [
|
||||
{
|
||||
id: 0,
|
||||
name: '绿意盎然',
|
||||
class: 'green',
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
name: '蓝田生玉',
|
||||
class: 'blue',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: '信口雌黄',
|
||||
class: 'yellow',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: '橙黄橘绿',
|
||||
class: 'orange',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: '热情似火',
|
||||
class: 'red',
|
||||
},
|
||||
{
|
||||
id: 10,
|
||||
name: '粉装玉琢',
|
||||
class: 'pink',
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
name: '重斤球紫',
|
||||
class: 'purple',
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
name: '灰常美丽',
|
||||
class: 'grey',
|
||||
},
|
||||
{
|
||||
id: 11,
|
||||
name: '青出于黑',
|
||||
class: 'ming',
|
||||
},
|
||||
{
|
||||
id: 12,
|
||||
name: '青出于黑',
|
||||
class: 'blue2',
|
||||
},
|
||||
{
|
||||
id: 13,
|
||||
name: '黑纸白字',
|
||||
class: 'black',
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
name: '月里嫦娥',
|
||||
class: 'mid_autumn',
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
name: '木叶之村',
|
||||
class: 'naruto',
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
name: '新年快乐',
|
||||
class: 'happy_new_year',
|
||||
},
|
||||
],
|
||||
version: {
|
||||
version,
|
||||
newVersion: null,
|
||||
showModal: false,
|
||||
isError: false,
|
||||
isTimeOut: false,
|
||||
isUnknow: false,
|
||||
isDownloaded: false,
|
||||
isDownloading: false,
|
||||
isLatestVer: false,
|
||||
downloadProgress: null,
|
||||
},
|
||||
userInfo: null,
|
||||
setting: null,
|
||||
settingVersion: null,
|
||||
|
||||
windowSizeList,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user