核心功能完成

This commit is contained in:
hunlongyu
2019-12-23 15:45:35 +08:00
parent 3488d7c2ed
commit f6bef563d2
15 changed files with 400 additions and 151 deletions

View File

@@ -4,9 +4,9 @@
<Sider class="sider" width="70"><ZYSider /></Sider>
<Layout>
<Header class="header"><ZYHeader /></Header>
<Content class="content">
<ZYContent class="content">
<router-view />
</Content>
</ZYContent>
</Layout>
</Layout>
</div>
@@ -15,6 +15,7 @@
import { mapGetters, mapActions } from 'vuex'
import ZYSider from '@/components/zy_sider.vue'
import ZYHeader from '@/components/zy_header.vue'
import ZYContent from '@/components/zy_content.vue'
import setting from './plugin/nedb/setting'
export default {
name: 'app',
@@ -28,7 +29,8 @@ export default {
},
components: {
ZYSider,
ZYHeader
ZYHeader,
ZYContent
},
methods: {
...mapActions([
@@ -63,5 +65,9 @@ html, body, #app, .box{
height: 50px;
padding: 0;
}
.content{
width: 100%;
height: 100%;
}
}
</style>

View File

@@ -1,5 +1,5 @@
<template>
<Row></Row>
<router-view />
</template>
<script>
export default {

View File

@@ -18,7 +18,11 @@ export default {
</script>
<style lang="scss" scoped>
.header-box{
height: 100%;
position: absolute;
top: 0;
left: 70px;
width: calc(100% - 70px);
height: 50px;
-webkit-app-region: drag;
-webkit-user-select: none;
display: flex;

View File

@@ -2,8 +2,8 @@
<Row class="sider-box">
<div class="top">
<Icon :class="iconActive === 'search' ? 'active': ''" type="md-search" @click="iconClickEvent('search')"/>
<Icon :class="iconActive === 'detail' ? 'active': ''" type="md-list" @click="iconClickEvent('detail')"/>
<Icon :class="iconActive === 'play' ? 'active': ''" type="md-play" @click="iconClickEvent('play')"/>
<Icon v-show="Object.keys(video).length !== 0" :class="iconActive === 'detail' ? 'active': ''" type="md-list" @click="iconClickEvent('detail')"/>
<Icon v-show="Object.keys(video).length !== 0" :class="iconActive === 'play' ? 'active': ''" type="md-play" @click="iconClickEvent('play')"/>
<Icon :class="iconActive === 'collection' ? 'active': ''" type="md-star" @click="iconClickEvent('collection')"/>
</div>
<div class="bottom">
@@ -17,6 +17,9 @@ export default {
computed: {
iconActive () {
return this.$store.getters.getIconActive
},
video () {
return this.$store.getters.getVideo
}
},
methods: {
@@ -24,6 +27,9 @@ export default {
this.$router.push({ name: e })
this.$store.commit('SET_ICON_ACTIVE', e)
}
},
created () {
console.log(this.video)
}
}
</script>

View File

@@ -1,6 +1,7 @@
import Vue from 'vue'
import Vuex from 'vuex'
import setting from '@/plugin/nedb/setting'
import video from '@/plugin/nedb/video'
Vue.use(Vuex)
@@ -11,8 +12,7 @@ export default new Vuex.Store({
color: 'light'
},
iconActive: 'search',
video: {},
videoList: []
video: {}
},
getters: {
getTheme: state => {
@@ -23,9 +23,6 @@ export default new Vuex.Store({
},
getVideo: state => {
return state.video
},
getVideoList: state => {
return state.videoList
}
},
mutations: {
@@ -37,9 +34,6 @@ export default new Vuex.Store({
},
SET_VIDEO: (state, payload) => {
state.video = payload
},
SET_VIDEO_LIST: (state, payload) => {
state.videoList = payload
}
},
actions: {
@@ -47,6 +41,11 @@ export default new Vuex.Store({
setting.update(payload.id, { theme: payload.color }).then(res => {
commit('SET_THEME', payload)
})
},
saveVideo: ({ commit }, payload) => {
video.add(payload).then(res => {
console.log(res)
})
}
}
})

94
src/util/util.666zy.js Normal file
View File

@@ -0,0 +1,94 @@
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

@@ -1,41 +0,0 @@
// import Axios from "axios"
import axios from 'axios'
const detail = {
getList (url) {
return new Promise((resolve, reject) => {
axios({
url: url,
method: 'get'
}).then(res => {
resolve(this.parser(res.data))
}).catch(err => {
reject(err)
})
})
},
parser (txt) {
return new Promise((resolve, reject) => {
const parser = new DOMParser()
let html = parser.parseFromString(txt, 'text/html')
let data = {
box: null,
info: null,
m3u8: null
}
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.m3u8 = arr
resolve(data)
})
}
}
export default detail

View File

@@ -1,53 +0,0 @@
// import Axios from "axios"
import axios from 'axios'
const video = {
getList (url, txt) {
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 (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)
}
resolve(data)
})
}
}
export default video

View File

@@ -54,7 +54,9 @@ export default {
})
},
play (e) {
console.log(e)
this.$router.push({ name: 'play' })
this.$store.commit('SET_ICON_ACTIVE', 'play')
this.$store.commit('SET_VIDEO', e)
},
detailShow (e) {
this.$store.commit('SET_ICON_ACTIVE', 'detail')

View File

@@ -3,12 +3,12 @@
<div v-show="box" class="detail-box" v-html="data.box"></div>
<div v-show="box" class="detail-box" v-html="data.info"></div>
<div v-show="box" class="detail-box">
<Button v-for="(i, j) in data.m3u8" :key="j" @click="playBtn(i, j, video)">{{i | ftLink}}</Button>
<Button v-for="(i, j) in data.urls" :key="j" @click="playBtn(i, j, video)">{{i | ftLink}}</Button>
</div>
</div>
</template>
<script>
import detail from '@/util/util.detail'
import haku from '@/util/util.666zy'
import { mapMutations } from 'vuex'
export default {
name: 'detail',
@@ -35,18 +35,21 @@ export default {
},
methods: {
...mapMutations([
'SET_VIDEO_LIST',
'SET_DETAIL'
'SET_VIDEO'
]),
async getDetail () {
this.box = false
let url = this.video.detail
this.data = await detail.getList(url)
this.SET_VIDEO_LIST(this.data.m3u8)
this.data = await haku.getDetail(url)
this.video.urls = this.data.urls
this.video.check = true
this.box = true
},
playBtn (i, j, e) {
console.log(i, j, e, 'playBtn')
this.video.index = j
this.$store.commit('SET_VIDEO', this.video)
this.$router.push({ name: 'play' })
this.$store.commit('SET_ICON_ACTIVE', 'play')
}
},
created () {

View File

@@ -1,19 +1,39 @@
<template>
<Row class="player">
<div class="title">{{ video.name }}</div>
<div class="box"></div>
<div class="list"></div>
{{video}}
<div class="title">{{ video.name }} -- {{ info }}</div>
<div class="playerBox" id="xg"></div>
<div class="list">
<Button v-for="(i, j) in video.urls" :key="j" @click="playBtn(i, j, video)">{{i | ftLink}}</Button>
</div>
</Row>
</template>
<script>
import detail from '@/util/util.detail'
import 'xgplayer'
import Hls from 'xgplayer-hls.js'
import haku from '@/util/util.666zy'
export default {
name: 'player',
data () {
return {
data: {},
url: null
url: null,
xg: null,
info: '',
config: {
id: 'xg',
url: null,
fluid: true,
autoplay: true,
keyShortcut: 'on',
defaultPlaybackRate: 1,
playbackRate: [0.5, 0.75, 1, 1.5, 2]
}
}
},
filters: {
ftLink (e) {
let name = e.split('$')[0]
return name
}
},
computed: {
@@ -22,14 +42,62 @@ export default {
}
},
methods: {
init () {
if (this.video.check) {
let url = this.video.urls[this.video.index].split('$')[1]
this.info = this.video.urls[this.video.index].split('$')[0]
this.$nextTick(() => {
this.playEvent(url)
})
} else {
this.getDetail()
}
},
async getDetail () {
let url = this.video.detail
this.data = await detail.getList(url)
console.log(this.data.m3u8)
let d = this.video.detail
let index = this.video.index
this.data = await haku.getDetail(d)
let urls = this.data.urls
this.video.urls = urls
this.video.check = true
let playUrl = urls[index].split('$')[1]
this.info = urls[index].split('$')[0]
this.$nextTick(() => {
this.playEvent(playUrl)
})
},
playEvent (e) {
this.config.url = e
this.xg = new Hls(this.config)
},
playBtn (i, j, e) {
this.video.index = j
let url = this.video.urls[this.video.index].split('$')[1]
this.xg.src = url
}
},
created () {
this.getDetail()
this.init()
}
}
</script>
<style lang="scss" scoped>
.player{
padding: 10px;
.title{
margin-bottom: 8px;
font-size: 18px;
}
.playerBox{
width: 100%;
max-width: 600px;
}
.list{
margin-top: 10px;
button{
margin-right: 10px;
margin-bottom: 10px;
}
}
}
</style>

View File

@@ -21,13 +21,14 @@
</template>
<script>
import db from '@/plugin/nedb/video'
import video from '@/util/util.video'
import haku from '@/util/util.666zy'
import { mapGetters } from 'vuex'
export default {
name: 'search',
data () {
return {
txt: '吸血鬼',
active: true,
txt: '',
active: false,
percent: 0,
columns: [
{
@@ -57,10 +58,13 @@ export default {
loading: true
}
},
computed: {
...mapGetters(['getVideo'])
},
methods: {
async searchEvent () {
if (this.txt !== '') {
this.data = await video.getList('http://www.666zy.com/', this.txt)
this.data = await haku.getHtml(this.txt)
this.active = true
this.loading = false
this.percent = 20
@@ -71,19 +75,28 @@ export default {
this.active = false
},
play (e) {
this.$router.push({ name: 'play' })
if (this.getVideo.detail !== e.detail) {
this.$store.commit('SET_VIDEO', e)
}
this.$store.commit('SET_ICON_ACTIVE', 'play')
this.$store.commit('SET_VIDEO', e)
this.$router.push({ name: 'play' })
},
collection (e) {
async collection (e) {
let d = await haku.getDetail(e.detail)
let data = {
category: e.category,
detail: e.detail,
name: e.name,
time: e.time
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 => {
console.log(res, 'find')
if (res.length >= 1) {
this.$Notice.warning({
title: '资源已存在',
@@ -91,7 +104,6 @@ export default {
})
} else {
db.add(data).then(res => {
console.log(res, 'add')
this.$Notice.success({
title: '收藏成功',
backgroud: true
@@ -105,9 +117,6 @@ export default {
this.$store.commit('SET_ICON_ACTIVE', 'detail')
this.$router.push({ name: 'detail' })
}
},
created () {
this.searchEvent()
}
}
</script>

View File

@@ -2,7 +2,6 @@
<Row>
<Button type="primary" @click="changeTheme({ id: getTheme.id, color: 'light' })">light</Button>
<Button type="primary" @click="changeTheme({ id: getTheme.id, color: 'dark' })">Dark</Button>
<Button type="primary" @click="add()">Add</Button>
</Row>
</template>
<script>