From a2f7547cdbd24dce69df5087a7f9ce36b27c061a Mon Sep 17 00:00:00 2001 From: lyswhut Date: Mon, 2 Sep 2019 00:57:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=AD=8C=E5=8D=95=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3bug=EF=BC=8C=E5=AE=8C=E5=96=84=E6=AD=8C=E5=8D=95?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/components/material/SongList.vue | 1 + src/renderer/store/modules/songList.js | 11 ++-- src/renderer/store/mutations.js | 7 +- src/renderer/utils/index.js | 4 +- src/renderer/utils/music/bd/songList.js | 12 ++-- src/renderer/utils/music/kg/songList.js | 65 +++++++++---------- src/renderer/utils/music/kw/songList.js | 32 +++++---- src/renderer/views/Leaderboard.vue | 2 +- src/renderer/views/SongList.vue | 58 +++++++---------- 9 files changed, 86 insertions(+), 106 deletions(-) diff --git a/src/renderer/components/material/SongList.vue b/src/renderer/components/material/SongList.vue index 036b4c58..de87a1ac 100644 --- a/src/renderer/components/material/SongList.vue +++ b/src/renderer/components/material/SongList.vue @@ -42,6 +42,7 @@ div(:class="$style.songList") import { mapGetters } from 'vuex' import { scrollTo } from '../../utils' export default { + name: 'MaterialSongList', model: { prop: 'selectdData', event: 'input', diff --git a/src/renderer/store/modules/songList.js b/src/renderer/store/modules/songList.js index f9f66c34..28c83bd1 100644 --- a/src/renderer/store/modules/songList.js +++ b/src/renderer/store/modules/songList.js @@ -43,15 +43,15 @@ const getters = { const actions = { getTags({ state, rootState, commit }) { let source = rootState.setting.songList.source - return music[source].songList.getTags().then(result => commit('setTags', { result, source })) + return music[source].songList.getTags().then(result => commit('setTags', { tags: result, source })) }, getList({ state, rootState, commit }, page) { let source = rootState.setting.songList.source - let tabId = rootState.setting.songList.sortId - let sortType = rootState.setting.songList.sortType - let key = `${source}${sortType}${tabId}${page}}` + let tabId = rootState.setting.songList.tagId + let sortId = rootState.setting.songList.sortId + let key = `${source}${sortId}${tabId}${page}` if (state.list.list.length && state.list.key == key) return true - return music[source].songList.getList(sortType, tabId, page).then(result => commit('setList', { result, key })) + return music[source].songList.getList(sortId, tabId, page).then(result => commit('setList', { result, key })) }, getListDetail({ state, rootState, commit }, { id, page }) { let source = rootState.setting.songList.source @@ -72,6 +72,7 @@ const mutations = { state.list.limit = result.limit state.list.page = result.page state.list.key = key + console.log(result) }, setListDetail(state, { result, key }) { state.listDetail.list = result.list diff --git a/src/renderer/store/mutations.js b/src/renderer/store/mutations.js index 2b46854b..5988335c 100644 --- a/src/renderer/store/mutations.js +++ b/src/renderer/store/mutations.js @@ -12,9 +12,10 @@ export default { if (tabId != null) state.setting.leaderboard.tabId = tabId if (source != null) state.setting.leaderboard.source = source }, - setSongList(state, { sortId, source }) { - if (sortId != null) state.setting.leaderboard.sortId = sortId - if (source != null) state.setting.leaderboard.source = source + setSongList(state, { sortId, tagId, source }) { + if (tagId != null) state.setting.songList.tagId = tagId + if (sortId != null) state.setting.songList.sortId = sortId + if (source != null) state.setting.songList.source = source }, setNewVersion(state, val) { // val.history.forEach(ver => { diff --git a/src/renderer/utils/index.js b/src/renderer/utils/index.js index cbd60f5a..47bf0dfa 100644 --- a/src/renderer/utils/index.js +++ b/src/renderer/utils/index.js @@ -185,8 +185,8 @@ export const updateSetting = setting => { }, songList: { source: 'kw', - sortId: 'kwhot', - tagId: '', + sortId: 'hot', + tagId: null, }, themeId: 0, sourceId: 'kw', diff --git a/src/renderer/utils/music/bd/songList.js b/src/renderer/utils/music/bd/songList.js index 8d718320..54344f94 100644 --- a/src/renderer/utils/music/bd/songList.js +++ b/src/renderer/utils/music/bd/songList.js @@ -13,13 +13,11 @@ export default { sortList: [ { name: '最热', - tabId: 'bdhot', - id: '最热', + id: '1', }, { name: '最新', - tabId: 'bdnew', - id: '最新', + id: '0', }, ], aesPassEncod(jsonData) { @@ -91,7 +89,7 @@ export default { }, getListUrl(sortType, tagName, page) { return this.createUrl({ - channelname: tagName, + channelname: tagName || '全部', from: 'qianqianmini', offset: (page - 1) * this.limit_list, order_type: sortType, @@ -116,8 +114,8 @@ export default { return this._requestObj_tags.promise.then(({ body }) => { if (body.error_code !== this.successCode) return this.getTags() return { - hotTag: this.filterInfoHotTag(body.data.hot), - tags: this.filterTagInfo(body.data.tags), + hotTag: this.filterInfoHotTag(body.result.hot), + tags: this.filterTagInfo(body.result.tags), } }) }, diff --git a/src/renderer/utils/music/kg/songList.js b/src/renderer/utils/music/kg/songList.js index 89dc0675..76b89433 100644 --- a/src/renderer/utils/music/kg/songList.js +++ b/src/renderer/utils/music/kg/songList.js @@ -2,37 +2,34 @@ import { httpFatch } from '../../request' import { formatPlayTime, sizeFormate } from '../../index' export default { - _requestObj_tagInfo: null, + _requestObj_tags: null, + _requestObj_listInfo: null, _requestObj_list: null, + _requestObj_listRecommend: null, _requestObj_listDetail: null, currentTagInfo: { - id: null, - info: null, + id: undefined, + info: undefined, }, sortList: [ { name: '推荐', - tabId: 'kgrecommend', id: '5', }, { name: '最热', - tabId: 'kghot', id: '6', }, { name: '最新', - tabId: 'kgnew', id: '7', }, { name: '热藏', - tabId: 'kghotcollect', id: '3', }, { name: '飙升', - tabId: 'kgup', id: '8', }, ], @@ -44,7 +41,7 @@ export default { ? `http://www2.kugou.kugou.com/yueku/v9/special/getSpecial?is_smarty=1&cdn=cdn&t=5&c=${tagId}` : `http://www2.kugou.kugou.com/yueku/v9/special/getSpecial?is_smarty=1&` }, - getSongListUrl(sortId, tagId, page) { + getSongListUrl(sortId, tagId = '', page) { return `http://www2.kugou.kugou.com/yueku/v9/special/index/getData/getData.html&cdn=cdn&t=${sortId}&c=${tagId}?is_ajax=1&p=${page}` }, getSongListDetailUrl(id) { @@ -52,26 +49,13 @@ export default { }, getTagInfo(tagId) { - if (this._requestObj_tagInfo) this._requestObj_tagInfo.cancelHttp() - this._requestObj_tagInfo = httpFatch(this.getInfoUrl(tagId)) - return this._requestObj_tagInfo.promise.then(({ body }) => { - if (body.status !== 1) return this.getTagInfo(tagId) - return { - hotTag: this.filterInfoHotTag(body.data.hotTag), - tags: this.filterTagInfo(body.data.tagids), - tagInfo: { - limit: body.data.params.pagesize, - page: body.data.params.p, - total: body.data.params.total, - }, - } - }) + }, filterInfoHotTag(rawData) { const result = [] if (rawData.status !== 1) return result - for (let index = 0; index < Object.keys(rawData.data).lengt; index++) { - let tag = rawData.data[index.toString()] + for (const key of Object.keys(rawData.data)) { + let tag = rawData.data[key] result.push({ id: tag.id, name: tag.special_name, @@ -92,6 +76,7 @@ export default { })), }) } + return result }, getSongList(sortId, tagId, page) { @@ -101,12 +86,12 @@ export default { ) return this._requestObj_list.promise.then(({ body }) => { if (body.status !== 1) return this.getSongList(sortId, tagId, page) - return this.filterList(body.data) + return this.filterList(body.special_db) }) }, getSongListRecommend() { if (this._requestObj_listRecommend) this._requestObj_listRecommend.cancelHttp() - this._requestObj_listRecommendRecommend = httpFatch( + this._requestObj_listRecommend = httpFatch( 'http://everydayrec.service.kugou.com/guess_special_recommend', { method: 'post', @@ -127,7 +112,8 @@ export default { } ) return this._requestObj_listRecommend.promise.then(({ body }) => { - if (body.status !== 1) return this.getSongListRecommend() + // if (body.status !== 1) return this.getSongListRecommend() + if (body.status !== 1) return [] return this.filterList(body.data) }) }, @@ -215,11 +201,14 @@ export default { // 获取列表信息 getListInfo(tagId) { - return this.getTagInfo(tagId).then(info => { + if (this._requestObj_listInfo) this._requestObj_listInfo.cancelHttp() + this._requestObj_listInfo = httpFatch(this.getInfoUrl(tagId)) + return this._requestObj_listInfo.promise.then(({ body }) => { + if (body.status !== 1) return this.getListInfo(tagId) return { - limit: info.tagInfo.limit, - page: info.tagInfo.page, - total: info.tagInfo.total, + limit: body.data.params.pagesize, + page: body.data.params.p, + total: body.data.params.total, } }) }, @@ -237,8 +226,9 @@ export default { }) ) if (!tagId) tasks.push(this.getSongListRecommend()) // 如果是所有类别,则顺便获取推荐列表 - Promise.all(tasks).then(([list, info, recommendList]) => { + return Promise.all(tasks).then(([list, info, recommendList]) => { if (recommendList) list.unshift(...recommendList) + console.log(info) return { list, ...info, @@ -248,10 +238,13 @@ export default { // 获取标签 getTags() { - return this.getTagInfo().then(info => { + if (this._requestObj_tags) this._requestObj_tags.cancelHttp() + this._requestObj_tags = httpFatch(this.getInfoUrl()) + return this._requestObj_tags.promise.then(({ body }) => { + if (body.status !== 1) return this.getTags() return { - hotTag: info.hotTag, - tags: info.tags, + hotTag: this.filterInfoHotTag(body.data.hotTag), + tags: this.filterTagInfo(body.data.tagids), } }) }, diff --git a/src/renderer/utils/music/kw/songList.js b/src/renderer/utils/music/kw/songList.js index 0b43de52..0f2908c4 100644 --- a/src/renderer/utils/music/kw/songList.js +++ b/src/renderer/utils/music/kw/songList.js @@ -13,43 +13,41 @@ export default { sortList: [ { name: '最热', - tabId: 'kwhot', id: 'hot', }, { name: '最新', - tabId: 'kwnew', id: 'new', }, ], tagsUrl: 'http://wapi.kuwo.cn/api/pc/classify/playlist/getTagList?cmd=rcm_keyword_playlist&user=0&prod=kwplayer_pc_9.0.5.0&vipver=9.0.5.0&source=kwplayer_pc_9.0.5.0&loginUid=0&loginSid=0&appUid=76039576', hotTagUrl: 'http://wapi.kuwo.cn/api/pc/classify/playlist/getRcmTagList?loginUid=0&loginSid=0&appUid=76039576', - getListUrl({ sortType, id, page }) { + getListUrl({ sortId, id, page }) { return id - ? `http://wapi.kuwo.cn/api/pc/classify/playlist/getTagPlayList?loginUid=0&loginSid=0&appUid=76039576&id=${id}&pn=${page}&rn=${this.limit}` - : `http://wapi.kuwo.cn/api/pc/classify/playlist/getRcmPlayList?loginUid=0&loginSid=0&appUid=76039576&pn=${page}&rn=${this.limit}&order=${sortType}` + ? `http://wapi.kuwo.cn/api/pc/classify/playlist/getTagPlayList?loginUid=0&loginSid=0&appUid=76039576&id=${id}&pn=${page}&rn=${this.limit_list}` + : `http://wapi.kuwo.cn/api/pc/classify/playlist/getRcmPlayList?loginUid=0&loginSid=0&appUid=76039576&pn=${page}&rn=${this.limit_list}&order=${sortId}` }, getListDetailUrl(id, page) { - return `http://nplserver.kuwo.cn/pl.svc?op=getlistinfo&pid=${id}&pn=${page - 1}&rn=${this.limit}&encode=utf8&keyset=pl2012&identity=kuwo&pcmp4=1&vipver=MUSIC_9.0.5.0_W1&newver=1` + return `http://nplserver.kuwo.cn/pl.svc?op=getlistinfo&pid=${id}&pn=${page - 1}&rn=${this.limit_song}&encode=utf8&keyset=pl2012&identity=kuwo&pcmp4=1&vipver=MUSIC_9.0.5.0_W1&newver=1` }, // 获取标签 - getTags() { + getTag() { if (this._requestObj_tags) this._requestObj_tags.cancelHttp() this._requestObj_tags = httpFatch(this.tagsUrl) return this._requestObj_tags.promise.then(({ body }) => { - if (body.code !== this.successCode) return this.getTags() - return this.filterTagInfo(body.data.tags) + if (body.code !== this.successCode) return this.getTag() + return this.filterTagInfo(body.data) }) }, // 获取标签 - getHotTags() { + getHotTag() { if (this._requestObj_hotTags) this._requestObj_hotTags.cancelHttp() this._requestObj_hotTags = httpFatch(this.hotTagUrl) return this._requestObj_hotTags.promise.then(({ body }) => { - if (body.code !== this.successCode) return this.getHotTags() - return this.filterInfoHotTag(body.data.data) + if (body.code !== this.successCode) return this.getHotTag() + return this.filterInfoHotTag(body.data[0].data) }) }, filterInfoHotTag(rawList) { @@ -73,11 +71,9 @@ export default { // 获取列表数据 getList(sortId, tagId, page) { if (this._requestObj_list) this._requestObj_list.cancelHttp() - this._requestObj_list = httpFatch( - this.getListUrl({ sortId, id: tagId, page }) - ) + this._requestObj_list = httpFatch(this.getListUrl({ sortId, id: tagId, page })) return this._requestObj_list.promise.then(({ body }) => { - if (body.code !== this.successCode) return this.getList({ sortId, id: tagId, page }) + if (body.code !== this.successCode) return this.getListUrl({ sortId, id: tagId, page }) return { list: this.filterList(body.data.data), total: body.data.total, @@ -167,7 +163,9 @@ export default { } }) }, - + getTags() { + return Promise.all([this.getTag(), this.getHotTag()]).then(([tags, hotTag]) => ({ tags, hotTag })) + }, } // getList diff --git a/src/renderer/views/Leaderboard.vue b/src/renderer/views/Leaderboard.vue index 585ee41c..a26a9d94 100644 --- a/src/renderer/views/Leaderboard.vue +++ b/src/renderer/views/Leaderboard.vue @@ -3,7 +3,7 @@ div(:class="$style.header") material-tab(:class="$style.tab" :list="types" item-key="id" item-name="name" v-model="tabId") material-select(:class="$style.select" :list="sourceInfo.sources" item-key="id" item-name="name" v-model="source") - material-song-list(v-model="selectdData" @action="handleSongListAction" :source="source" :page="page" :limit="info.limit" :total="info.total" :list="list") + material-song-list(v-model="selectdData" noItem="列表加载中..." @action="handleSongListAction" :source="source" :page="page" :limit="info.limit" :total="info.total" :list="list") material-download-modal(:show="isShowDownload" :musicInfo="musicInfo" @select="handleAddDownload" @close="isShowDownload = false") material-download-multiple-modal(:show="isShowDownloadMultiple" :list="selectdData" @select="handleAddDownloadMultiple" @close="isShowDownloadMultiple = false") diff --git a/src/renderer/views/SongList.vue b/src/renderer/views/SongList.vue index e9c9b582..7989fd81 100644 --- a/src/renderer/views/SongList.vue +++ b/src/renderer/views/SongList.vue @@ -1,8 +1,8 @@ @@ -12,31 +12,27 @@ import { mapGetters, mapMutations, mapActions } from 'vuex' import { scrollTo } from '../utils' // import music from '../utils/music' export default { - name: 'Leaderboard', + name: 'SongList', data() { return { tagId: null, - sortId: null, + sortId: undefined, source: null, listPage: 1, songListPage: 1, - clickTime: 0, - clickIndex: -1, isShowDownload: false, musicInfo: null, selectdData: [], - isSelectAll: false, - isIndeterminate: false, - isShowEditBtn: false, isShowDownloadMultiple: false, + isToggleSource: false, } }, computed: { ...mapGetters(['setting']), ...mapGetters('songList', ['sourceInfo', 'tags', 'listData', 'listDetail']), ...mapGetters('list', ['defaultList']), - types() { - return this.source ? this.sourceInfo.sources[this.source] : [] + sorts() { + return this.source ? this.sourceInfo.sortList[this.source] : [] }, isAPITemp() { return this.setting.apiSource == 'temp' @@ -45,47 +41,39 @@ export default { watch: { sortId(n, o) { this.setSongList({ sortId: n }) - if (!o && this.listPage !== 1) return + console.log(n) + if (o === undefined && this.listPage !== 1) return this.getList(1).then(() => { - this.listPage = this.info.listPage - scrollTo(this.$refs.dom_scrollContent, 0) + this.listPage = this.listData.listPage }) }, tagId(n, o) { - this.setSongList({ sortId: n }) - if (!o && this.songListPage !== 1) return + this.setSongList({ tagId: n }) + if (!o && this.listPage !== 1) return + if (this.isToggleSource) { + this.isToggleSource = false + return + } this.getList(1).then(() => { - this.songListPage = this.info.songListPage - scrollTo(this.$refs.dom_scrollContent, 0) + this.listPage = this.listData.listPage }) }, source(n, o) { this.setSongList({ source: n }) + if (!this.tags[n]) this.getTags() if (o) { - this.tagId = this.tags[0] && this.tags[0].id - this.sortType = this.sortList[0] && this.sortList[0].id + this.isToggleSource = true + this.tagId = null + this.sortId = this.sorts[0] && this.sorts[0].id } }, - selectdData(n) { - const len = n.length - if (len) { - this.isSelectAll = true - this.isIndeterminate = len !== this.list.length - this.isShowEditBtn = true - } else { - this.isSelectAll = false - this.isShowEditBtn = false - } - }, - list() { - this.resetSelect() - }, }, mounted() { this.source = this.setting.songList.source - // this.sortId = this.setting.songList.sortId + this.tagId = this.setting.songList.tagId this.listPage = this.listData.page this.songListPage = this.listDetail.page + this.sortId = this.setting.songList.sortId }, methods: { ...mapMutations(['setSongList']),