video_app/pages/video/video.nvue

608 lines
15 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="detail">
<list @loadmore="getData()" :loadmoreoffset="wHeight*3" :show-scrollbar="false" ref="listBox"
:pagingEnabled="true" :scrollable="true">
<cell v-for="(item,i) in videoList" :key="i" :ref="'list'+item.courseDetailsId">
<view class="swipers-items" @longpress="openBs()" @appear="appear(item.courseDetailsId,i)"
:style="boxStyle">
<!-- 视频 -->
<video :show-fullscreen-btn="false" @controlstoggle="controlstoggles" object-fit="cover"
v-if="isShowVideo == item.courseDetailsId && item.videoUrl" :play-strategy="2"
:show-loading="true" codec="software" :muted="false" :show-center-play-btn="true" :loop="true"
@timeupdate="timeupdate"
@play="videoPlay('myVideo'+item.courseDetailsId, item.courseDetailsId)"
@ended="ended" :enable-progress-gesture="false" :poster="item.titleImg"
:ref="'myVideo'+item.courseDetailsId" :id="'myVideo'+item.courseDetailsId" :src="item.videoUrl"
:autoplay="item.autoPlay" class="swipers-items-video"></video>
<image v-else :src="item.titleImg" class="swipers-items-imgsbg" mode="aspectFill">
</image>
<!-- 右边操作 -->
<view class="swipers-items-right" :style="rightTop" v-if="showControls">
<view class="swipers-items-right-item">
<view class="swipers-items-right-item-img" @click.stop="dianzan(item)">
<image v-if="item.isGood!=null && item.isGood!=0" class="swipers-items-right-item-imgs"
src="../../static/images/me/myLove_.png" mode=""></image>
<image v-else class="swipers-items-right-item-imgs"
src="../../static/images/me/myLove.png" mode=""></image>
</view>
<view class="swipers-items-right-item-txt">
<text class="swipers-items-right-item-txts">
{{item.goodNum}}
</text>
</view>
</view>
<view class="swipers-items-right-item" @click="share()">
<view class="swipers-items-right-item-img">
<image class="swipers-items-right-item-imgs" src="../../static/images/me/share.png"
mode=""></image>
</view>
<view class="swipers-items-right-item-txt">
<text class="swipers-items-right-item-txts">
分享
</text>
</view>
</view>
<view class="swipers-items-right-item" v-if="item.isCollect==null || item.isCollect == 0">
<view class="swipers-items-right-item-img" @click.stop="shoucang(item)">
<image class="swipers-items-right-item-imgs" src="../../static/images/me/shuqian.png"
mode=""></image>
</view>
<view class="swipers-items-right-item-txt">
<text class="swipers-items-right-item-txts">
追剧
</text>
</view>
</view>
<view class="swipers-items-right-item" v-else>
<view class="swipers-items-right-item-img" @click.stop="shoucang(item)">
<image class="swipers-items-right-item-imgs" src="../../static/images/me/shuqian_s.png"
mode=""></image>
</view>
<view class="swipers-items-right-item-txt">
<text class="swipers-items-right-item-txts">
已追
</text>
</view>
</view>
</view>
<!-- 底部视频信息 -->
<view class="swipers-items-btom"
:style="{bottom:(item.rankCount && item.rankCount<30)?'160rpx':'100rpx'}" v-if="showControls">
<view class="swipers-items-btom-box">
<!-- 标题 -->
<view class="swipers-items-btom-box-title">
<text class="swipers-items-btom-box-titles">
{{item.title}}
</text>
</view>
<!-- 介绍 -->
<view v-if="item.content" class="swipers-items-btom-box-content">
<text class="swipers-items-btom-box-contents">{{item.content}}</text>
</view>
<!-- 集数 -->
<view @click="goCourse(item.courseId,item.courseDetailsId)"
class="swipers-items-btom-box-num">
<text class="swipers-items-btom-box-nums">
查看更多续集 >
</text>
</view>
</view>
</view>
</view>
</cell>
</list>
<uni-popup ref="popupBs" :safe-area="true" background-color="#ffffff">
<view class="bs">
<text class="bs-title">倍速:</text>
<view class="bs-se">
<view class="bs-se-i" @click="BsChange(index)" :class="nowBs==index?'bsActive':''"
v-for="(item,index) in subList" :key="index">
<text class="bs-se-it">{{item.name}}</text>
</view>
</view>
</view>
</uni-popup>
</view>
</template>
<script>
const listDom = uni.requireNativePlugin('dom')
import config from '../../common/config.js'
import httpsRequest from '../../common/httpRequest.js'
export default {
data() {
return {
nowBs: 1, //当前倍速
subList: [{
name: '0.5x',
num: 0.5
}, {
name: '1x',
num: 1
}, {
name: '1.25x',
num: 1.25
}, {
name: '1.5x',
num: 1.5
}],
isStart: false, //是否开始生成二维码
erweima: '',
qrCodeData: '',
haibaoImg: '',
showImg: false,
haibaoShow: false,
imgSrc: '',
current: 0,
maskCustomStyle: {
background: 'rgba(0, 0, 0, 0.5)'
},
show: false,
videoList: [],
videoContext: null, //记录当前视频的上下文
isVIP: false, //是否是vip
courseId: '',
meunList: [], //菜单
meunTop: 37, //返回图标距离顶部的距离
num: 1, //当前播放的集数
showPay: false, //购买视频的弹窗
info: {}, //整部的信息
courseDetailsId: '', //详情id
scrollIntoView: '', //当前播放视频的位置
scrollIntoViews: 'video0', //当前播放视频的位置
isVips: '否', //是否显示会员
rightTop: {
top: '0rpx'
},
title: '',
showControls: true, //是否显示控制中心
page: 1,
pages: 1,
limit: 10,
randomNum: 0,
wHeight: 0,
boxStyle: {
'height': 0,
'width': '750rpx',
},
isShowVideo: '',
playFlag: false
};
},
onShow() {
let that = this
//获取设备的高度
uni.getSystemInfo({
success(res) {
//计算右侧操作拦的位置
that.rightTop.top = res.screenHeight - (440 / 2) + 'rpx'
},
fail() {
//如果获取屏幕的高度失败那么位置默认设置为通用高度630rpx
that.rightTop.top = '630rpx'
}
})
this.page = 1
this.randomNum = Math.floor(Math.random() * 33);
this.getDataList()
},
onHide() {
try {
this.videoContext.stop();
this.videoContext = null;
setTimeout(() => {
this.meunList = [];
this.videoList = [];
this.current = 0;
}, 500)
} catch (e) {
//TODO handle the exception
}
},
onLoad() {
const sysInfo = uni.getSystemInfoSync()
this.wHeight = sysInfo.windowHeight
this.boxStyle.height = this.wHeight + 5;
this.$forceUpdate()
},
methods: {
//播放时的回掉
videoPlay(videoId,courseDetailsId) {
this.courseDetailsId = courseDetailsId
if ( !this.playFlag ) {
this.playFlag = true
httpsRequest.getT('app/course/viewCourse', {
courseId: this.courseId,
courseDetailsId: courseDetailsId,
type: 'start'
}).then(res => {
console.log('播放开始')
})
}
},
//播放进度变化回掉
timeupdate(e) {
if (e.detail.currentTime > e.detail.duration*0.9) {
if ( this.playFlag) {
this.playFlag = false
httpsRequest.getT('app/course/viewCourse', {
courseId: this.courseId,
courseDetailsId: this.courseDetailsId,
type: 'end'
}).then(res => {
console.log('播放结束')
})
}
}
},
appear(e, index) {
this.current = index
this.showControls = true
this.isShowVideo = e
this.scrollIntoViews = 'video' + index
this.scrollIntoView = 'video' + index
let numIdCurr = this.videoList[index].courseDetailsId;
this.videoContextId = 'myVideo' + numIdCurr;
this.videoContext = uni.createVideoContext(this.videoContextId, this);
//插入历史记录
this.setHistor(this.videoList[index].courseId, this.videoList[index].courseDetailsId);
this.$forceUpdate()
},
getData() {
if (this.page < this.pages) {
this.page += 1
this.getDataList()
this.$forceUpdate()
}
},
//显示/隐藏适配控制器的回调
controlstoggles(e) {
this.showControls = e.detail.show
console.log(e.detail.show, '显示/隐藏控制栏')
},
//打开倍速弹框
openBs() {
this.$refs.popupBs.open('bottom')
},
//切换倍速
BsChange(index) {
this.nowBs = index
this.videoContext.playbackRate(this.subList[index].num)
this.$refs.popupBs.close()
uni.showToast({
title: '已切换' + this.subList[index].num + '倍播放',
icon: 'none',
duration: 2000
})
},
// 跳转资源详情
goCourse(e, courseDetailsId) {
let userId = uni.getStorageSync('userId')
if (userId) {
// uni.navigateTo({
// url: '/pages/index/course/courseDet?id=' + e
// });
uni.navigateTo({
url: '/me/detail/detail?id=' + e + '&courseDetailsId=' + courseDetailsId
})
} else {
uni.navigateTo({
url: "/pages/login/login"
})
}
},
//分享-复制app下载连接
share() {
let invitationCode = ''
let qdCode = ''
if (uni.getStorageSync('invitationCode')) {
invitationCode = uni.getStorageSync('invitationCode')
}
if (uni.getStorageSync('qdCode')) {
qdCode = uni.getStorageSync('qdCode')
}
let url = config.APIHOST2 + '/pages/login/registerApp?invitation=' + invitationCode + '&qdCode=' + qdCode
uni.setClipboardData({
data: url,
success(res) {
uni.showToast({
title: '已复制链接'
})
}
})
},
//收藏
shoucang(item) {
if (uni.getStorageSync('token')) {
let data = {
courseId: item.courseId,
courseDetailsId: item.courseDetailsId,
classify: 1,
type: item.isCollect == 0 ? 1 : 0
}
httpsRequest.postJson('/app/courseCollect/insertCourseCollect', data).then(res => {
if (res.code == 0) {
if (data.type == 1) {
item.isCollect = 1;
} else {
item.isCollect = 0;
}
}
})
} else {
uni.navigateTo({
url: "/pages/login/login"
})
}
},
//点赞
dianzan(item) {
if (uni.getStorageSync('token')) {
let data = {
courseId: item.courseId,
courseDetailsId: item.courseDetailsId,
classify: 2,
type: item.isGood == 0 ? 1 : 0
};
httpsRequest.postJson('/app/courseCollect/insertCourseCollect', data).then(res => {
if (res.code == 0) {
if (data.type == 1) {
item.isGood = 1;
item.goodNum += 1;
} else {
item.isGood = 0;
item.goodNum -= 1;
}
}
})
} else {
uni.navigateTo({
url: "/pages/login/login"
})
}
},
ended() {
console.log(this.current, 'eeeeeeeeeeeee')
if (this.current < this.videoList.length - 1) {
// this.current += 1
this.$nextTick(() => {
let courseDetailsId = this.videoList[this.current + 1].courseDetailsId
console.log(courseDetailsId, '开始移动了')
const el = this.$refs['list' + courseDetailsId][0]
listDom.scrollToElement(el, {})
this.$forceUpdate()
console.log(el, '移动结束')
})
}
},
/**
* @param {Number} courseId 总id
* @param {Number} courseDetailsId 当前视频id
* @param {boolean} type 是购买后返回的还是直接进来的
*/
getDataList() {
let data = {
page: this.page,
limit: this.limit,
token: uni.getStorageSync('token') ? uni.getStorageSync('token') : '',
randomNum: this.randomNum
};
httpsRequest.getT('/app/course/selectCourseDetailsList', data).then(res => {
if (res.code == 0) {
this.pages = res.data.totalPage
if (res.data.list) {
let arr = JSON.parse(JSON.stringify(res.data.list))
arr.map((item, index) => {
item.autoPlay = true
})
//菜单数组
if (this.page == 1) {
this.videoList = arr
this.isShowVideo = this.videoList[0].courseDetailsId
} else {
this.videoList = [...this.videoList, ...arr]
}
if (this.page == 1) {
let numIdCurr = this.videoList[0].courseDetailsId;
this.videoContextId = 'myVideo' + numIdCurr;
this.$nextTick(() => {
this.videoContext = uni.createVideoContext(this.videoContextId, this);
this.videoContext.play();
})
if (uni.getStorageSync('token')) { //如果有token则插入
//插入历史记录
this.setHistor(this.videoList[this.current].courseId, this.videoList[this
.current]
.courseDetailsId)
}
}
this.$forceUpdate()
}
} else {
uni.showToast({
title: '加载失败',
icon: 'none'
})
setTimeout(() => {
uni.navigateBack();
}, 1000)
}
})
},
//插入观看记录
setHistor(courseId, courseDetailsId) {
if (uni.getStorageSync('token')) {
let data = {
courseId: courseId,
courseDetailsId: courseDetailsId,
classify: 3,
type: 1
};
httpsRequest.postJson('/app/courseCollect/insertCourseCollect', data).then(res => {})
}
},
}
}
</script>
<style>
.bs {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
padding: 20rpx;
}
.bs-title {
font-size: 24rpx;
font-weight: bold;
}
.bs-se {
display: flex;
flex-direction: row;
align-items: center;
background-color: #eeeeef;
padding: 10rpx 20rpx;
border-radius: 10rpx;
}
.bs-se-it {
font-size: 24rpx;
width: 100rpx;
padding: 16rpx 0;
text-align: center;
}
.bsActive {
background-color: #ffffff;
border-radius: 6rpx;
}
.detail {
width: 750rpx;
flex: 1;
background-color: #000;
overflow-y: hidden;
}
.swipers {
width: 750rpx;
flex: 1;
}
.swipers-item {
width: 750rpx;
flex: 1;
}
.swipers-items {
width: 750rpx;
flex: 1;
position: relative;
background-color: #000;
}
.swipers-items-video {
width: 750rpx;
flex: 1;
}
.swipers-items-imgsbg {
width: 750rpx;
flex: 1;
}
.swipers-items-right {
position: absolute;
width: 60rpx;
top: 100rpx;
right: 20rpx;
}
.swipers-items-right-item {
width: 60rpx;
margin-bottom: 40rpx;
}
.swipers-items-right-item-imgs {
width: 60rpx;
height: 60rpx;
border-radius: 50%;
}
.swipers-items-right-item-img {
width: 60rpx;
height: 60rpx;
}
.swipers-items-right-item-imgs {
width: 60rpx;
height: 60rpx;
}
.swipers-items-right-item-txt {
width: 60rpx;
}
.swipers-items-right-item-txts {
width: 60rpx;
color: #ffffff;
font-size: 24rpx;
text-align: center;
}
.swipers-items-btom {
width: 750rpx;
position: absolute;
/* bottom: 140rpx; */
align-items: center;
}
.swipers-items-btom-box {
width: 710rpx;
}
.swipers-items-btom-box-title {
width: 710rpx;
}
.swipers-items-btom-box-titles {
width: 710rpx;
color: #ffffff;
font-size: 30rpx;
}
.swipers-items-btom-box-content {
width: 710rpx;
margin-top: 10rpx;
}
.swipers-items-btom-box-contents {
width: 710rpx;
color: #ffffff;
font-size: 28rpx;
}
.swipers-items-btom-box-num {
width: 750rpx;
margin-top: 20rpx;
}
.swipers-items-btom-box-nums {
width: 710rpx;
color: #ffffff;
font-size: 30rpx;
}
</style>