diff --git a/src/util/util.video.js b/src/util/util.video.js index 7342f13..1f38d6c 100644 --- a/src/util/util.video.js +++ b/src/util/util.video.js @@ -1,49 +1,53 @@ // import Axios from "axios" import axios from 'axios' const video = { - url: 'http://www.666zy.com/', getList (url, txt) { - const t = encodeURI(txt) - const d = `wd=${t}&submit=search` - axios({ - url: url, - method: 'post', - params: { m: 'vod-search' }, - data: d - }).then(res => { - this.parser(res.data) + return new Promise((resolve, reject) => { + const t = encodeURI(txt) + const d = `wd=${t}&submit=search` + axios({ + url: url, + method: 'post', + params: { m: 'vod-search' }, + data: d + }).then(res => { + resolve(this.parser(url, res.data)) + }) }) }, - parser (txt) { - const parser = new DOMParser() - let html = parser.parseFromString(txt, 'text/html') - let data = [] - let name = [] - let detail = [] - let type = [] - let time = [] - let nameList = html.querySelectorAll('.xing_vb4 a') - for (let i = 0; i < nameList.length; i++) { - name.push(nameList[i].innerText) - detail.push('http://www.666zy.com' + nameList[i].getAttribute('href')) - } - let typeList = html.querySelectorAll('.xing_vb5 a') - for (let i = 0; i < typeList.length; i++) { - type.push(typeList[i].innerText) - } - let timeList = html.querySelectorAll('.xing_vb6') - for (let i = 0; i < timeList.length; i++) { - time.push(timeList[i].innerText) - } - for (let i = 0; i < name.length; i++) { - let d = {} - d.name = name[i] - d.detail = detail[i] - d.type = type[i] - d.time = time[i] - data.push(d) - } - return data + parser (url, txt) { + return new Promise((resolve, reject) => { + const parser = new DOMParser() + let html = parser.parseFromString(txt, 'text/html') + let data = [] + let name = [] + let detail = [] + let category = [] + let time = [] + let nameList = html.querySelectorAll('.xing_vb4 a') + for (let i = 0; i < nameList.length; i++) { + name.push(nameList[i].innerText) + detail.push(url + nameList[i].getAttribute('href')) + } + let typeList = html.querySelectorAll('.xing_vb5 a') + for (let i = 0; i < typeList.length; i++) { + category.push(typeList[i].innerText) + } + let timeList = html.querySelectorAll('.xing_vb6') + for (let i = 0; i < timeList.length; i++) { + time.push(timeList[i].innerText) + } + for (let i = 0; i < name.length; i++) { + let d = {} + d.name = name[i] + d.detail = detail[i] + d.category = category[i] + d.time = time[i] + data.push(d) + } + console.log(data) + resolve(data) + }) } } diff --git a/src/views/Search.vue b/src/views/Search.vue index 0838004..578d0fc 100644 --- a/src/views/Search.vue +++ b/src/views/Search.vue @@ -25,8 +25,8 @@ export default { name: 'search', data () { return { - txt: '', - active: false, + txt: '吸血鬼', + active: true, percent: 0, columns: [ { @@ -35,11 +35,15 @@ export default { }, { title: 'Category', - key: 'category' + key: 'category', + width: 120, + align: 'center' }, { title: 'Time', - key: 'time' + key: 'time', + width: 180, + align: 'center' }, { title: 'Action', @@ -55,9 +59,10 @@ export default { methods: { async searchEvent () { if (this.txt !== '') { + this.data = await video.getList('http://www.666zy.com/', this.txt) this.active = true - let d = await video.getList('http://www.666zy.com/', this.txt) - console.log(d) + this.loading = false + this.percent = 20 } }, searchFocus () { @@ -70,17 +75,21 @@ export default { collection (e) {}, detail (e) {} }, - created () {} + created () { + this.searchEvent() + } }