更新搜索提示词
This commit is contained in:
parent
69640076b7
commit
2296e23860
@ -22,7 +22,7 @@ export default {
|
||||
const visibleList = ref(false)
|
||||
const tipList = ref([])
|
||||
let isFocused = false
|
||||
let prevTempSearchSource = ''
|
||||
let prevTipSearchSource = ''
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
@ -44,19 +44,19 @@ export default {
|
||||
handleTipSearch()
|
||||
})
|
||||
|
||||
|
||||
const tipSearch = debounce(async() => {
|
||||
if (searchText.value === '' && prevTempSearchSource) {
|
||||
if (searchText.value === '' && prevTipSearchSource) {
|
||||
tipList.value = []
|
||||
music[prevTempSearchSource].tempSearch.cancelTempSearch()
|
||||
music[prevTipSearchSource].tipSearch.cancelTipSearch()
|
||||
return
|
||||
}
|
||||
const { temp_source } = await getSearchSetting()
|
||||
prevTempSearchSource = temp_source
|
||||
music[prevTempSearchSource].tempSearch.search(searchText.value).then(list => {
|
||||
const { source, temp_source } = await getSearchSetting()
|
||||
prevTipSearchSource = source
|
||||
if (source === 'all') prevTipSearchSource = temp_source
|
||||
music[prevTipSearchSource].tipSearch.search(searchText.value).then(list => {
|
||||
tipList.value = list
|
||||
}).catch(() => {})
|
||||
}, 50)
|
||||
}, 100)
|
||||
|
||||
const handleTipSearch = () => {
|
||||
if (!visibleList.value && isFocused) visibleList.value = true
|
||||
|
||||
@ -6,8 +6,10 @@ import pic from './pic'
|
||||
import lyric from './lyric'
|
||||
import hotSearch from './hotSearch'
|
||||
import comment from './comment'
|
||||
import tipSearch from './tipSearch'
|
||||
|
||||
const kg = {
|
||||
tipSearch,
|
||||
leaderboard,
|
||||
songList,
|
||||
musicSearch,
|
||||
|
||||
25
src/renderer/utils/musicSdk/kg/tipSearch.js
Normal file
25
src/renderer/utils/musicSdk/kg/tipSearch.js
Normal file
@ -0,0 +1,25 @@
|
||||
import { createHttpFetch } from './util'
|
||||
|
||||
export default {
|
||||
requestObj: null,
|
||||
cancelTipSearch() {
|
||||
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
||||
},
|
||||
tipSearchBySong(str) {
|
||||
this.cancelTipSearch()
|
||||
this.requestObj = createHttpFetch(`https://searchtip.kugou.com/getSearchTip?MusicTipCount=10&keyword=${encodeURIComponent(str)}`, {
|
||||
headers: {
|
||||
referer: 'https://www.kugou.com/',
|
||||
},
|
||||
})
|
||||
return this.requestObj.then(body => {
|
||||
return body[0].RecordDatas
|
||||
})
|
||||
},
|
||||
handleResult(rawData) {
|
||||
return rawData.map(info => info.HintInfo)
|
||||
},
|
||||
async search(str) {
|
||||
return this.tipSearchBySong(str).then(result => this.handleResult(result))
|
||||
},
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
import { httpFetch } from '../../request'
|
||||
import tempSearch from './tempSearch'
|
||||
import tipSearch from './tipSearch'
|
||||
import musicSearch from './musicSearch'
|
||||
import { formatSinger, getToken } from './util'
|
||||
import leaderboard from './leaderboard'
|
||||
@ -32,7 +32,7 @@ const kw = {
|
||||
// // })
|
||||
// },
|
||||
|
||||
tempSearch,
|
||||
tipSearch,
|
||||
musicSearch,
|
||||
leaderboard,
|
||||
songList,
|
||||
|
||||
@ -1,15 +1,13 @@
|
||||
// import { httpFetch } from '../../request'
|
||||
import { decodeName } from '../../index'
|
||||
import { tokenRequest } from './util'
|
||||
|
||||
|
||||
export default {
|
||||
regExps: {
|
||||
relWord: /RELWORD=(.+)/,
|
||||
},
|
||||
requestObj: null,
|
||||
async tempSearch(str) {
|
||||
this.cancelTempSearch()
|
||||
async tipSearchBySong(str) {
|
||||
this.cancelTipSearch()
|
||||
this.requestObj = await tokenRequest(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`)
|
||||
return this.requestObj.promise.then(({ body }) => {
|
||||
// console.log(body)
|
||||
@ -23,10 +21,10 @@ export default {
|
||||
return matchResult ? decodeName(matchResult[1]) : ''
|
||||
})
|
||||
},
|
||||
cancelTempSearch() {
|
||||
cancelTipSearch() {
|
||||
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
||||
},
|
||||
async search(str) {
|
||||
return this.tempSearch(str).then(result => this.handleResult(result.data))
|
||||
return this.tipSearchBySong(str).then(result => this.handleResult(result.data))
|
||||
},
|
||||
}
|
||||
@ -6,8 +6,10 @@ import pic from './pic'
|
||||
import lyric from './lyric'
|
||||
import hotSearch from './hotSearch'
|
||||
import comment from './comment'
|
||||
import tipSearch from './tipSearch'
|
||||
|
||||
const mg = {
|
||||
tipSearch,
|
||||
songList,
|
||||
musicSearch,
|
||||
leaderboard,
|
||||
|
||||
25
src/renderer/utils/musicSdk/mg/tipSearch.js
Normal file
25
src/renderer/utils/musicSdk/mg/tipSearch.js
Normal file
@ -0,0 +1,25 @@
|
||||
import { createHttpFetch } from './util'
|
||||
|
||||
export default {
|
||||
requestObj: null,
|
||||
cancelTipSearch() {
|
||||
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
||||
},
|
||||
tipSearchBySong(str) {
|
||||
this.cancelTipSearch()
|
||||
this.requestObj = createHttpFetch(`https://music.migu.cn/v3/api/search/suggest?keyword=${encodeURIComponent(str)}`, {
|
||||
headers: {
|
||||
referer: 'https://music.migu.cn/v3',
|
||||
},
|
||||
})
|
||||
return this.requestObj.then(body => {
|
||||
return body.songs
|
||||
})
|
||||
},
|
||||
handleResult(rawData) {
|
||||
return rawData.map(info => `${info.name} - ${info.singerName}`)
|
||||
},
|
||||
async search(str) {
|
||||
return this.tipSearchBySong(str).then(result => this.handleResult(result))
|
||||
},
|
||||
}
|
||||
@ -15,6 +15,15 @@ export const createHttpFetch = async(url, options, retryNum = 0) => {
|
||||
console.log(err)
|
||||
return createHttpFetch(url, options, ++retryNum)
|
||||
}
|
||||
if (result.statusCode !== 200 || result.body.code !== '000000') return createHttpFetch(url, options, ++retryNum)
|
||||
if (result.body) return result.body
|
||||
if (result.statusCode !== 200 ||
|
||||
(
|
||||
(result.body.code !== undefined
|
||||
? result.body.code
|
||||
: result.body.returnCode !== undefined
|
||||
? result.body.returnCode
|
||||
: result.body.code
|
||||
) !== '000000')
|
||||
) return createHttpFetch(url, options, ++retryNum)
|
||||
if (result.body.data) return result.body.data
|
||||
return result.body
|
||||
}
|
||||
|
||||
@ -5,10 +5,10 @@ import musicSearch from './musicSearch'
|
||||
import { apis } from '../api-source'
|
||||
import hotSearch from './hotSearch'
|
||||
import comment from './comment'
|
||||
import tempSearch from './tempSearch'
|
||||
import tipSearch from './tipSearch'
|
||||
|
||||
const tx = {
|
||||
tempSearch,
|
||||
tipSearch,
|
||||
leaderboard,
|
||||
songList,
|
||||
musicSearch,
|
||||
|
||||
@ -1,16 +1,12 @@
|
||||
import { httpFetch } from '../../request'
|
||||
|
||||
|
||||
export default {
|
||||
regExps: {
|
||||
relWord: /RELWORD=(.+)/,
|
||||
},
|
||||
requestObj: null,
|
||||
cancelTempSearch() {
|
||||
cancelTipSearch() {
|
||||
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
||||
},
|
||||
tempSearch(str) {
|
||||
this.cancelTempSearch()
|
||||
tipSearchBySong(str) {
|
||||
this.cancelTipSearch()
|
||||
this.requestObj = httpFetch(`https://c.y.qq.com/splcloud/fcgi-bin/smartbox_new.fcg?_=1682514997109&cv=4747474&ct=24&format=json&inCharset=utf-8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=1&uin=0&g_tk_new_20200303=5381&g_tk=5381&hostUin=0&is_xml=0&key=${encodeURIComponent(str)}`, {
|
||||
headers: {
|
||||
origin: 'https://y.qq.com/',
|
||||
@ -19,13 +15,13 @@ export default {
|
||||
})
|
||||
return this.requestObj.promise.then(({ statusCode, body }) => {
|
||||
if (statusCode != 200 || body.code != 0) return Promise.reject(new Error('请求失败'))
|
||||
return body.data
|
||||
return body.data.song.itemlist
|
||||
})
|
||||
},
|
||||
handleResult(rawData) {
|
||||
return rawData.map(info => `${info.name} - ${info.singer}`)
|
||||
},
|
||||
async search(str) {
|
||||
return this.tempSearch(str).then(result => this.handleResult(result.song.itemlist))
|
||||
return this.tipSearchBySong(str).then(result => this.handleResult(result))
|
||||
},
|
||||
}
|
||||
@ -6,8 +6,10 @@ import musicSearch from './musicSearch'
|
||||
import songList from './songList'
|
||||
import hotSearch from './hotSearch'
|
||||
import comment from './comment'
|
||||
import tipSearch from './tipSearch'
|
||||
|
||||
const wy = {
|
||||
tipSearch,
|
||||
leaderboard,
|
||||
musicSearch,
|
||||
songList,
|
||||
|
||||
33
src/renderer/utils/musicSdk/wy/tipSearch.js
Normal file
33
src/renderer/utils/musicSdk/wy/tipSearch.js
Normal file
@ -0,0 +1,33 @@
|
||||
import { httpFetch } from '../../request'
|
||||
import { weapi } from './utils/crypto'
|
||||
import { getSingerName } from '../../index'
|
||||
|
||||
export default {
|
||||
requestObj: null,
|
||||
cancelTipSearch() {
|
||||
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
||||
},
|
||||
tipSearchBySong(str) {
|
||||
this.cancelTipSearch()
|
||||
this.requestObj = httpFetch('https://music.163.com/weapi/search/suggest/web', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
referer: 'https://music.163.com/',
|
||||
origin: 'https://music.163.com/',
|
||||
},
|
||||
form: weapi({
|
||||
s: str,
|
||||
}),
|
||||
})
|
||||
return this.requestObj.promise.then(({ statusCode, body }) => {
|
||||
if (statusCode != 200 || body.code != 200) return Promise.reject(new Error('请求失败'))
|
||||
return body.result.songs
|
||||
})
|
||||
},
|
||||
handleResult(rawData) {
|
||||
return rawData.map(info => `${info.name} - ${getSingerName(info.artists, 'name')}`)
|
||||
},
|
||||
async search(str) {
|
||||
return this.tipSearchBySong(str).then(result => this.handleResult(result))
|
||||
},
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user