修复kw搜索联想词
This commit is contained in:
parent
e8d8feb042
commit
9ab564951c
@ -1,5 +1,6 @@
|
|||||||
import { decodeName } from '../../index'
|
// import { decodeName } from '../../index'
|
||||||
import { tokenRequest } from './util'
|
// import { tokenRequest } from './util'
|
||||||
|
import { httpFetch } from '../../request'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
regExps: {
|
regExps: {
|
||||||
@ -7,24 +8,25 @@ export default {
|
|||||||
},
|
},
|
||||||
requestObj: null,
|
requestObj: null,
|
||||||
async tipSearchBySong(str) {
|
async tipSearchBySong(str) {
|
||||||
|
// 报错403,加了referer还是有问题(直接换一个
|
||||||
|
// this.requestObj = await tokenRequest(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`)
|
||||||
|
|
||||||
this.cancelTipSearch()
|
this.cancelTipSearch()
|
||||||
this.requestObj = await tokenRequest(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`)
|
this.requestObj = httpFetch(`https://tips.kuwo.cn/t.s?corp=kuwo&newver=3&p2p=1¬race=0&c=mbox&w=${encodeURIComponent(str)}&encoding=utf8&rformat=json`, {
|
||||||
return this.requestObj.promise.then(({ body }) => {
|
Referer: 'http://www.kuwo.cn/',
|
||||||
// console.log(body)
|
})
|
||||||
if (body.code !== 200) return Promise.reject(new Error('请求失败'))
|
return this.requestObj.promise.then(({ body, statusCode }) => {
|
||||||
return body
|
if (statusCode != 200 || !body.WORDITEMS) return Promise.reject(new Error('请求失败'))
|
||||||
|
return body.WORDITEMS
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
handleResult(rawData) {
|
handleResult(rawData) {
|
||||||
return rawData.map(info => {
|
return rawData.map(item => item.RELWORD)
|
||||||
let matchResult = info.match(this.regExps.relWord)
|
|
||||||
return matchResult ? decodeName(matchResult[1]) : ''
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
cancelTipSearch() {
|
cancelTipSearch() {
|
||||||
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
||||||
},
|
},
|
||||||
async search(str) {
|
async search(str) {
|
||||||
return this.tipSearchBySong(str).then(result => this.handleResult(result.data))
|
return this.tipSearchBySong(str).then(result => this.handleResult(result))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user