diff --git a/publish/changeLog.md b/publish/changeLog.md index 52cb198b..697b4bac 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -1,3 +1,6 @@ +### 新增 + +- 直接从歌单详情收藏的列表新增同步功能。注意:这将会覆盖本地的目标列表,歌曲将被替换成最新的在线列表 ### 修复 diff --git a/src/renderer/App.vue b/src/renderer/App.vue index 01ccc8b3..c14726f9 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -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 = [] diff --git a/src/renderer/lang/en-us/view/list.json b/src/renderer/lang/en-us/view/list.json index 8a23de01..37809cf7 100644 --- a/src/renderer/lang/en-us/view/list.json +++ b/src/renderer/lang/en-us/view/list.json @@ -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", diff --git a/src/renderer/lang/zh-cn/view/list.json b/src/renderer/lang/zh-cn/view/list.json index e53c3460..87778d88 100644 --- a/src/renderer/lang/zh-cn/view/list.json +++ b/src/renderer/lang/zh-cn/view/list.json @@ -4,6 +4,7 @@ "lists_rename": "重命名", "lists_moveup": "上移", "lists_movedown": "下移", + "lists_sync": "同步", "lists_remove": "删除", "list_play": "播放", "list_copy_name": "复制歌曲名", diff --git a/src/renderer/lang/zh-tw/view/list.json b/src/renderer/lang/zh-tw/view/list.json index 52612a8c..1f218c54 100644 --- a/src/renderer/lang/zh-tw/view/list.json +++ b/src/renderer/lang/zh-tw/view/list.json @@ -4,6 +4,7 @@ "lists_rename": "重命名", "lists_moveup": "上移", "lists_movedown": "下移", + "lists_sync": "同步", "lists_remove": "刪除", "list_play": "播放", "list_copy_name": "複製歌曲名", diff --git a/src/renderer/store/modules/list.js b/src/renderer/store/modules/list.js index eb9e51cf..9df804c3 100644 --- a/src/renderer/store/modules/list.js +++ b/src/renderer/store/modules/list.js @@ -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) diff --git a/src/renderer/store/modules/songList.js b/src/renderer/store/modules/songList.js index da1b3959..406db827 100644 --- a/src/renderer/store/modules/songList.js +++ b/src/renderer/store/modules/songList.js @@ -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) diff --git a/src/renderer/views/List.vue b/src/renderer/views/List.vue index 251e2b2a..7afb79e3 100644 --- a/src/renderer/views/List.vue +++ b/src/renderer/views/List.vue @@ -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, + }) + }, }, } diff --git a/src/renderer/views/SongList.vue b/src/renderer/views/SongList.vue index af6e3168..2c1b5cda 100644 --- a/src/renderer/views/SongList.vue +++ b/src/renderer/views/SongList.vue @@ -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