优化收藏页面和详情页面

This commit is contained in:
hunlongyu
2020-01-08 11:15:53 +08:00
parent 188035c4a1
commit f4becc4645
6 changed files with 72 additions and 134 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "zy-player",
"version": "0.5.2",
"version": "0.5.3",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",

View File

@@ -1,94 +0,0 @@
import axios from 'axios'
const haku = {
url: 'https://www.666zy.com',
getHtml (txt) {
return new Promise((resolve, reject) => {
const t = encodeURI(txt)
const d = `wd=${t}&submit=search`
axios({
url: this.url + '/index.php',
method: 'post',
params: { m: 'vod-search' },
data: d
}).then(res => {
resolve(this.getVideoInfo(res.data))
}).catch(err => {
reject(err)
})
})
},
getVideoInfo (txt) {
return new Promise((resolve, reject) => {
const parser = new DOMParser()
let html = parser.parseFromString(txt, 'text/html')
let nameList = html.querySelectorAll('.xing_vb4 a')
let name = []
let detail = []
for (let i = 0; i < nameList.length; i++) {
name.push(nameList[i].innerText)
detail.push(this.url + nameList[i].getAttribute('href'))
}
let categoryList = html.querySelectorAll('.xing_vb5 a')
let category = []
for (let i = 0; i < categoryList.length; i++) {
category.push(categoryList[i].innerText)
}
let timeList = html.querySelectorAll('.xing_vb6')
let time = []
for (let i = 0; i < timeList.length; i++) {
time.push(timeList[i].innerText)
}
let data = []
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]
d.index = 0
d.urls = []
d.check = false
data.push(d)
}
resolve(data)
})
},
getDetail (url) {
return new Promise((resolve, reject) => {
axios({
url: url,
method: 'get'
}).then(res => {
resolve(this.getUrls(res.data))
}).catch(err => {
reject(err)
})
})
},
getUrls (txt) {
return new Promise((resolve, reject) => {
const parser = new DOMParser()
let html = parser.parseFromString(txt, 'text/html')
let data = {
box: null,
info: null,
urls: []
}
data.box = html.querySelector('.vodBox').innerHTML
data.info = html.querySelector('.vodplayinfo').innerHTML
let url = html.querySelectorAll('.vodplayinfo a')
let arr = []
for (let i in url) {
let j = url[i].innerHTML
if (j !== undefined && j.indexOf('.m3u8') !== -1) {
arr.push(url[i].innerHTML)
}
}
data.urls = arr
resolve(data)
})
}
}
export default haku

View File

@@ -57,7 +57,38 @@ const zy = {
})
})
},
detail () {}
detail (url) {
return new Promise((resolve, reject) => {
axios.get(url).then(res => {
resolve(this.getDetailUrls(res.data))
}).catch(err => {
reject(err)
})
})
},
getDetailUrls (txt) {
return new Promise((resolve, reject) => {
const parser = new DOMParser()
let html = parser.parseFromString(txt, 'text/html')
let data = {
box: null,
info: null,
urls: []
}
data.box = html.querySelector('.vodBox').innerHTML
data.info = html.querySelector('.vodplayinfo').innerHTML
let urls = html.querySelectorAll('.vodplayinfo li')
let arr = []
for (let i in urls) {
let j = urls[i].innerText
if (j !== undefined && j.indexOf('.m3u8') !== -1) {
arr.push(urls[i].innerText)
}
}
data.urls = arr
resolve(data)
})
}
}
export default zy

View File

@@ -8,7 +8,7 @@
</div>
</template>
<script>
import haku from '@/lib/util.666zy'
import zy from '@/lib/util.zy'
import { mapMutations } from 'vuex'
export default {
name: 'detail',
@@ -40,7 +40,7 @@ export default {
async getDetail () {
this.box = false
let url = this.video.detail
this.data = await haku.getDetail(url)
this.data = await zy.detail(url)
this.video.urls = this.data.urls
this.video.check = true
this.box = true

View File

@@ -10,7 +10,8 @@
<script>
import 'xgplayer'
import Hls from 'xgplayer-hls.js'
import haku from '@/lib/util.666zy'
import zy from '@/lib/util.zy'
// import haku from '@/lib/util.666zy'
export default {
name: 'player',
data () {
@@ -56,7 +57,7 @@ export default {
async getDetail () {
let d = this.video.detail
let index = this.video.index
this.data = await haku.getDetail(d)
this.data = await zy.detail(d)
let urls = this.data.urls
this.video.urls = urls
this.video.check = true
@@ -73,6 +74,7 @@ export default {
playBtn (i, j, e) {
this.video.index = j
let url = this.video.urls[this.video.index].split('$')[1]
this.info = this.video.urls[this.video.index].split('$')[0]
this.xg.src = url
}
},

View File

@@ -37,18 +37,19 @@ export default {
columns: [
{
title: 'Name',
key: 'name'
key: 'name',
minWidth: 240
},
{
title: 'Category',
key: 'category',
width: 120,
width: 100,
align: 'center'
},
{
title: 'Time',
key: 'time',
width: 180,
width: 110,
align: 'center'
},
{
@@ -109,37 +110,35 @@ export default {
this.$router.push({ name: 'play' })
},
async collection (e) {
console.log(e)
// let d = await haku.getDetail(e.detail)
// let d = {}
// let data = {
// category: e.category,
// detail: e.detail,
// name: e.name,
// time: e.time,
// type: 'single',
// index: 0,
// urls: [],
// check: false
// }
// data.urls = d.urls
// data.check = true
// this.$store.commit('SET_VIDEO', data)
// db.find({ detail: data.detail }).then(res => {
// if (res.length >= 1) {
// this.$Notice.warning({
// title: '资源已存在',
// backgroud: true
// })
// } else {
// db.add(data).then(res => {
// this.$Notice.success({
// title: '收藏成功',
// backgroud: true
// })
// })
// }
// })
let d = await zy.detail(e.detail)
let data = {
category: e.category,
detail: e.detail,
name: e.name,
time: e.time,
type: 'single',
index: 0,
urls: [],
check: false
}
data.urls = d.urls
data.check = true
this.$store.commit('SET_VIDEO', data)
db.find({ detail: data.detail }).then(res => {
if (res.length >= 1) {
this.$Notice.warning({
title: '资源已存在',
backgroud: true
})
} else {
db.add(data).then(res => {
this.$Notice.success({
title: '收藏成功',
backgroud: true
})
})
}
})
},
detail (e) {
this.$store.commit('SET_VIDEO', e)