直接从歌单详情收藏的列表新增同步功能

pull/392/head
lyswhut 2020-12-10 12:57:48 +08:00
parent 2056bdb43d
commit f1049169b5
9 changed files with 86 additions and 10 deletions

View File

@ -1,3 +1,6 @@
### 新增
- 直接从歌单详情收藏的列表新增同步功能。注意:这将会覆盖本地的目标列表,歌曲将被替换成最新的在线列表
### 修复

View File

@ -273,7 +273,21 @@ export default {
getPlayList().then(({ defaultList, loveList, userList, downloadList }) => {
if (!defaultList) defaultList = this.defaultList
if (!loveList) loveList = this.loveList
if (!userList) userList = this.userList
if (userList) {
let needSave = false
const getListId = id => id.includes('.') ? getListId(id.substring(0, id.lastIndexOf('_'))) : id
userList.forEach(l => {
if (!l.id.includes('__') || l.source) return
let [source, id] = l.id.split('__')
id = getListId(id)
l.source = source
l.sourceListId = id
if (!needSave) needSave = true
})
if (needSave) this.this.saveUserList(userList)
} else {
userList = this.userList
}
if (!defaultList.list) defaultList.list = []
if (!loveList.list) loveList.list = []

View File

@ -4,6 +4,7 @@
"lists_rename": "Rename",
"lists_moveup": "Move Up",
"lists_movedown": "Move Down",
"lists_sync": "Sync",
"lists_remove": "Remove",
"list_play": "Play",
"list_copy_name": "Copy name",

View File

@ -4,6 +4,7 @@
"lists_rename": "重命名",
"lists_moveup": "上移",
"lists_movedown": "下移",
"lists_sync": "同步",
"lists_remove": "删除",
"list_play": "播放",
"list_copy_name": "复制歌曲名",

View File

@ -4,6 +4,7 @@
"lists_rename": "重命名",
"lists_moveup": "上移",
"lists_movedown": "下移",
"lists_sync": "同步",
"lists_remove": "刪除",
"list_play": "播放",
"list_copy_name": "複製歌曲名",

View File

@ -60,7 +60,7 @@ const mutations = {
allListInit(state.defaultList, state.loveList, state.userList)
state.isInitedList = true
},
setList(state, { id, list, name, location }) {
setList(state, { id, list, name, location, source, sourceListId }) {
const targetList = allList[id]
if (targetList) {
if (name && targetList.name === name) {
@ -76,6 +76,8 @@ const mutations = {
id,
list,
location,
source,
sourceListId,
}
state.userList.push(newList)
allListUpdate(newList)
@ -145,7 +147,7 @@ const mutations = {
if (!targetList) return
Object.assign(targetList.list[index], data)
},
createUserList(state, { name, id = `userlist_${Date.now()}`, list = [] }) {
createUserList(state, { name, id = `userlist_${Date.now()}`, list = [], source, sourceListId }) {
let newList = state.userList.find(item => item.id === id)
if (!newList) {
newList = {
@ -153,6 +155,8 @@ const mutations = {
id,
list: [],
location: 0,
source,
sourceListId,
}
state.userList.push(newList)
allListUpdate(newList)

View File

@ -81,8 +81,8 @@ const actions = {
: music[source].songList.getListDetail(id, page)
).then(result => commit('setListDetail', { result, key, source, id, page }))
},
getListDetailAll({ state, rootState }, id) {
let source = rootState.setting.songList.source
getListDetailAll({ state, rootState }, { source, id }) {
// console.log(source, id)
const loadData = (id, page) => {
let key = `sdetail__${source}__${id}__${page}`
return cache.has(key)

View File

@ -100,6 +100,7 @@ export default {
isShowItemMenu: false,
itemMenuControl: {
rename: true,
sync: false,
moveup: true,
movedown: true,
remove: true,
@ -131,6 +132,7 @@ export default {
isMove: false,
isMoveMultiple: false,
isVisibleMusicSearch: false,
fetchingListStatus: {},
}
},
computed: {
@ -180,6 +182,11 @@ export default {
action: 'rename',
disabled: !this.listsData.itemMenuControl.rename,
},
{
name: this.$t('view.list.lists_sync'),
action: 'sync',
disabled: !this.listsData.itemMenuControl.sync,
},
{
name: this.$t('view.list.lists_moveup'),
action: 'moveup',
@ -309,7 +316,18 @@ export default {
},
methods: {
...mapMutations(['setPrevSelectListId']),
...mapMutations('list', ['listRemove', 'listRemoveMultiple', 'setUserListName', 'createUserList', 'moveupUserList', 'movedownUserList', 'removeUserList', 'setListScroll']),
...mapMutations('list', [
'listRemove',
'listRemoveMultiple',
'setUserListName',
'createUserList',
'moveupUserList',
'movedownUserList',
'removeUserList',
'setListScroll',
'setList',
]),
...mapActions('songList', ['getListDetailAll']),
...mapActions('download', ['createDownload', 'createDownloadMultiple']),
...mapMutations('player', {
setPlayList: 'setList',
@ -668,6 +686,8 @@ export default {
}).catch(_ => _)
},
handleListsItemRigthClick(event, index) {
const source = this.userList[index].source
this.listsData.itemMenuControl.sync = !!source && !!musicSdk[source].songList
this.listsData.itemMenuControl.moveup = index > 0
this.listsData.itemMenuControl.movedown = index < this.userList.length - 1
this.listsData.rightClickItemIndex = index
@ -714,6 +734,9 @@ export default {
dom.querySelector('input').focus()
})
break
case 'sync':
this.handleSyncSourceList(index)
break
case 'moveup':
this.moveupUserList(index)
break
@ -814,6 +837,27 @@ export default {
break
}
},
fetchList(id, source, sourceListId) {
if (this.fetchingListStatus[id] == null) {
this.$set(this.fetchingListStatus, id, true)
} else {
this.fetchingListStatus[id] = true
}
return this.getListDetailAll({ source, id: sourceListId }).catch(err => {
return Promise.reject(err)
}).finally(() => {
this.fetchingListStatus[id] = false
})
},
async handleSyncSourceList(index) {
const targetList = this.userList[index]
const list = await this.fetchList(targetList.id, targetList.source, targetList.sourceListId)
// console.log(targetList.list.length, list.length)
this.setList({
...targetList,
list,
})
},
},
}
</script>

View File

@ -405,14 +405,22 @@ export default {
},
async fetchList() {
this.detailLoading = true
const list = await this.getListDetailAll(this.selectListInfo.id)
this.detailLoading = false
return list
return this.getListDetailAll({ source: this.source, id: this.selectListInfo.id }).catch(err => {
return Promise.reject(err)
}).finally(() => {
this.detailLoading = false
})
},
async addSongListDetail() {
if (!this.listDetail.info.name) return
const list = await this.fetchList()
this.createUserList({ name: this.listDetail.info.name, id: `${this.listDetail.source}__${this.listDetail.id}`, list })
this.createUserList({
name: this.listDetail.info.name,
id: `${this.listDetail.source}__${this.listDetail.id}`,
list,
source: this.listDetail.source,
sourceListId: this.listDetail.id,
})
},
async playSongListDetail() {
if (!this.listDetail.info.name) return