123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680 |
- <template>
- <view style="display: flex;justify-content: space-between;align-items: center;" @click="getVideo">
- <view style="display: flex;justify-content: space-between;margin: 20rpx 0;width: 100%;">
- <view style="display: flex;align-items: center;flex:1;">
- <view class="tag tagColor1" v-if="menuItem.sectionType==1">录播</view>
- <view class="tag tagColor2" v-if="menuItem.sectionType==2">直播</view>
- <view class="tag tagColor3" v-if="menuItem.sectionType==3">回放</view>
- <view class="t_content">
- <view v-if="menuItem.sectionType==1" :class="playSectionId==newId && playNextId==playId?'color1':''">{{menuItem.name || ''}}</view>
- <view v-if="menuItem.sectionType==2" :class="playSectionId==newId && playNextId==playId?'color2':''">{{menuItem.name || ''}}</view>
- <view v-if="menuItem.sectionType==3" :class="playSectionId==newId && playNextId==playId?'color3':''">{{menuItem.name || ''}}</view>
- <view style="font-size: 20rpx;color: #FF3B30;" v-if="menuItem.sectionType==2 && menuItem.liveStartTime">
- <view v-if="menuItem.liveStartTime>nowTime || !isBuy">
- <text>{{$method.timestampToTime(menuItem.liveStartTime, isDay =false)}}</text>-
- <text>{{$method.timestampToTime(menuItem.liveEndTime, isDay =false)}}</text>
- </view>
- <template v-if="isLast()">
- <view v-if="liveLast.watchStatus == 'live'">
- <text>直播中</text>
- </view>
- <view v-if="liveLast.watchStatus == 'end'">
- <text>当前直播回放视频请稍后再查看</text>
- </view>
- </template>
- <!-- <view v-if="menuItem.liveStartTime<=nowTime&&menuItem.liveEndTime>nowTime">
- <text>直播中</text>
- </view>
- <view v-if="menuItem.liveEndTime<nowTime">
- <text>回放</text>
- </view> -->
- </view>
- <view style="font-size: 20rpx;color: #FF3B30;" v-if="menuItem.sectionType == 3">
- <view v-if="!menuItem.recordingUrl">
- <text>当前直播回放视频请稍后再查看</text>
- </view>
- <view v-else>
- 回放中
- </view>
- </view>
- </view>
- <view v-if="menuItem.sectionType==null">{{menuItem.name || ''}}</view>
- </view>
- <view style="font-size: 20rpx;color: #FF3B30;" v-if="menuItem.liveStartTime && menuItem.sectionType != 3 && isBuy">
-
- <template v-if="!isLast() && !isLive">
- <view class="tagWillPlay" v-if="menuItem.liveStartTime>nowTime">
- <text>待开播</text>
- </view>
- <view class="tagPlaying" v-if="menuItem.liveStartTime<=nowTime&&menuItem.liveEndTime>nowTime">
- <text>直播中</text>
- </view>
- <view class="tagPlayed" v-if="menuItem.liveEndTime<nowTime">
- <text>已结束</text>
- </view>
- </template>
-
- </view>
- <!-- 直播课程没有学习状态 -->
- <template v-if="!isLive">
- <view v-if="(isRebuild||menuItem.rebuild>0)" class="tagRe">待重修</view>
- <view v-else>
- <view v-if="menuItem.learning==1" class="tagGreen">已看完</view>
- </view>
- </template>
-
-
- </view>
- <view v-if="menuItem.tryListen&&!isBuy" class="tryBox">
- 试看
- </view>
- </view>
- </template>
- <script>
- import { mapGetters } from 'vuex';
- import eventHub from '@/common/eventHub.js'
- import {WEBVIEW_URL} from '@/common/request.js'
- export default {
- name: 'courseSection',
- props: {
- isLive:false, //是否是直播课
- orderGoodsId:{
- default:0
- },
- preItem:{
- default:undefined,
- },
- learningOrder:{ //是否设置学习顺序 1 章节顺序 0不设置 2从头学到尾顺序
- type:Number,
- default:0
- },
- courseId: {
- type: Number,
- default: 0
- },
- goodsId: {
- type: Number,
- default: 0
- },
- menuItem: {
- type: Object,
- default: {}
- },
- isBuy: {
- type: Boolean,
- default: false
- },
- levelId: {
- type: String,
- default: ""
- },
- isRebuild: {
- type: Boolean,
- default: false
- },
- gradeId: {
- type: Number,
- default: 0
- },
- nextMenuItem: {
- type: Object,
- default: {}
- },
- sectionMaxNum:{
- default:undefined,
- },
- },
- watch:{
- menuItem(val) {
- console.log(val,'val')
- }
- },
- data() {
- return {
- nowTime:0,
- newId:0,
- playId:'',
- clickLock:false, //点击锁,防止连续点击多次
- };
- },
- onLoad() {
- },
- created() {
-
- },
- mounted() {
- this.nowTime = Number(new Date().getTime()/1000).toFixed(0)
- this.newId= this.menuItem.sectionId>0?this.menuItem.sectionId:this.menuItem.menuId
- console.log(this.newId,'this.newId', this.playNextId)
- console.log(this.playSectionId,'this.playSectionId')
- console.log(this.isRebuild)
- console.log(this.nextMenuItem,'nextMenuItem')
- console.log(this.menuItem,'this.menuItem=======>',this.menuItem.recordingUrl, this.nowTime)
- let moduleId = this.menuItem.moduleId || 0;
- let chapterId = this.menuItem.chapterId || 0;
- let sectionId = this.menuItem.sectionId || this.menuItem.menuId;
- let playNextId = `moduleId${moduleId}chapterId${chapterId}sectionId${sectionId}${this.isRebuild?'isRebuild':''}`;
- this.playId = playNextId;
- console.log('this.playId:', this.playId)
- uni.$off('playNext'+playNextId) //绑定前先移除之前的事件
- uni.$once('playNext'+playNextId, (data) => {
- //到时会触发每个节的监听事件,只允许当前节的接收
- let self = this
-
- if(this.nextMenuItem.recordingUrl&&this.isRebuild&&(this.newId==this.playSectionId) && data.fromRebuild){ // fromRebuild 来自重修目录的点击才弹出播放下一节
- //重修存在下一节
- uni.showModal({
- title: '提示',
- content: '是否播放下一节',
- success: function (res) {
- if (res.confirm) {
- console.log('用户点击确定');
- let nextId= self.nextMenuItem.sectionId>0?self.nextMenuItem.sectionId:self.nextMenuItem.menuId
- //设置播放的节ID
- self.$store.commit('setPlaySectionId', {playSectionId :nextId});
- self.$store.commit('setPlayVID', {playVID :self.nextMenuItem.recordingUrl});
- let ids = self.levelId.split('-');
- ids[2] = nextId
- uni.$emit('levelId', ids.join('-'))
- uni.$emit('getSection', self.nextMenuItem)
- self.$emit('playEnd',{isRebuild:self.isRebuild})
- // uni.$off('playend')
- // uni.$on('playend',res => {
- // console.log('playend2')
- // this.$emit('playEnd',{isRebuild:this.isRebuild})
- // })
-
- } else {
- let nextId= self.nextMenuItem.sectionId>0?self.nextMenuItem.sectionId:self.nextMenuItem.menuId
- //设置播放的节ID
- self.$store.commit('setPlaySectionId', {playSectionId :nextId});
- self.$store.commit('setPlayVID', {playVID :self.nextMenuItem.recordingUrl});
- let ids = self.levelId.split('-');
- ids[2] = nextId
- self.$emit('playEnd',{isRebuild:self.isRebuild})
- }
- }
- });
- } else {
- this.$emit('playEnd',{isRebuild:this.isRebuild})
- }
- });
- },
- methods: {
- isLast() {
- console.log(this.liveLast,'this.liveLast')
- if(this.liveLast) {
- let sectionASame = this.liveLast.sectionId == (this.menuItem.sectionId || this.menuItem.menuId)
- let chapterSame = this.liveLast.chapterId == (this.menuItem.chapterId || 0)
- let moduleSame = this.liveLast.moduleId == (this.menuItem.moduleId || 0);
- console.log(sectionASame && chapterSame && moduleSame,'sectionASame && chapterSame && moduleSame')
- return sectionASame && chapterSame && moduleSame
- } else {
- return false;
- }
-
- },
- studyRecordMenuAllList() {
- return new Promise(resolve => {
-
- this.$api.studyRecordMenuAllList({
- courseId:this.courseId,
- gradeId:this.gradeId,
- goodsId:this.goodsId
- }).then(res => {
- if(res.data.code == 200) {
- resolve(res.data.data)
- }
- })
- })
- },
- gradeCheckGoodsStudy() {
- let moduleId = this.menuItem.moduleId || 0;
- let chapterId = this.menuItem.chapterId || 0;
- let sectionId = this.menuItem.sectionId || this.menuItem.menuId;
- return new Promise(resolve => {
- this.$api.gradeCheckGoodsStudy({
- goodsId:this.goodsId,
- gradeId:this.gradeId,
- moduleId:this.menuItem.moduleId || 0,
- chapterId:this.menuItem.chapterId || 0,
- sectionId:this.menuItem.sectionId || this.menuItem.menuId
- }).then( res => {
- resolve(res.data.data)
- })
- })
- },
- goodsTodayStudySectionNum() {
- return new Promise(resolve => {
- this.$api.goodsTodayStudySectionNum({goodsId:this.goodsId,gradeId:this.gradeId}).then(res => {
- if(res.data.code == 200) {
- resolve(res.data.data)
- }
- })
- })
- },
- async getVideo(){
- if(this.clickLock) {
- return;
- }
- this.clickLock = true;
-
- if(this.learningOrder == 2 && !this.menuItem.isRebuild && !this.isLive) { //要按从头到尾顺序学习, 且不是重修课程
- if(this.preItem) {
- let rows = await this.studyRecordMenuAllList();
- let newRows = [];
- for(let i = 0; i < rows.length; i++ ) {
- let moduleTrue = rows[i].moduleId == this.menuItem.moduleId || rows[i].moduleId == 0
- let chapterTrue = rows[i].chapterId == this.menuItem.chapterId || rows[i].chapterId == 0;
- let sectionTrue = (rows[i].sectionId == this.menuItem.sectionId) || (rows[i].sectionId == this.menuItem.menuId);
- if(moduleTrue && chapterTrue && sectionTrue) {
- break;
- } else {
- if(rows[i].sectionType != 2) {
- newRows.push(rows[i])
- }
-
- }
- }
- console.log(newRows)
- let isAllLearn = newRows.every(item => {
- return item.studyStatus == 1;
- })
-
- if(isAllLearn) {
- this.playVideo();
- } else {
- uni.showToast({
- icon:'none',
- title:'请按顺序学习视频课程'
- })
- }
-
- // if(this.preItem.menuType == 3) { //上一个是节
- // if(this.preItem.learning == 1) { //上一节学完
- // this.playVideo();
- // } else {
- // uni.showToast({
- // icon:'none',
- // title:'请按顺序学习视频课程'
- // })
- // }
- // } else if(this.preItem.menuType == 2) { //上一个是章
- // this.$api.reSectionList({chapterId: this.preItem.menuId || this.preItem.chapterId,gradeId:this.gradeId,courseId:this.courseId,moduleId:this.preItem.moduleId || 0}).then(res => {
- // if(res.data.code==200){
- // let lastItem = res.data.data[res.data.data.length -1];
- // if(lastItem.learning == 1) {
- // this.playVideo();
- // } else {
- // uni.showToast({
- // icon:'none',
- // title:'请按顺序学习视频课程'
- // })
- // }
- // }
- // });
- // } else if(this.preItem.menuType == 1) { //上一个是模块
- // this.$api.reChapterList({moduleId:this.preItem.menuId,gradeId:this.gradeId,courseId:this.courseId}).then(res => {
- // if(res.data.code==200){
- // let lastChapterItem = res.data.data[res.data.data.length -1];
-
- // this.$api.reSectionList({chapterId:lastChapterItem.chapterId,gradeId:this.gradeId,courseId:this.courseId,moduleId:this.menuItem.menuId || this.menuItem.moduleId}).then(res => {
- // if(res.data.code==200){
- // let lastSectionItem = res.data.data[res.data.data.length -1];
- // if(lastSectionItem.learning == 1) {
- // this.playVideo();
- // } else {
- // uni.showToast({
- // icon:'none',
- // title:'请按顺序学习视频课程'
- // })
- // }
- // }
- // });
- // }
- // });
- // }
- } else { //第一章第一节
- this.playVideo();
- }
- } else {
- this.playVideo();
- }
-
-
- setTimeout(() => {
- this.clickLock = false;
- },3000)
-
- },
- studyRecordGetChannelBasicInfo(channelId) {
- return new Promise((resolve) => {
- this.$api
- .studyRecordGetChannelBasicInfo({
- channelId,
- })
- .then((res) => {
- resolve(res.data.data);
- });
- });
- },
- async playVideo() {
- console.log('直播的课程:',this.menuItem,this.menuItem.recordingUrl)
- if(this.menuItem.sectionType==1 || this.menuItem.sectionType == 3){
- //1录播 3回放
- if(!this.isBuy){
- //非购买
- if(!this.menuItem.tryListen){
- //不允许试听
- this.clickLock = false;
- return
- } else {
- this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
- this.$store.commit('setPlayVID', {playVID :this.menuItem.recordingUrl});
- this.menuItem.courseId = this.courseId;
- console.log('-----getSection-')
- uni.$emit('getSection', this.menuItem)
- return;
- }
-
- }
-
- let learnNum = await this.goodsTodayStudySectionNum()
- let hasLearn = await this.gradeCheckGoodsStudy();
-
- console.log(this.sectionMaxNum,'this.sectionMaxNum')
- console.log(learnNum,'learnNum')
- if(this.sectionMaxNum > 0) {
- if(learnNum >= this.sectionMaxNum && !hasLearn) {
- uni.showToast({
- icon:'none',
- title:`每天最多学习${this.sectionMaxNum}节`
- })
- this.clickLock = false;
- return;
- }
- }
- if(!this.menuItem.recordingUrl){
- uni.showToast({
- title: '暂无播放地址数据',
- icon: 'none'
- });
- this.clickLock = false;
- return;
- }
- /* if(this.playSectionId==this.newId){
- //切换为同一节
- return
- } */
- // 回放
- if (this.menuItem.sectionType == 3) {
- // return
- let moduleId = this.menuItem.moduleId || 0;
- let chapterId = this.menuItem.chapterId || 0;
- let sectionId = this.menuItem.sectionId || this.menuItem.menuId;
- let uuid = new Date().valueOf() + ""
- // buyCourse 是否购买课程:1是 0否,type=vod是回放
- let encode = encodeURIComponent(WEBVIEW_URL+'pages/live/index?token='+uni.getStorageSync('token')+'&userInfo='+JSON.stringify(this.userInfo)+
- '&channelId='+this.menuItem.liveUrl+'&gradeId='+this.gradeId+'&courseId='+this.courseId+'&goodsId='+this.goodsId+'&orderGoodsId='+this.orderGoodsId+
- '§ionId='+sectionId+'&chapterId='+chapterId+'&moduleId='+moduleId+'&buyCourse=1'+'&ident='+uuid+'§ionType=3'+'&vid='+this.menuItem.recordingUrl)
- uni.navigateTo({
- url:`../../pages/webview/index?url=`+encode
- })
- return
- }
- if(this.playSectionId>0){
- //切换视频
- let oldSectionId = this.playSectionId
- uni.$emit('changeSection', oldSectionId)
- }
- //设置播放的节ID
- this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
- this.$store.commit('setPlayVID', {playVID :this.menuItem.recordingUrl});
- this.$store.commit('updatePlayNextId',this.playId)
- uni.$emit('levelId', this.levelId)
- uni.$emit('getSection', this.menuItem)
- uni.$emit('isRebuild',this.isRebuild)
- console.log(this.menuItem,'menuItem')
- // uni.$off('playend')
- // uni.$on('playend',res => {
- // console.log('playend2')
- // this.$emit('playEnd',{isRebuild:this.isRebuild})
- // })
- console.log(999)
- }
- if(this.menuItem.sectionType==2){
- //直播
- if(!this.isBuy){
- //非购买
- this.clickLock = false;
- return
- }
-
- let learnNum = await this.goodsTodayStudySectionNum()
- let hasLearn = await this.gradeCheckGoodsStudy();
-
- console.log(this.sectionMaxNum,'this.sectionMaxNum')
- console.log(learnNum,'learnNum')
- if(this.sectionMaxNum > 0 && !this.isLive) {
- if(learnNum >= this.sectionMaxNum && !hasLearn) {
- uni.showToast({
- icon:'none',
- title:`每天最多学习${this.sectionMaxNum}节`
- })
- this.clickLock = false;
- return;
- }
- }
- if(!this.menuItem.liveUrl){
- uni.showToast({
- title: '暂无直播地址数据',
- icon: 'error'
- });
- return;
- }
-
- let data = await this.studyRecordGetChannelBasicInfo(this.menuItem.liveUrl);
- let nowTime = +this.$method.timest();
-
- if (this.menuItem.liveStartTime > nowTime) {
- if (data.watchStatus == "end" || data.watchStatus == "playback") {
- this.clickLock = false;
- uni.showToast({
- title: '直播未开始',
- icon: 'none'
- });
- return;
- }
- } else if (
- this.menuItem.liveStartTime < nowTime &&
- this.menuItem.liveEndTime > nowTime
- ) {
- if (data.watchStatus == "end" || data.watchStatus == "playback") {
- this.clickLock = false;
- uni.showToast({
- title: '暂无直播',
- icon: 'none'
- });
- return;
- }
- } else if (this.menuItem.liveEndTime < nowTime) {
- if (!data) {
- uni.showToast({
- title: '直播已结束',
- icon: 'none'
- });
- return;
- }
- if (data.watchStatus == "end" || data.watchStatus == "playback") {
- this.clickLock = false;
- uni.showToast({
- title: '直播已结束',
- icon: 'none'
- });
- return;
- }
- }
- // if (data.watchStatus == "end" || data.watchStatus == "playback") {
- // this.clickLock = false;
- // uni.showToast({
- // title: '直播已结束',
- // icon: 'none'
- // });
- // return;
- // }
- // if (data.watchStatus == "waiting") {
- // this.clickLock = false;
- // uni.showToast({
- // title: '直播未开始',
- // icon: 'none'
- // });
- // return;
- // }
-
- // if(this.playSectionId==this.newId){
- // //切换为同一频道
- // this.clickLock = false;
- // return
- // }
- let moduleId = this.menuItem.moduleId || 0;
- let chapterId = this.menuItem.chapterId || 0;
- let sectionId = this.menuItem.sectionId || this.menuItem.menuId;
- let uuid = new Date().valueOf() + ""
- // buyCourse 是否购买课程:1是 0否
- let encode = encodeURIComponent(WEBVIEW_URL+'pages/live/index?token='+uni.getStorageSync('token')+'&userInfo='+JSON.stringify(this.userInfo)+
- '&channelId='+this.menuItem.liveUrl+'&gradeId='+this.gradeId+'&courseId='+this.courseId+'&goodsId='+this.goodsId+'&orderGoodsId='+this.orderGoodsId+
- '§ionId='+sectionId+'&chapterId='+chapterId+'&moduleId='+moduleId+'&buyCourse=1'+'&ident='+uuid+'§ionType=2')
- uni.navigateTo({
- url:`../../pages/webview/index?url=`+encode
- })
-
- return;
- //设置播放的节ID
- // this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
- // this.$store.commit('setPlayChannelId', {playChannelId :this.menuItem.liveUrl});
- // this.$store.commit('updatePlayNextId',this.playId)
- // uni.$emit('levelId', this.levelId)
- // uni.$emit('getChannel', this.menuItem)
- // uni.$emit('isRebuild',this.isRebuild)
- // console.log(this.menuItem,'menuItem')
- // uni.$off('playend')
- // uni.$on('playend',res => {
- // console.log('playend1')
- // this.$emit('playEnd',{isRebuild:this.isRebuild})
- // })
-
- }
-
- }
- },
- computed: { ...mapGetters(['playSectionId','playChannelId','playVID','playNextId','userInfo','liveLast']) }
-
- };
- </script>
- <style scoped lang="scss">
- .tagGreen{
- width: 80rpx;
- height: 28rpx;
- background: #34C759;
- border-radius: 8rpx;
- font-size: 20rpx;
- color: #FFFFFF;
- text-align: center;
- }
- .tagWillPlay{
- width: 80rpx;
- height: 28rpx;
- background: #EBF4FF;
- border-radius: 8rpx;
- font-size: 20rpx;
- color: #007AFF;
- text-align: center;
- }
- .tagPlaying{
- width: 80rpx;
- height: 28rpx;
- background: #FFF7EB;
- border-radius: 8rpx;
- font-size: 20rpx;
- color: #FF9500;
- text-align: center;
- }
- .tagPlayed{
- width: 80rpx;
- height: 28rpx;
- background: #EEEEEE;
- border-radius: 8rpx;
- font-size: 20rpx;
- color: #666666;
- text-align: center;
- }
- .tagRe{
- width: 80rpx;
- height: 28rpx;
- background: #FF3B30;
- border-radius: 8rpx;
- font-size: 20rpx;
- color: #FFFFFF;
- text-align: center;
- }
- .tryBox{
- width: 103rpx;
- height: 48rpx;
- background: #fff;
- border-radius: 24rpx;
- color: #3577E8;
- font-size: 24rpx;
- line-height: 48rpx;
- text-align: center;
- border: 1rpx solid #3577E8;
- }
- .icon_up{
- width: 24rpx;
- height: 24rpx;
- }
- .t_content3{
- color: #007AFF;
- }
- .t_content2{
- color: #007AFF;
- }
- .t_content1{
- color: #007AFF;
- }
- .t_content{
- font-size: 30rpx;
- margin-left: 10rpx;
- color: #666666;
- flex:1;
- }
- .tagColor3{
- border: 2rpx solid #FF9500;
- color: #FF9500;
- }
- .tagColor2{
- border: 2rpx solid #FF3B30;
- color: #FF3B30;
- }
- .tagColor1{
- border: 2rpx solid #007AFF;
- color: #007AFF;
- }
- .color3{
- color: #FF9500;
- }
- .color2{
- color: #FF3B30;
- }
- .color1{
- color: #007AFF;
- }
- .tag{
- border-radius: 8rpx;
- font-size: 20rpx;
- padding: 5rpx;
- }
- </style>
|