修复歌单接口bug,完善歌单页面

pull/96/head
lyswhut 2019-09-02 00:57:57 +08:00
parent d48308d913
commit a2f7547cdb
9 changed files with 86 additions and 106 deletions

View File

@ -42,6 +42,7 @@ div(:class="$style.songList")
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import { scrollTo } from '../../utils' import { scrollTo } from '../../utils'
export default { export default {
name: 'MaterialSongList',
model: { model: {
prop: 'selectdData', prop: 'selectdData',
event: 'input', event: 'input',

View File

@ -43,15 +43,15 @@ const getters = {
const actions = { const actions = {
getTags({ state, rootState, commit }) { getTags({ state, rootState, commit }) {
let source = rootState.setting.songList.source 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) { getList({ state, rootState, commit }, page) {
let source = rootState.setting.songList.source let source = rootState.setting.songList.source
let tabId = rootState.setting.songList.sortId let tabId = rootState.setting.songList.tagId
let sortType = rootState.setting.songList.sortType let sortId = rootState.setting.songList.sortId
let key = `${source}${sortType}${tabId}${page}}` let key = `${source}${sortId}${tabId}${page}`
if (state.list.list.length && state.list.key == key) return true 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 }) { getListDetail({ state, rootState, commit }, { id, page }) {
let source = rootState.setting.songList.source let source = rootState.setting.songList.source
@ -72,6 +72,7 @@ const mutations = {
state.list.limit = result.limit state.list.limit = result.limit
state.list.page = result.page state.list.page = result.page
state.list.key = key state.list.key = key
console.log(result)
}, },
setListDetail(state, { result, key }) { setListDetail(state, { result, key }) {
state.listDetail.list = result.list state.listDetail.list = result.list

View File

@ -12,9 +12,10 @@ export default {
if (tabId != null) state.setting.leaderboard.tabId = tabId if (tabId != null) state.setting.leaderboard.tabId = tabId
if (source != null) state.setting.leaderboard.source = source if (source != null) state.setting.leaderboard.source = source
}, },
setSongList(state, { sortId, source }) { setSongList(state, { sortId, tagId, source }) {
if (sortId != null) state.setting.leaderboard.sortId = sortId if (tagId != null) state.setting.songList.tagId = tagId
if (source != null) state.setting.leaderboard.source = source if (sortId != null) state.setting.songList.sortId = sortId
if (source != null) state.setting.songList.source = source
}, },
setNewVersion(state, val) { setNewVersion(state, val) {
// val.history.forEach(ver => { // val.history.forEach(ver => {

View File

@ -185,8 +185,8 @@ export const updateSetting = setting => {
}, },
songList: { songList: {
source: 'kw', source: 'kw',
sortId: 'kwhot', sortId: 'hot',
tagId: '', tagId: null,
}, },
themeId: 0, themeId: 0,
sourceId: 'kw', sourceId: 'kw',

View File

@ -13,13 +13,11 @@ export default {
sortList: [ sortList: [
{ {
name: '最热', name: '最热',
tabId: 'bdhot', id: '1',
id: '最热',
}, },
{ {
name: '最新', name: '最新',
tabId: 'bdnew', id: '0',
id: '最新',
}, },
], ],
aesPassEncod(jsonData) { aesPassEncod(jsonData) {
@ -91,7 +89,7 @@ export default {
}, },
getListUrl(sortType, tagName, page) { getListUrl(sortType, tagName, page) {
return this.createUrl({ return this.createUrl({
channelname: tagName, channelname: tagName || '全部',
from: 'qianqianmini', from: 'qianqianmini',
offset: (page - 1) * this.limit_list, offset: (page - 1) * this.limit_list,
order_type: sortType, order_type: sortType,
@ -116,8 +114,8 @@ export default {
return this._requestObj_tags.promise.then(({ body }) => { return this._requestObj_tags.promise.then(({ body }) => {
if (body.error_code !== this.successCode) return this.getTags() if (body.error_code !== this.successCode) return this.getTags()
return { return {
hotTag: this.filterInfoHotTag(body.data.hot), hotTag: this.filterInfoHotTag(body.result.hot),
tags: this.filterTagInfo(body.data.tags), tags: this.filterTagInfo(body.result.tags),
} }
}) })
}, },

View File

@ -2,37 +2,34 @@ import { httpFatch } from '../../request'
import { formatPlayTime, sizeFormate } from '../../index' import { formatPlayTime, sizeFormate } from '../../index'
export default { export default {
_requestObj_tagInfo: null, _requestObj_tags: null,
_requestObj_listInfo: null,
_requestObj_list: null, _requestObj_list: null,
_requestObj_listRecommend: null,
_requestObj_listDetail: null, _requestObj_listDetail: null,
currentTagInfo: { currentTagInfo: {
id: null, id: undefined,
info: null, info: undefined,
}, },
sortList: [ sortList: [
{ {
name: '推荐', name: '推荐',
tabId: 'kgrecommend',
id: '5', id: '5',
}, },
{ {
name: '最热', name: '最热',
tabId: 'kghot',
id: '6', id: '6',
}, },
{ {
name: '最新', name: '最新',
tabId: 'kgnew',
id: '7', id: '7',
}, },
{ {
name: '热藏', name: '热藏',
tabId: 'kghotcollect',
id: '3', id: '3',
}, },
{ {
name: '飙升', name: '飙升',
tabId: 'kgup',
id: '8', 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&cdn=cdn&t=5&c=${tagId}`
: `http://www2.kugou.kugou.com/yueku/v9/special/getSpecial?is_smarty=1&` : `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}` 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) { getSongListDetailUrl(id) {
@ -52,26 +49,13 @@ export default {
}, },
getTagInfo(tagId) { 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) { filterInfoHotTag(rawData) {
const result = [] const result = []
if (rawData.status !== 1) return result if (rawData.status !== 1) return result
for (let index = 0; index < Object.keys(rawData.data).lengt; index++) { for (const key of Object.keys(rawData.data)) {
let tag = rawData.data[index.toString()] let tag = rawData.data[key]
result.push({ result.push({
id: tag.id, id: tag.id,
name: tag.special_name, name: tag.special_name,
@ -92,6 +76,7 @@ export default {
})), })),
}) })
} }
return result
}, },
getSongList(sortId, tagId, page) { getSongList(sortId, tagId, page) {
@ -101,12 +86,12 @@ export default {
) )
return this._requestObj_list.promise.then(({ body }) => { return this._requestObj_list.promise.then(({ body }) => {
if (body.status !== 1) return this.getSongList(sortId, tagId, page) if (body.status !== 1) return this.getSongList(sortId, tagId, page)
return this.filterList(body.data) return this.filterList(body.special_db)
}) })
}, },
getSongListRecommend() { getSongListRecommend() {
if (this._requestObj_listRecommend) this._requestObj_listRecommend.cancelHttp() if (this._requestObj_listRecommend) this._requestObj_listRecommend.cancelHttp()
this._requestObj_listRecommendRecommend = httpFatch( this._requestObj_listRecommend = httpFatch(
'http://everydayrec.service.kugou.com/guess_special_recommend', 'http://everydayrec.service.kugou.com/guess_special_recommend',
{ {
method: 'post', method: 'post',
@ -127,7 +112,8 @@ export default {
} }
) )
return this._requestObj_listRecommend.promise.then(({ body }) => { 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) return this.filterList(body.data)
}) })
}, },
@ -215,11 +201,14 @@ export default {
// 获取列表信息 // 获取列表信息
getListInfo(tagId) { 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 { return {
limit: info.tagInfo.limit, limit: body.data.params.pagesize,
page: info.tagInfo.page, page: body.data.params.p,
total: info.tagInfo.total, total: body.data.params.total,
} }
}) })
}, },
@ -237,8 +226,9 @@ export default {
}) })
) )
if (!tagId) tasks.push(this.getSongListRecommend()) // 如果是所有类别,则顺便获取推荐列表 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) if (recommendList) list.unshift(...recommendList)
console.log(info)
return { return {
list, list,
...info, ...info,
@ -248,10 +238,13 @@ export default {
// 获取标签 // 获取标签
getTags() { 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 { return {
hotTag: info.hotTag, hotTag: this.filterInfoHotTag(body.data.hotTag),
tags: info.tags, tags: this.filterTagInfo(body.data.tagids),
} }
}) })
}, },

View File

@ -13,43 +13,41 @@ export default {
sortList: [ sortList: [
{ {
name: '最热', name: '最热',
tabId: 'kwhot',
id: 'hot', id: 'hot',
}, },
{ {
name: '最新', name: '最新',
tabId: 'kwnew',
id: 'new', 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', 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', 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 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/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}&order=${sortType}` : `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) { 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() if (this._requestObj_tags) this._requestObj_tags.cancelHttp()
this._requestObj_tags = httpFatch(this.tagsUrl) this._requestObj_tags = httpFatch(this.tagsUrl)
return this._requestObj_tags.promise.then(({ body }) => { return this._requestObj_tags.promise.then(({ body }) => {
if (body.code !== this.successCode) return this.getTags() if (body.code !== this.successCode) return this.getTag()
return this.filterTagInfo(body.data.tags) return this.filterTagInfo(body.data)
}) })
}, },
// 获取标签 // 获取标签
getHotTags() { getHotTag() {
if (this._requestObj_hotTags) this._requestObj_hotTags.cancelHttp() if (this._requestObj_hotTags) this._requestObj_hotTags.cancelHttp()
this._requestObj_hotTags = httpFatch(this.hotTagUrl) this._requestObj_hotTags = httpFatch(this.hotTagUrl)
return this._requestObj_hotTags.promise.then(({ body }) => { return this._requestObj_hotTags.promise.then(({ body }) => {
if (body.code !== this.successCode) return this.getHotTags() if (body.code !== this.successCode) return this.getHotTag()
return this.filterInfoHotTag(body.data.data) return this.filterInfoHotTag(body.data[0].data)
}) })
}, },
filterInfoHotTag(rawList) { filterInfoHotTag(rawList) {
@ -73,11 +71,9 @@ export default {
// 获取列表数据 // 获取列表数据
getList(sortId, tagId, page) { getList(sortId, tagId, page) {
if (this._requestObj_list) this._requestObj_list.cancelHttp() if (this._requestObj_list) this._requestObj_list.cancelHttp()
this._requestObj_list = httpFatch( this._requestObj_list = httpFatch(this.getListUrl({ sortId, id: tagId, page }))
this.getListUrl({ sortId, id: tagId, page })
)
return this._requestObj_list.promise.then(({ body }) => { 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 { return {
list: this.filterList(body.data.data), list: this.filterList(body.data.data),
total: body.data.total, total: body.data.total,
@ -167,7 +163,9 @@ export default {
} }
}) })
}, },
getTags() {
return Promise.all([this.getTag(), this.getHotTag()]).then(([tags, hotTag]) => ({ tags, hotTag }))
},
} }
// getList // getList

View File

@ -3,7 +3,7 @@
div(:class="$style.header") div(:class="$style.header")
material-tab(:class="$style.tab" :list="types" item-key="id" item-name="name" v-model="tabId") 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-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-modal(:show="isShowDownload" :musicInfo="musicInfo" @select="handleAddDownload" @close="isShowDownload = false")
material-download-multiple-modal(:show="isShowDownloadMultiple" :list="selectdData" @select="handleAddDownloadMultiple" @close="isShowDownloadMultiple = false") material-download-multiple-modal(:show="isShowDownloadMultiple" :list="selectdData" @select="handleAddDownloadMultiple" @close="isShowDownloadMultiple = false")
</template> </template>

View File

@ -1,8 +1,8 @@
<template lang="pug"> <template lang="pug">
div(:class="$style.leaderboard") div(:class="$style.leaderboard")
div(:class="$style.header") div(:class="$style.header")
//- material-tab(:class="$style.tab" :list="types" item-key="id" item-name="name" v-model="sortId") material-tab(:class="$style.tab" :list="sorts" item-key="id" item-name="name" v-model="sortId")
//- material-select(:class="$style.select" :list="sourceInfo.sources" item-key="id" item-name="name" v-model="source") material-select(:class="$style.select" :list="sourceInfo.sources" item-key="id" item-name="name" v-model="source")
material-download-modal(:show="isShowDownload" :musicInfo="musicInfo" @select="handleAddDownload" @close="isShowDownload = false") 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") material-download-multiple-modal(:show="isShowDownloadMultiple" :list="selectdData" @select="handleAddDownloadMultiple" @close="isShowDownloadMultiple = false")
</template> </template>
@ -12,31 +12,27 @@ import { mapGetters, mapMutations, mapActions } from 'vuex'
import { scrollTo } from '../utils' import { scrollTo } from '../utils'
// import music from '../utils/music' // import music from '../utils/music'
export default { export default {
name: 'Leaderboard', name: 'SongList',
data() { data() {
return { return {
tagId: null, tagId: null,
sortId: null, sortId: undefined,
source: null, source: null,
listPage: 1, listPage: 1,
songListPage: 1, songListPage: 1,
clickTime: 0,
clickIndex: -1,
isShowDownload: false, isShowDownload: false,
musicInfo: null, musicInfo: null,
selectdData: [], selectdData: [],
isSelectAll: false,
isIndeterminate: false,
isShowEditBtn: false,
isShowDownloadMultiple: false, isShowDownloadMultiple: false,
isToggleSource: false,
} }
}, },
computed: { computed: {
...mapGetters(['setting']), ...mapGetters(['setting']),
...mapGetters('songList', ['sourceInfo', 'tags', 'listData', 'listDetail']), ...mapGetters('songList', ['sourceInfo', 'tags', 'listData', 'listDetail']),
...mapGetters('list', ['defaultList']), ...mapGetters('list', ['defaultList']),
types() { sorts() {
return this.source ? this.sourceInfo.sources[this.source] : [] return this.source ? this.sourceInfo.sortList[this.source] : []
}, },
isAPITemp() { isAPITemp() {
return this.setting.apiSource == 'temp' return this.setting.apiSource == 'temp'
@ -45,47 +41,39 @@ export default {
watch: { watch: {
sortId(n, o) { sortId(n, o) {
this.setSongList({ sortId: n }) 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.getList(1).then(() => {
this.listPage = this.info.listPage this.listPage = this.listData.listPage
scrollTo(this.$refs.dom_scrollContent, 0)
}) })
}, },
tagId(n, o) { tagId(n, o) {
this.setSongList({ sortId: n }) this.setSongList({ tagId: n })
if (!o && this.songListPage !== 1) return if (!o && this.listPage !== 1) return
if (this.isToggleSource) {
this.isToggleSource = false
return
}
this.getList(1).then(() => { this.getList(1).then(() => {
this.songListPage = this.info.songListPage this.listPage = this.listData.listPage
scrollTo(this.$refs.dom_scrollContent, 0)
}) })
}, },
source(n, o) { source(n, o) {
this.setSongList({ source: n }) this.setSongList({ source: n })
if (!this.tags[n]) this.getTags()
if (o) { if (o) {
this.tagId = this.tags[0] && this.tags[0].id this.isToggleSource = true
this.sortType = this.sortList[0] && this.sortList[0].id 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() { mounted() {
this.source = this.setting.songList.source this.source = this.setting.songList.source
// this.sortId = this.setting.songList.sortId this.tagId = this.setting.songList.tagId
this.listPage = this.listData.page this.listPage = this.listData.page
this.songListPage = this.listDetail.page this.songListPage = this.listDetail.page
this.sortId = this.setting.songList.sortId
}, },
methods: { methods: {
...mapMutations(['setSongList']), ...mapMutations(['setSongList']),