修复在线音乐列表获取失败时无限循环请求的问题
This commit is contained in:
@@ -169,17 +169,18 @@ export default {
|
||||
}
|
||||
})
|
||||
},
|
||||
loadData(p1, p2, page, bangid) {
|
||||
loadData(p1, p2, page, bangid, retryNum = 0) {
|
||||
if (++retryNum > 3) return Promise.reject(new Error('try max num'))
|
||||
return Promise.all([p1, p2]).then(([data1, data2]) => {
|
||||
// console.log(data1, data2)
|
||||
if (!data1.musiclist.length) {
|
||||
return this.loadData(this.getData(this.getUrl(page, this.limit, bangid)),
|
||||
data2.data.musicList.length
|
||||
? Promise.resolve(data2)
|
||||
: this.getData2(this.getUrl2(page, this.limit, bangid)), page, bangid)
|
||||
: this.getData2(this.getUrl2(page, this.limit, bangid)), page, bangid, retryNum)
|
||||
}
|
||||
if (!data2.data.musicList.length) {
|
||||
return this.loadData(Promise.resolve(data1), this.getData2(this.getUrl2(page, this.limit, bangid)), page, bangid)
|
||||
return this.loadData(Promise.resolve(data1), this.getData2(this.getUrl2(page, this.limit, bangid)), page, bangid, retryNum)
|
||||
}
|
||||
return Promise.resolve([data1, data2])
|
||||
})
|
||||
|
||||
@@ -121,11 +121,13 @@ export default {
|
||||
}
|
||||
return result
|
||||
},
|
||||
search(str, page = 1, { limit } = {}) {
|
||||
search(str, page = 1, { limit } = {}, retryNum = 0) {
|
||||
if (retryNum > 2) return Promise.reject(new Error('try max num'))
|
||||
if (limit != null) this.limit = limit
|
||||
// http://newlyric.kuwo.cn/newlyric.lrc?62355680
|
||||
return this.musicSearch(str, page).then(result => {
|
||||
if (!result || (result.TOTAL !== '0' && result.SHOW === '0')) return this.search(str, page, { limit })
|
||||
if (!result || (result.TOTAL !== '0' && result.SHOW === '0')) return this.search(str, page, { limit }, ++retryNum)
|
||||
console.log(result)
|
||||
let list = this.handleResult(result.abslist)
|
||||
|
||||
if (list == null) return this.search(str, page, { limit })
|
||||
|
||||
@@ -93,7 +93,7 @@ export default {
|
||||
this._requestObj_list = httpFetch(this.getListUrl({ sortId, id, type, page }))
|
||||
return this._requestObj_list.promise.then(({ body }) => {
|
||||
if (!id || type == '10000') {
|
||||
if (body.code !== this.successCode) return this.getList(sortId, id, type, page, ++tryNum)
|
||||
if (body.code !== this.successCode) return this.getList(sortId, tagId, page, ++tryNum)
|
||||
return {
|
||||
list: this.filterList(body.data.data),
|
||||
total: body.data.total,
|
||||
|
||||
Reference in New Issue
Block a user