Files
video_mini/pagesA/player/detailPlayer.vue
T
2025-08-25 11:20:35 +08:00

913 lines
26 KiB
Vue

<template>
<view class="pages">
<!-- #ifdef MP-WEIXIN -->
<view class="header" :style="{marginTop:searchBarTop + 'px',height:searchBarHeight + 'px'}">
<view style="height: 45px;display: flex;width: 100%;padding-left: 15rpx; " @tap.stop="back_load">
<image src="https://wxtietong.hnjrdzkj.xyz/static/wechat/static/on_back.png" style="width: 44rpx;height: 44rpx;"></image>
</view>
</view>
<!-- #endif -->
<!-- #ifdef H5 -->
<view class="header">
<view style="height: 45px;display: flex;width: 100%;padding-top: 10px; " @tap.stop="back_load">
<image src="https://wxtietong.hnjrdzkj.xyz/static/wechat/static/on_back.png" style="width: 44rpx;height: 44rpx;"></image>
</view>
</view>
<!-- #endif -->
<swiper class="swiper" :current="swiperCurrent" :indicator-dots="false" :autoplay="false" :vertical="true"
:duration="50" @change="currentChange" :style="{height:winHeight} ">
<swiper-item class="swiperItem" v-for="(videoItem,videoIndex) in videoListData" :key="videoItem._id">
<view class="swiperItemContent" style="color: #ffffff;">
<view class="payVideo" v-if="videoIndex == swiperCurrent && videoItem.pays == '2'">
<!-- #ifdef MP-WEIXIN -->
<video-player class="video"
:album-id="videoItem.album_id"
:cloud-type="1"
:autoplay="true"
:episode-id="videoItem.episode_id"
:controls="true"
:loop="false"
:enable-progress-gesture="false"
@ended="videoPlayerEnded"
:show-fullscreen-btn='false'
@loadedmetadata="loadedmetadata"
@error="videoPalyerErr">
</video-player>
<!-- #endif -->
<!-- #ifdef APP || H5-->
<video class="video"
:id="videoItem._id"
:poster="videoItem.img"
:autoplay="true"
object-fit="contain"
@ended="videoPlayerEnded"
@loadedmetadata="loadedmetadata"
:src="videoItem.src"></video>
<!-- #endif -->
</view>
<view class="noPayVideo" v-if="videoItem.pays == 1">
<image class="videoCove" :src="imageUrl+videoItem.img" mode="aspectFit"></image>
</view>
<view class="rightBtnList" v-if="videoIndex == swiperCurrent && videoItem.pays == 2">
<view class="btnItem" @click="userChangeLike(videoItem)" v-if="userInfo.id">
<image class="videoBtnImg" v-if="videoItem.like=='2'" src="https://wxtietong.hnjrdzkj.xyz/static/wechat/static/aixinRed.png"
mode="scaleToFill"></image>
<image class="videoBtnImg" v-else src="https://wxtietong.hnjrdzkj.xyz/static/wechat/static/aixin.png"
mode="scaleToFill"></image>
<view class="btnText">{{videoItem.like_n>0?videoItem.like_n:'0'}}</view>
</view>
<view class="btnItem" @click="userChangeStar(videoItem)" v-if="userInfo.id">
<image class="videoBtnImg" v-if="videoInfo.iszj=='2'" src="https://wxtietong.hnjrdzkj.xyz/static/wechat/static/scRed.png"
mode="scaleToFill"></image>
<image class="videoBtnImg" v-else src="https://wxtietong.hnjrdzkj.xyz/static/wechat/static/sc.png"
mode="scaleToFill"></image>
<!-- <text class="btnText" >{{videoItem.like_n>0?videoItem.iszj_n : '0'}}</text>-->
<view class=" btnTextRed" v-if="videoInfo.iszj=='2'">已追</view>
<view class="btnText" v-else>追剧</view>
</view>
<!-- #ifdef H5 -->
<view class="btnItem" @click="copyShareLink(videoItem)" v-if="userInfo.id">
<image class="videoBtnImg" src="https://wxtietong.hnjrdzkj.xyz/static/wechat/static/icon/share-fill.png" mode=""></image>
<view class="btnText">分享</view>
</view>
<!-- #endif -->
</view>
<view class="videoFooter" v-if="videoIndex == swiperCurrent && videoInfo.id" @click="showChoice">
<view class="videoName">
<image class="footerTv" src="https://wxtietong.hnjrdzkj.xyz/static/wechat/static/video.png" mode="scaleToFill"></image>
<text class="footerTvText">{{videoInfo.name}} · 当前第{{videoItem.weigh}}集/全{{videoInfo.sum}}集</text>
</view>
<view class="choiceVideo">
<text class="choiceVideoTexts">选集</text>
<uni-icons size="12" type="right" color="#ffffff"></uni-icons>
</view>
</view>
</view>
</swiper-item>
</swiper>
<recharge ref="rechargePups"
:userBeans="userBeansNum"
:play-video-info="playVideoDetail"
:video-info="videoInfo"
:pageHeight="pupHeight"
@rechargeSuccess="rechargeSuccess"
></recharge>
<selectVideo ref="choiceVideoPup" @choiceVideoItem="changePlaying" :play-video-info="playVideoDetail"
:video-info="videoInfo">
</selectVideo>
</view>
</template>
<script>
import selectVideo from "@/components/select/video.vue"
import recharge from "@/pagesA/components/recharge/rechargePup.vue"
import PAY from "@/utils/pay"
import login from "@/utils/login";
import config from "@/utils/config";
export default {
components: {
selectVideo,
recharge
},
data() {
return {
page: {
pageSize: 50,
currentPage: 1,
isNextPage: true,
},
userInfo: {},
swiperCurrent: 0,
playVideoDetail: {}, //
videoInfo: {}, //短剧简介
videoListData: [{
beans: Number,
fjname: String,
href: String,
id: Number,
img: String,
isplay: Boolean,
isvip: Number,
iszj: Number,
iszj_n: Number,
like: Number,
like_n: Number,
lx: Number,
mid: Number,
name: String,
pays: Number,
pid: Number,
price: String,
src: String,
state: String,
sum: Number,
videourl: String,
vipprice: String,
weigh: Number,
}], //剧集列表
swiperData: [], //
userBeansNum: 0,
videoId: '',
imageUrl: "",
searchBarTop:0,
searchBarHeight:0,
winHeight: '800px',
pupHeight: "400px",
onPlayVideo: null,
};
},
onLoad(e) {
console.log(e)
this.userinfo = uni.getStorageSync("userinfo");
this.getPageDefault();
this.checkQueryData(e);
if (this.userinfo.token) {
this.openid = uni.getStorageSync("openid");
if (e.adv_id && e.code) {
this.bindUser(e).then(res => {
console.log('bind user success')
// #ifdef APP || H5
this.get_user_info()
this.getVideoList()
// #endif
// #ifdef MP-WEIXIN
this.getWechartVideoDel(e)
// #endif
}).catch(err => {
console.log('bind user catch')
console.log(err)
})
} else {
// #ifdef APP || H5
this.get_user_info()
this.getVideoList()
// #endif
// #ifdef MP-WEIXIN
this.getWechartVideoDel(e)
// #endif
}
} else {
// #ifdef MP-WEIXIN
login.wxLogin().then(res=>{
this.openid = uni.getStorageSync("openid");
if (e.adv_id && e.code) {
this.bindUser(e).then(res => {
console.log('bind user success')
this.getWechartVideoDel(e)
}).catch(err => {
console.log('bind user catch')
console.log(err)
})
} else {
this.getWechartVideoDel(e)
}
})
// #endif
// #ifdef H5 ||APP
uni.showModal({
title: '提示',
content: '您还未登录,请先登录',
success: function (res) {
if (res.confirm) {
uni.navigateTo({
url: '/pagesA/login/login'
})
} else if (res.cancel) {
uni.switchTab({url: '/pages/tabs/home'})
}
}
})
// #endif
}
},
methods: {
// 获取页面宽高数据& 系统信息
getPageDefault() {
console.log(this.system, uni.getSystemInfoSync())
// #ifdef MP-WEIXIN
let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
this.searchBarTop = menuButtonInfo.top;
this.searchBarHeight = menuButtonInfo.height;
this.wxlx = 'wxxcx'
// #endif
//#ifdef H5
var ua = window.navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
this.wxlx = 'wxgzh';
}
//#endif
this.winHeight = uni.getWindowInfo().windowHeight+"px";
console.log(uni.getWindowInfo().windowHeight+"px")
this.pupHeight =( uni.getWindowInfo().windowHeight - 40 )+ "px";
uni.setStorage({
key: 'isbuy',
data: 1
})
uni.getSystemInfo({
success: res => {
this.safeArea = res.safeAreaInsets.bottom;
}
})
},
checkQueryData(e) {
if (e.start_free) {
this.free_start = Number(e.start_free)
this.free_end = Number(e.end_free)
if (Number(e.start_free) > 0) {
this.isAttention = true;
}
}
if (e.fxpid) {
if (e.fxpid > 0) {
uni.setStorage({
key: 'fxpid',
data: e.fxpid
})
}
}
if (e.vid) {
this.videoId = e.vid;
}
if (e.mid) {
this.mid = e.mid
}
console.log(this.free_start, this.free_end, this.isAttention)
},
// 绑定推荐
bindUser(data) {
let that = this
return new Promise((resolve, reject) => {
uni.setStorageSync('vs_id_code', data.vs_id);
let upData = {
uid: uni.getStorageSync("userinfo").id,
ad_id: data.code,
advertiser_id: data.advertiser_id,
clue_id: data.clue_id,
clue_token: data.clue_token,
click_id: data.clickid,
vid: data.vid,
mid: data.mid,
type: data.inventory,
vs_id: data.vs_id,
token: uni.getStorageSync("userinfo").token
}
that.$httpRequest({
url: '/api/user/callbackBinding',
data: upData,
methods:"GET"
}).then(res=>{
uni.setStorageSync('get_ad_code', res.data.code);
resolve(res)
}).catch(err=>{
reject(err)
})
})
},
// 获取播放器信息
getWechartVideoDel(data) {
let that = this
that.$httpRequest({
url: '/api/video/videoIdToDramaId',
data: {
vid: data.vid,
},
methods:"GET"
}).then(videoRes=>{
console.log(videoRes)
let fxpid = uni.getStorageSync("userinfo").id,
invite = uni.getStorageSync("userinfo").invite || '';
let param = JSON.stringify({
vid: data.vid,
mid: data.mid || 0,
fxpid: fxpid,
invite: invite
})
// 获取活动指定的是那一集并跳转到指定剧集
if(data.vs_id){
that.$httpRequest({
url: '/api/video/getPushDataInfo',
data: {
vs_id: data.vs_id || '',
},
methods: "GET",
isLoading: true,
}).then(advRes => {
let nums = advRes.data.weigh?advRes.data.weigh: 0
uni.redirectTo({
url: `plugin-private://wx94a6522b1d640c3b/pages/playlet/playlet?dramaId=${videoRes.data.drama_id}&srcAppid=${videoRes.data.appid?videoRes.data.appid:that.$config.mini_appid}&serialNo=${nums?nums:1}&extParam=${param}`
})
}).catch(advErr => {
console.log('get activity err');
console.log(advErr);
})
}else{
uni.redirectTo({
url: `plugin-private://wx94a6522b1d640c3b/pages/playlet/playlet?dramaId=${videoRes.data.drama_id}&srcAppid=${videoRes.data.appid?videoRes.data.appid:that.$config.mini_appid}&serialNo=${data.num?data.num:1}&extParam=${param}`
})
}
console.log(videoRes.data.appid?that.$config.mini_appid:videoRes.data.appid)
}).catch(videoErr=>{
console.log('get video id error')
console.log(videoErr)
})
},
// //获取个人信息
get_user_info() {
let that = this;
that.$httpRequest({
url:'/api/user/index'
}).then(res=>{
if (res.code == 1) {
uni.removeStorageSync("userinfo")
uni.setStorageSync('userinfo', res.data);
that.userInfo = res.data;
that.userBeansNum = res.data.beans;
}
}).catch(err=>{
console.log(err)
})
},
copyShareLink() {
var href = '/pagesA/player/detailPlayer?vid=' + this.videoId + '&fxpid=' + this.userInfo.id + '&mid=0'
// #ifdef H5
uni.setClipboardData({
data: config.webUrl + '/h5/#' + href,
complete() {
uni.showToast({
title: "分享连接已复制到剪贴板"
})
}
})
// #endif
// #ifndef H5
uni.share({
provider: "weixin",
scene: "WXSenceTimeline",
type: 0,
href: href,
title: '分享标题',
summary: '分享总结',
imageUrl: '',
success: function (res) {
console.log("success:" + JSON.stringify(res));
},
fail: function (err) {
console.log("fail:" + JSON.stringify(err));
}
})
// #endif
},
currentChange(val) {
console.log("swiper_chanage");
let that = this;
let isNext = false;
if (val.detail.current > that.swiperCurrent) {
// 下一集s
isNext = true;
}
// 是否即将到达当前页最后两条,为最后两条时获取下一页数据
if (that.videoListData.length <= that.swiperCurrent + 3 && that.page.isNextPage) {
that.getVideoList();
}
that.swiperCurrent = val.detail.current;
that.playVideoDetail = that.videoListData[that.swiperCurrent];
// 检查当前集是否支付,未支付触发支付
that.checkIsPaying();
},
//从列表选择第几集时
changePlaying(val) {
console.log('change Playing video', val)
let that = this;
console.log(val.ranking_num)
if (that.videoListData.length - 1 < val.ranking_num) {
// 当前视频列表数据不包含选中的数据
that.getVideoList(true, val.ranking_num - 1)
} else {
that.swiperCurrent = val.ranking_num;
console.log('选集', that.videoListData)
}
},
getVideoList(isSync, num) {
let that = this
if (that.page.isNextPage) {
console.log('get video List',)
that.$httpRequest({
url:'/api/video/videoinfo',
data:{
page: that.page.currentPage,
limit: that.page.pageSize,
vid: that.videoId,
}
}).then(res=>{
if (res.total < that.page.pageSize * that.page.currentPage) {
that.page.isNextPage = false;
}
if (that.page.currentPage == 1) {
res.videodata.iszj = res.data[0].iszj;
that.videoInfo = res.videodata;
uni.setNavigationBarTitle({title: res.videodata.name})
res.data.forEach(item => {
item._id = 'ks_' + item.id;
})
that.videoListData = res.data;
that.playVideoDetail = res.data[0];
that.checkIsPaying();
} else {
that.videoListData = that.videoListData.concat(res.data)
}
that.page.currentPage += 1;
if (isSync && that.videoListData.length > num + 1) {
// 等页面更新完调用,否则可能swiper还未加载
that.$nextTick(() => {
that.swiperCurrent = num;
console.log(that.swiperCurrent);
// 触发 swiperCurrent改变之后会获取选中集的路径,在此获取下一集的内容
})
} else if (isSync && that.videoListData.length < num + 1) {
that.getVideoList(isSync, num);
} else {
}
}).catch(err=>{
console.log(err)
})
}
},
checkIsPaying() {
console.log('check is can paying')
// 未支付
let that = this;
if (that.playVideoDetail.pays == 1) {
// 检查金豆余额是否足够支付
if (that.userBeansNum >= that.playVideoDetail.beans) {
// 用户是否开启自动金豆支付
if(that.userInfo.type){ //1自动扣费 2手动支付
// 金豆支付
that.beansPaying();
}else{
// 弹出支付询问弹窗
uni.showModal({
title: '提示',
content: '是否支付' + that.playVideoDetail.beans + '金豆观看视频',
success: function (res) {
if (res.confirm) {
that.beansPaying();
} else if (res.cancel) {
console.log('用户点击取消');
}
}
})
}
} else {
// 金豆余额不足显示充值
this.$refs.rechargePups.showRechargePup();
}
} else if (!that.playVideoDetail.src) {
that.getVideoSrc()
} else {
that.$nextTick(() => {
that.onPlayVideo = uni.createVideoContext(that.videoListData[that.swiperCurrent]._id, that);
console.log('check end play videos ')
that.onPlayVideo.play();
})
if (this.userInfo.id) {
that.upPlayNum();
}
}
},
beansPaying(){
let that = this;
let upData = {
buytype: "金豆",
beans: that.playVideoDetail.beans,
id: that.playVideoDetail.id,
smid: that.playVideoDetail.id,
wxlx:"wxxcx",
uid: that.userInfo.id,
token: that.userInfo.token,
sum: 1,
ad_code: uni.getStorageSync('get_ad_code'),
pricebuy: that.playVideoDetail.isvip == 2 ? that.playVideoDetail.vippriceq : that.playVideoDetail.priceq,
openid: uni.getStorageSync('openid'),
lx: 2,//1全集购买 2单集购买
}
PAY.pays.beansPay(upData).then(res => {
if (res.data.code == 1) {
that.videoListData[that.swiperCurrent].pays = 2;
that.userBeansNum -= that.playVideoDetail.beans;
// that.onPlayVideo = uni.createVideoContext(that.videoListData[that.swiperCurrent]._id, that);
console.log('buy success play videos')
// that.onPlayVideo.play();
// 更新播放
that.upPlayNum();
}else if(res.data.code ==0 && res.data.msg =='msg: "金豆不足"'){
this.$refs.rechargePups.showRechargePup();
}
}).catch(err => {
console.log(err)
})
},
rechargeSuccess(order) {
if (order.oid) {
this.page = {
pageSize: 80,
currentPage: 1,
isNextPage: true,
};
this.getVideoList(true, this.swiperCurrent, order.oid)
}
},
// 获取视频的src
getVideoSrc() {
let that = this;
that.$httpRequest({
url:'/api/video/memberUnlockVideo',
method: "GET",
data:{
smid: that.playVideoDetail.id,
vid: that.videoInfo.id,
},
isLoading: true,
}).then(res=>{
if (res.code == 1) {
uni.showLoading()
this.videoListData[this.swiperCurrent].src = res.data.src
this.$nextTick(() => {
that.onPlayVideo = uni.createVideoContext(that.playVideoDetail._id, that);
that.onPlayVideo.play();
})
}
}).catch(err=>{
console.log(err)
})
},
videoPalyerErr(err) {
console.log('tou tiao player err', err)
},
videoPlayerEnded() {
if (this.swiperCurrent == this.videoListData.length - 1) {
this.swiperCurrent = 0;
} else {
this.swiperCurrent = this.swiperCurrent + 1;
}
},
loadedmetadata() {
console.log("loadedmetadata end")
// #ifdef H5
setTimeout(() => {
this.onPlayVideo.play();
uni.hideLoading()
}, 500)
// #endif
},
upPlayNum() { //更新播放记录
let that = this
if (uni.getStorageSync("userinfo")) {
that.$httpRequest({
url:'/api/video/bfjl',
method: "GET",
data:{
vid: that.videoInfo.id,
mid: that.playVideoDetail.id,
uid: that.userInfo.id
},
}).then(res=>{
console.log('up play end')
})
}
},
// 修改
userChangeStar() {
let that = this;
that.$httpRequest({
url:'/api/user/videorecord',
method: "GET",
data:{
uid: that.userInfo.id,
vid: that.videoId,
mid: that.playVideoDetail.id,
ad_code: uni.getStorageSync('get_ad_code')
},
}).then(res=>{
that.videoInfo.iszj = that.videoInfo.iszj == 1 ? 2 : 1
uni.showToast({
icon: 'none',
title: res.msg
})
})
},
// 修改喜欢状态
userChangeLike() {
let that = this;
that.$httpRequest({
url:'/api/user/tapLove',
method: "GET",
data:{
vid: that.videoId,
mid: that.playVideoDetail.id
},
}).then(res=>{
that.playVideoDetail.like = that.playVideoDetail.like == 1 ? 2 : 1
let likeNUm = that.playVideoDetail.like_n
that.playVideoDetail.like_n = that.playVideoDetail.like == 1 ? likeNUm - 1 : likeNUm + 1
})
},
//返回
back_load() {
let that = this;
if (this.playVideoDetail.iszj == 1) {
uni.showModal({
title: '提示',
content: '是否将此剧加入追剧列表?',
success: function (res) {
if (res.confirm) {
that.userChangeStar()
} else if (res.cancel) {
uni.switchTab({
url: '/pages/tabs/home'
})
}
}
})
} else {
uni.switchTab({
url: '/pages/tabs/home'
})
}
},
showChoice() {
this.$refs.choiceVideoPup.showChoicePup()
}
},
onShareAppMessage: function (res) {
let that = this;
// #ifdef MP-WEIXIN || MP-TOUTIAO
let invite = this.userinfo.invite ? this.userinfo.invite : "";
let video = that.originList[that.originIndex];
var href = '/pagesA/player/detailPlayer?vid=' + this.videoId + '&fxpid=' + this.userinfo.id + '&mid=0' + '&invite=' +
invite + '&tt_album_id=' + video.album_id + '&tt_episode_id=' + video.episode_id
const obj = {
title: that.title_text,
imageUrl: '',
path: href,
success: function (res) {
console.log(res, "转发成功")
},
fail: function (res) {
wx.showToast({
title: '发送失败',
icon: 'none'
})
}
}
return obj
// #endif
},
};
</script>
<style scoped lang="scss">
.pages {
background-color: #000000;
height: 100vh;
}
.header {
width: 750rpx;
display: flex;
align-items: center;
flex-direction: row;
justify-content: space-between;
position: absolute;
top: 0;
z-index: 99;
}
.swiper {
width: 750rpx;
}
.swiperItemContent {
position: relative;
width: 750rpx;
height: 100%;
}
.payVideo {
width: 750rpx;
height: calc(100vh - 100rpx);
.video {
width: 750rpx;
height: calc(100vh - 100rpx);
}
}
.noPayVideo {
width: 750rpx;
height: 100%;
.videoCove {
width: 800rpx;
height: calc(100% - 70rpx);
}
}
.rightBtnList {
position: absolute;
right: 34rpx;
top: calc(50% - 200rpx);
width: 100rpx;
text-align: center;
z-index: 99;
.btnItem {
margin-top: 40rpx;
background: none;
text-align: center;
.videoBtnImg {
width: 64rpx;
height: 64rpx;
margin: 0 auto;
}
.btnText {
color: #FFFFFF;
text-align: center;
font-weight: bold;
font-size: 24rpx;
}
.btnTextRed {
color: red;
}
.wxClickBtn {
border: none;
background: none;
width: 100rpx;
opacity: 0;
height: 100rpx;
position: relative;
top: -100rpx;
left: 0;
}
}
}
.choiceTitleLine {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
padding: 0 40rpx;
.appText {
font-weight: 500;
font-size: 30rpx;
color: #333333;
}
.schoiceClose {
padding: 10rpx;
border-radius: 8rpx;
background: #f6f6f6;
}
}
.videoFooter {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
padding-left: 40rpx;
line-height: 70rpx;
height: 80rpx;
font-size: 22rpx;
color: #FFFFFF;
.footerTv {
width: 40rpx;
height: 26rpx;
margin-top: 6rpx;
margin-right: 20rpx;
}
.videoName {
display: flex;
flex-direction: row;
.footerTvText {
font-weight: 500;
font-size: 22rpx;
color: #FFFFFF;
line-height: 32rpx;
border-bottom: 2rpx solid #ffffff;
max-width: 600rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.choiceVideo {
display: flex;
flex-direction: row;
align-items: center;
padding-right: 20rpx;
.choiceVideoTexts {
font-size: 22rpx;
line-height: 70rpx;
color: #FFFFFF;
}
.footerChoice {
width: 34rpx;
height: 32rpx;
margin-top: 20rpx;
}
}
}
</style>