升级到 vue3
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { reactive, ref, markRaw } from '@renderer/utils/vueTools'
|
||||
|
||||
export const isInitedList = ref(false)
|
||||
|
||||
export const setInited = () => {
|
||||
isInitedList.value = true
|
||||
}
|
||||
|
||||
export const downloadList = reactive([])
|
||||
export const downloadListMap = new Map()
|
||||
|
||||
export const initDownloadList = list => {
|
||||
downloadList.splice(0, downloadList.length, ...list)
|
||||
downloadListMap.clear()
|
||||
for (const task of list) {
|
||||
downloadListMap.set(task.key, task)
|
||||
}
|
||||
}
|
||||
|
||||
export const downloadStatus = markRaw({
|
||||
RUN: 'run',
|
||||
WAITING: 'waiting',
|
||||
PAUSE: 'pause',
|
||||
ERROR: 'error',
|
||||
COMPLETED: 'completed',
|
||||
})
|
||||
@@ -0,0 +1,46 @@
|
||||
import { ref, reactive, shallowRef, markRaw } from '@renderer/utils/vueTools'
|
||||
import { windowSizeList as configWindowSizeList, themes as configThemes } from '@common/config'
|
||||
import { version } from '../../../../package.json'
|
||||
process.versions.app = version
|
||||
|
||||
export const apiSource = ref(null)
|
||||
export const isShowPact = window.isShowPact = ref(false)
|
||||
export const proxy = reactive({})
|
||||
export const versionInfo = window.versionInfo = reactive({
|
||||
version,
|
||||
newVersion: null,
|
||||
showModal: false,
|
||||
isError: false,
|
||||
isTimeOut: false,
|
||||
isUnknow: false,
|
||||
isDownloaded: false,
|
||||
isDownloading: false,
|
||||
isLatestVer: false,
|
||||
downloadProgress: null,
|
||||
})
|
||||
export const userApi = reactive({
|
||||
list: [],
|
||||
status: false,
|
||||
message: 'initing',
|
||||
apis: {},
|
||||
})
|
||||
export const sync = window.sync = reactive({
|
||||
enable: false,
|
||||
isShowSyncMode: false,
|
||||
deviceName: '',
|
||||
status: {
|
||||
status: false,
|
||||
message: '',
|
||||
address: [],
|
||||
code: '',
|
||||
devices: [],
|
||||
},
|
||||
})
|
||||
|
||||
export const windowSizeList = markRaw(configWindowSizeList)
|
||||
export const themes = markRaw(configThemes)
|
||||
|
||||
export const qualityList = shallowRef({})
|
||||
export const setQualityList = _qualityList => {
|
||||
qualityList.value = _qualityList
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import { reactive, ref, markRaw } from '@renderer/utils/vueTools'
|
||||
|
||||
// const TEMP_LIST = 'TEMP_LIST'
|
||||
|
||||
export const isInitedList = ref(false)
|
||||
|
||||
export const setInited = () => {
|
||||
isInitedList.value = true
|
||||
}
|
||||
|
||||
export const allList = markRaw({})
|
||||
|
||||
export const allListInit = (defaultList, loveList, tempList, userList) => {
|
||||
for (const id of Object.keys(allList)) {
|
||||
delete allList[id]
|
||||
}
|
||||
allList[defaultList.id] = reactive(defaultList.list)
|
||||
allList[loveList.id] = reactive(loveList.list)
|
||||
allList[tempList.id] = reactive(tempList.list)
|
||||
userLists.splice(0, userLists.length)
|
||||
for (const { list, ...listInfo } of userList) {
|
||||
allList[listInfo.id] = reactive(list)
|
||||
userLists.push(listInfo)
|
||||
}
|
||||
}
|
||||
export const allListUpdate = (id, list) => {
|
||||
if (allList[id]) {
|
||||
allList[id].splice(0, allList[id].length, ...list)
|
||||
} else {
|
||||
allList[id] = list
|
||||
}
|
||||
}
|
||||
export const allListRemove = id => {
|
||||
delete allList[id]
|
||||
}
|
||||
|
||||
export const defaultList = reactive({
|
||||
id: 'default',
|
||||
name: '试听列表',
|
||||
})
|
||||
|
||||
export const loveList = reactive({
|
||||
id: 'love',
|
||||
name: '我的收藏',
|
||||
})
|
||||
|
||||
export const tempList = reactive({
|
||||
id: 'temp',
|
||||
name: '临时列表',
|
||||
})
|
||||
|
||||
export const userLists = reactive([])
|
||||
|
||||
export const addUserList = ({
|
||||
name,
|
||||
id,
|
||||
list,
|
||||
source,
|
||||
sourceListId,
|
||||
position,
|
||||
}) => {
|
||||
if (position == null) {
|
||||
userLists.push({
|
||||
name,
|
||||
id,
|
||||
source,
|
||||
sourceListId,
|
||||
})
|
||||
} else {
|
||||
userLists.splice(position + 1, 0, {
|
||||
name,
|
||||
id,
|
||||
source,
|
||||
sourceListId,
|
||||
})
|
||||
}
|
||||
allListUpdate(id, list)
|
||||
}
|
||||
|
||||
export const updateList = ({
|
||||
name,
|
||||
id,
|
||||
list,
|
||||
source,
|
||||
sourceListId,
|
||||
}) => {
|
||||
let targetList
|
||||
switch (id) {
|
||||
case defaultList.id:
|
||||
case loveList.id:
|
||||
case tempList.id:
|
||||
break
|
||||
default:
|
||||
targetList = userLists.find(l => l.id == id)
|
||||
targetList.name = name
|
||||
targetList.source = source
|
||||
targetList.sourceListId = sourceListId
|
||||
break
|
||||
}
|
||||
allListUpdate(id, list)
|
||||
}
|
||||
|
||||
export const removeUserList = id => {
|
||||
const index = userLists.findIndex(l => l.id == id)
|
||||
if (index < 0) return
|
||||
userLists.splice(index, 1)
|
||||
allListRemove(id)
|
||||
}
|
||||
|
||||
export const getList = id => {
|
||||
return allList[id] ?? []
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { reactive } from '@renderer/utils/vueTools'
|
||||
|
||||
export const lyric = reactive({
|
||||
lines: [],
|
||||
text: '',
|
||||
line: 0,
|
||||
})
|
||||
|
||||
export const setLines = lines => {
|
||||
lyric.lines = lines
|
||||
}
|
||||
export const setText = (text, line) => {
|
||||
lyric.text = text
|
||||
lyric.line = line
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { reactive } from '@renderer/utils/vueTools'
|
||||
import { formatPlayTime2 } from '@renderer/utils'
|
||||
|
||||
export const playProgress = reactive({
|
||||
nowPlayTime: 0,
|
||||
maxPlayTime: 0,
|
||||
progress: 0,
|
||||
nowPlayTimeStr: '00:00',
|
||||
maxPlayTimeStr: '00:00',
|
||||
})
|
||||
|
||||
export const setNowPlayTime = time => {
|
||||
playProgress.nowPlayTime = time
|
||||
playProgress.nowPlayTimeStr = formatPlayTime2(time)
|
||||
playProgress.progress = playProgress.maxPlayTime ? time / playProgress.maxPlayTime : 0
|
||||
}
|
||||
|
||||
export const setMaxplayTime = time => {
|
||||
playProgress.maxPlayTime = time
|
||||
playProgress.maxPlayTimeStr = formatPlayTime2(time)
|
||||
playProgress.progress = time ? playProgress.nowPlayTime / time : 0
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
import { reactive, ref, shallowRef } from '@renderer/utils/vueTools'
|
||||
import { getList } from '@renderer/core/share/utils'
|
||||
|
||||
export const musicInfo = window.musicInfo = reactive({
|
||||
songmid: null,
|
||||
img: null,
|
||||
lrc: null,
|
||||
tlrc: null,
|
||||
lxlrc: null,
|
||||
url: null,
|
||||
name: '',
|
||||
singer: '',
|
||||
album: '',
|
||||
})
|
||||
const musicInfoKeys = Object.keys(musicInfo)
|
||||
export const setMusicInfo = _musicInfo => {
|
||||
for (const key of musicInfoKeys) {
|
||||
if (_musicInfo[key] !== undefined) {
|
||||
musicInfo[key] = _musicInfo[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const musicInfoItem = shallowRef({})
|
||||
export const setMusicInfoItem = musicInfo => {
|
||||
musicInfoItem.value = musicInfo.key ? musicInfo.metadata.musicInfo : musicInfo
|
||||
}
|
||||
|
||||
|
||||
export const isPlay = ref(false)
|
||||
export const setPlay = val => {
|
||||
isPlay.value = val
|
||||
}
|
||||
|
||||
export const status = ref('')
|
||||
export const setStatus = val => {
|
||||
status.value = val
|
||||
}
|
||||
|
||||
|
||||
export const statusText = ref('')
|
||||
export const setStatusText = val => {
|
||||
statusText.value = val
|
||||
}
|
||||
|
||||
export const setAllStatus = val => {
|
||||
status.value = val
|
||||
statusText.value = val
|
||||
}
|
||||
|
||||
|
||||
export const isShowPlayerDetail = ref(false)
|
||||
export const setShowPlayerDetail = val => {
|
||||
isShowPlayerDetail.value = val
|
||||
}
|
||||
|
||||
export const isShowPlayComment = ref(false)
|
||||
export const setShowPlayComment = val => {
|
||||
isShowPlayComment.value = val
|
||||
}
|
||||
|
||||
export const isShowLrcSelectContent = ref(false)
|
||||
export const setShowPlayLrcSelectContentLrc = val => {
|
||||
isShowLrcSelectContent.value = val
|
||||
}
|
||||
|
||||
|
||||
export const playMusicInfo = reactive({
|
||||
listId: null, // 当前播放歌曲的列表 id
|
||||
musicInfo: null, // 当前播放歌曲的歌曲信息
|
||||
isTempPlay: false, // 是否属于 “稍后播放”
|
||||
})
|
||||
export const playInfo = reactive({
|
||||
playIndex: -1, // 当前正在播放歌曲 index
|
||||
playListId: null, // 播放器的播放列表 id
|
||||
listPlayIndex: -1, // 播放器播放歌曲 index
|
||||
})
|
||||
|
||||
// 设置播放器的播放列表
|
||||
export const setPlayList = listId => {
|
||||
playInfo.playListId = listId
|
||||
}
|
||||
|
||||
// 更新播放位置
|
||||
export const updatePlayIndex = () => {
|
||||
const indexInfo = getPlayIndex(playMusicInfo.listId, playMusicInfo.musicInfo, playMusicInfo.isTempPlay)
|
||||
// console.log(indexInfo)
|
||||
playInfo.playIndex = indexInfo.playIndex
|
||||
playInfo.listPlayIndex = indexInfo.listPlayIndex
|
||||
|
||||
return indexInfo
|
||||
}
|
||||
|
||||
export const getPlayIndex = (listId, musicInfo, isTempPlay) => {
|
||||
const playerList = getList(playInfo.playListId)
|
||||
|
||||
// if (listIndex < 0) throw new Error('music info not found')
|
||||
// playInfo.playIndex = listIndex
|
||||
|
||||
let playIndex = -1
|
||||
let listPlayIndex = -1
|
||||
if (playerList?.length) {
|
||||
listPlayIndex = Math.min(playInfo.listPlayIndex, playerList.length - 1)
|
||||
}
|
||||
|
||||
const list = getList(listId)
|
||||
if (list?.length) {
|
||||
if (musicInfo.key) { // 已下载的歌曲
|
||||
const currentKey = musicInfo.key
|
||||
playIndex = list.findIndex(m => m.key == currentKey)
|
||||
} else {
|
||||
const currentSongmid = musicInfo.songmid
|
||||
playIndex = list.findIndex(m => m.songmid == currentSongmid)
|
||||
}
|
||||
if (!isTempPlay) {
|
||||
if (playIndex < 0) {
|
||||
listPlayIndex = listPlayIndex < 1 ? (list.length - 1) : (listPlayIndex - 1)
|
||||
} else {
|
||||
listPlayIndex = playIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
playIndex,
|
||||
listPlayIndex,
|
||||
}
|
||||
}
|
||||
|
||||
// 设置当前播放歌曲的信息
|
||||
export const setPlayMusicInfo = (listId, musicInfo, isTempPlay = false) => {
|
||||
playMusicInfo.listId = listId
|
||||
playMusicInfo.musicInfo = musicInfo
|
||||
playMusicInfo.isTempPlay = isTempPlay
|
||||
if (musicInfo == null) {
|
||||
playInfo.playIndex = -1
|
||||
playInfo.playListId = null
|
||||
playInfo.listPlayIndex = -1
|
||||
return
|
||||
}
|
||||
|
||||
const { playIndex, listPlayIndex } = getPlayIndex(listId, musicInfo, isTempPlay)
|
||||
|
||||
playInfo.playIndex = playIndex
|
||||
playInfo.listPlayIndex = listPlayIndex
|
||||
|
||||
setMusicInfoItem(musicInfo)
|
||||
// console.log(playInfo)
|
||||
}
|
||||
|
||||
export const playedList = window.playedList = reactive([])
|
||||
export const addPlayedList = (item) => {
|
||||
if (playedList.some(m => m.musicInfo === item.musicInfo)) return
|
||||
playedList.push(item)
|
||||
}
|
||||
export const removePlayedList = (index) => {
|
||||
playedList.splice(index, 1)
|
||||
}
|
||||
export const clearPlayedList = () => {
|
||||
playedList.splice(0, playedList.length)
|
||||
}
|
||||
|
||||
export const tempPlayList = reactive([])
|
||||
export const addTempPlayList = (list) => {
|
||||
tempPlayList.push(...list.map(({ musicInfo, listId }) => ({ musicInfo, listId, isTempPlay: true })))
|
||||
}
|
||||
export const removeTempPlayList = (index) => {
|
||||
tempPlayList.splice(index, 1)
|
||||
}
|
||||
export const clearTempPlayeList = () => {
|
||||
tempPlayList.splice(0, tempPlayList.length)
|
||||
}
|
||||
|
||||
window.playInfo = playInfo
|
||||
window.playMusicInfo = playMusicInfo
|
||||
@@ -0,0 +1,7 @@
|
||||
import { getList as getMyList } from './list'
|
||||
import { downloadList } from './download'
|
||||
|
||||
|
||||
export const getList = listId => {
|
||||
return listId == 'download' ? downloadList : getMyList(listId)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { ref } from '@renderer/utils/vueTools'
|
||||
|
||||
|
||||
export const volume = ref(0)
|
||||
export const isMute = ref(false)
|
||||
|
||||
export const setVolume = num => {
|
||||
volume.value = num
|
||||
}
|
||||
|
||||
export const setMute = flag => {
|
||||
isMute.value = flag
|
||||
}
|
||||
Reference in New Issue
Block a user