统一调用方法
parent
ad40fdcb55
commit
78db5b55ec
|
@ -4,8 +4,11 @@ import { formatPlayTime, sizeFormate } from '../../index'
|
||||||
export default {
|
export default {
|
||||||
_requestObj_tagInfo: null,
|
_requestObj_tagInfo: null,
|
||||||
_requestObj_songList: null,
|
_requestObj_songList: null,
|
||||||
_requestObj_songListRecommend: null,
|
|
||||||
_requestObj_songListDetail: null,
|
_requestObj_songListDetail: null,
|
||||||
|
currentTagInfo: {
|
||||||
|
id: null,
|
||||||
|
info: null,
|
||||||
|
},
|
||||||
sortList: [
|
sortList: [
|
||||||
{
|
{
|
||||||
name: '推荐',
|
name: '推荐',
|
||||||
|
@ -43,14 +46,14 @@ export default {
|
||||||
return `http://www2.kugou.kugou.com/yueku/v9/special/single/${id}-5-9999.html`
|
return `http://www2.kugou.kugou.com/yueku/v9/special/single/${id}-5-9999.html`
|
||||||
},
|
},
|
||||||
|
|
||||||
getTypeInfo(tagId) {
|
getTagInfo(tagId) {
|
||||||
if (this._requestObj_tagInfo) this._requestObj_tagInfo.cancelHttp()
|
if (this._requestObj_tagInfo) this._requestObj_tagInfo.cancelHttp()
|
||||||
this._requestObj_tagInfo = httpFatch(this.getInfoUrl(tagId))
|
this._requestObj_tagInfo = httpFatch(this.getInfoUrl(tagId))
|
||||||
return this._requestObj_tagInfo.promise.then(({ body }) => {
|
return this._requestObj_tagInfo.promise.then(({ body }) => {
|
||||||
if (body.status !== 1) return this.getTypeInfo(tagId)
|
if (body.status !== 1) return this.getTagInfo(tagId)
|
||||||
return {
|
return {
|
||||||
hotTag: this.filterInfoHotTag(body.data.hotTag),
|
hotTag: this.filterInfoHotTag(body.data.hotTag),
|
||||||
tags: this.filterTagInfo(),
|
tags: this.filterTagInfo(body.data.tagids),
|
||||||
tagInfo: {
|
tagInfo: {
|
||||||
limit: body.data.params.pagesize,
|
limit: body.data.params.pagesize,
|
||||||
page: body.data.params.p,
|
page: body.data.params.p,
|
||||||
|
@ -76,7 +79,7 @@ export default {
|
||||||
for (const type of Object.keys(rawData)) {
|
for (const type of Object.keys(rawData)) {
|
||||||
result.push({
|
result.push({
|
||||||
type,
|
type,
|
||||||
list: rawData[type].map(tag => ({
|
list: rawData[type].data.map(tag => ({
|
||||||
parent_id: tag.parent_id,
|
parent_id: tag.parent_id,
|
||||||
parent_name: tag.pname,
|
parent_name: tag.pname,
|
||||||
id: tag.id,
|
id: tag.id,
|
||||||
|
@ -125,8 +128,7 @@ export default {
|
||||||
},
|
},
|
||||||
filterSongList(rawData) {
|
filterSongList(rawData) {
|
||||||
return rawData.map(item => ({
|
return rawData.map(item => ({
|
||||||
play_count: item.play_count,
|
play_count: item.total_play_count,
|
||||||
total_play_count: item.total_play_count,
|
|
||||||
id: item.specialid,
|
id: item.specialid,
|
||||||
author: item.nickname,
|
author: item.nickname,
|
||||||
name: item.specialname,
|
name: item.specialname,
|
||||||
|
@ -137,13 +139,18 @@ export default {
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
|
|
||||||
getSongListDetail(id) { // 获取歌曲列表内的音乐
|
getListDetail(id, page) { // 获取歌曲列表内的音乐
|
||||||
if (this._requestObj_songListDetail) this._requestObj_songListDetail.cancelHttp()
|
if (this._requestObj_songListDetail) this._requestObj_songListDetail.cancelHttp()
|
||||||
this._requestObj_songListDetail = httpFatch(this.getSongListDetailUrl(id))
|
this._requestObj_songListDetail = httpFatch(this.getSongListDetailUrl(id))
|
||||||
return this._requestObj_songListDetail.promise.then(({ body }) => {
|
return this._requestObj_songListDetail.promise.then(({ body }) => {
|
||||||
let listData = body.match(this.regExps.listData)
|
let listData = body.match(this.regExps.listData)
|
||||||
if (listData) listData = this.filterData(JSON.parse(RegExp.$1))
|
if (listData) listData = this.filterData(JSON.parse(RegExp.$1))
|
||||||
return listData
|
return {
|
||||||
|
list: listData,
|
||||||
|
page: 1,
|
||||||
|
limit: 10000,
|
||||||
|
total: listData.length,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
filterData(rawList) {
|
filterData(rawList) {
|
||||||
|
@ -201,8 +208,9 @@ export default {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
getListInfo(tagId) { // 获取列表信息
|
// 获取列表信息
|
||||||
return this.getTypeInfo(tagId).then(info => {
|
getListInfo(tagId) {
|
||||||
|
return this.getTagInfo(tagId).then(info => {
|
||||||
return {
|
return {
|
||||||
limit: info.tagInfo.limit,
|
limit: info.tagInfo.limit,
|
||||||
page: info.tagInfo.page,
|
page: info.tagInfo.page,
|
||||||
|
@ -211,17 +219,31 @@ export default {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
getList(sortId, tagId, page) { // 获取列表数据
|
// 获取列表数据
|
||||||
|
getList(sortId, tagId, page) {
|
||||||
let tasks = [this.getSongList(sortId, tagId, page)]
|
let tasks = [this.getSongList(sortId, tagId, page)]
|
||||||
if (!tagId) tasks.push(this.getSongListRecommend())
|
tasks.push(
|
||||||
Promise.all(tasks).then(([list, recommendList]) => {
|
this.currentTagInfo.id === tagId
|
||||||
|
? Promise.resolve(this.currentTagInfo.info)
|
||||||
|
: this.getListInfo(tagId).then(info => {
|
||||||
|
this.currentTagInfo.id = tagId
|
||||||
|
this.currentTagInfo.info = Object.assign({}, info)
|
||||||
|
return info
|
||||||
|
})
|
||||||
|
)
|
||||||
|
if (!tagId) tasks.push(this.getSongListRecommend()) // 如果是所有类别,则顺便获取推荐列表
|
||||||
|
Promise.all(tasks).then(([list, info, recommendList]) => {
|
||||||
if (recommendList) list.unshift(...recommendList)
|
if (recommendList) list.unshift(...recommendList)
|
||||||
return list
|
return {
|
||||||
|
list,
|
||||||
|
...info,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
getTags() { // 获取标签
|
// 获取标签
|
||||||
return this.getTypeInfo().then(info => {
|
getTags() {
|
||||||
|
return this.getTagInfo().then(info => {
|
||||||
return {
|
return {
|
||||||
hotTag: info.hotTag,
|
hotTag: info.hotTag,
|
||||||
tags: info.tags,
|
tags: info.tags,
|
||||||
|
@ -229,3 +251,7 @@ export default {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getList
|
||||||
|
// getTags
|
||||||
|
// getListDetail
|
||||||
|
|
Loading…
Reference in New Issue