diff --git a/pages/study/courseStudy.vue b/pages/study/courseStudy.vue index fc4d8e6..9f06c6e 100644 --- a/pages/study/courseStudy.vue +++ b/pages/study/courseStudy.vue @@ -225,13 +225,13 @@ - + {{con.cataName}} - + {{con.contentName}} @@ -265,7 +265,7 @@ - 收藏 + 已收藏收藏 @@ -458,9 +458,10 @@ handleTimeout:null, isAppendTime:true, appendStartTime: null, //记录追加的开始时间 - appendHandle:null, + appendHandle:null,//追加学习时长的timeout句柄 appentId:'',//当前追加的学习时长的id - appentInterval:30000,//追加学习时间的间隔 30秒加一次 + appentInterval:5000,//追加学习时间的间隔 3秒加一次 + handleTimeout: null, preTime:-1, blobUrl:'',//音视频的播放地址 localTimeKey:'boeu-study-time' ,//本地存储的学习时长的key json格式 @@ -1037,13 +1038,98 @@ //console.log(e); this.scrollInfo = e.detail; }, - //以下是插入相关的处理 + //以下是播放相关的处理 + saveStudyDuration(duration) { //保存本地存储的学习时长 + if (duration > 0) { + //发送用户学习事件 + //console.log('保存到后台学习时长='+duration); + let postData={ + "key": "StudyCourse",//课程学习的key + "title": "学习课程",//事件的标题 + "parameters":"second:"+duration,//second:value,total:value 本次的学习时长 + "content": "学习课程【"+this.courseInfo.name+"】",//事件的内容 + "objId": this.courseInfo.id,//课程的id + "objType": "1",//类型 + "source":"page", + "objInfo": ""+this.courseInfo.name, + "aid":this.userInfo.aid, //当前登录人的id + "aname":this.userInfo.name,//当前人的姓名 + "status": 1 //状态 + } + //静默处理 + apiStat.sendEvent(postData).then(rs=>{ + if(rs.status == 200) { + this.appendStartTime = new Date();//重新计时 + studyUtil.clearStudyDuration(); //清除本地存储 + } else { + console.log(rs.message); + } + }); + } + }, + //结束追加学习时长 + stopStudyTime(){ + //console.log('停止追加学习时长'); + this.isAppendTime=false; + if (this.appendHandle != null) { + window.clearTimeout(this.appendHandle); + } + }, + //追加学习时长, flag是否提交到后台 + appendStudyTime() { + //console.log('开始追加学习时长',this.isAppendTime); + if (this.studyId == '') { + return; + } + if (!this.curContent.id) { + return; + } + //清除之前的 + if(this.appendHandle != null) { + window.clearTimeout(this.appendHandle); + } + if (!this.isAppendTime) { + this.appendStartTime = null; + return; + } + //首先从本地读取 + let duration = studyUtil.getStudyDuration(); + //console.log('追加学习时长,当前本地积累的学习时长='+duration); + //追加学习长 + let $this = this; + if (this.appendStartTime == null) { + this.appendStartTime = new Date(); + this.appendHandle = setTimeout(function() { + $this.appendStudyTime(); + }, $this.appentInterval); //设置定时追加学习时长 + //保存之前的 + if (duration >0 ) { + this.saveStudyDuration(duration); + } + return; + } + //如果当前追加开始时间不为空 + let now = new Date(); + let m = now.getTime() - this.appendStartTime.getTime(); //相差的毫秒数 + let sen = parseInt(m / 1000); //计算秒数 + duration = duration + $this.appentInterval/1000;//追加的是秒 + if (sen>=60) { //一分钟保存一次 + this.saveStudyDuration(duration); + } else { + studyUtil.setStudyDuration(duration); //添加到本地存储中 + } + //启动下次追加学习时长 + this.appendHandle = setTimeout(function() { + $this.appendStudyTime(); + }, $this.appentInterval); + }, appendStudyOtherTime() { //非音视频课学习时长的增加,每一分钟保存一次 //console.log('开始追加学习时长',this.isAppendTime); if (this.studyId == '') { return; } - if (!this.contentData.id) { + + if (!this.curContent.id) { return; } let postData={ @@ -1087,9 +1173,9 @@ } this.touchNum = 0 },250) - }, - saveStudyItem(){ //先保存学习的内容,针对于音视频的内容 + //先保存学习的内容,针对于音视频的内容 + saveStudyItem(){ if(this.curContent.studyItemId) { return;//已经有记录的,不需要再保存了 } @@ -1174,39 +1260,39 @@ }, 200); }, onPlayerPlay(){ - this.isPlaying = true; - this.videoPlayingTime=0; - // console.log("开始播放"); - this.playerBoxShow=false; - this.isAppendTime=false; - this.videoSpeed=studyUtil.getVideoSpeed(); - this.videoPlayer.playbackRate(this.videoSpeed); - this.videoPlayer.play(); - let $this=this; - if(this.curContent.status<9){ - let completeType=this.curriculumData.completeSetup; - //console.log(completeType,'completeType'); - if(completeType==0){ - //默认5秒后学习完成. - $this.handleTimeout= setTimeout(function() {$this.saveStudyInfo();}, 5000); //5秒后记录学习完成 - }else{ - //先记录进行中的学习内容 - this.saveStudyItem(); - } - } + this.isPlaying = true; + this.videoPlayingTime=0; + // console.log("开始播放"); + this.playerBoxShow=false; + this.isAppendTime=true;//可以追加学习时长 + this.videoSpeed=studyUtil.getVideoSpeed(); + this.videoPlayer.playbackRate(this.videoSpeed); + this.videoPlayer.play(); + this.appendStudyTime();//开始追加学习时长 + let $this=this; + if(this.curContent.status<9){ + let completeType=this.curriculumData.completeSetup; + //console.log(completeType,'completeType'); + if(completeType==0){ + //默认5秒后学习完成. + //$this.handleTimeout= setTimeout(function() {$this.saveStudyInfo();}, 5000); //5秒后记录学习完成 + }else{ + //先记录进行中的学习内容 + this.saveStudyItem(); + } + } }, onPlayerPause(){ - this.isPlaying = false; - this.videoPlayer.pause(); + this.isPlaying = false; + this.videoPlayer.pause(); + this.stopStudyTime(); }, onPlayerEnded(){ this.playerBoxShow=true; - //console.log("播放结束"); - //this.isAppendTime=true;//开启追 - //加学习时间 - if(this.curContent.status<9){ - this.finishStudyItem(); - } + this.stopStudyTime(); + if(this.curContent.status<9){ + this.finishStudyItem(); + } }, changeSpeed(e) { // 获取选择的倍速 @@ -1239,7 +1325,6 @@ }, onPlayerPlaying(e){ //console.log("当前播放11",itme); - this.isAppendTime=false;//禁止追加学习时间 //console.log("当前播放11"+itme); let intTime=parseInt(e.detail.currentTime); if(intTime>this.videoPlayingTime){ @@ -1259,7 +1344,7 @@ if(percent>=finishPercent){ this.finishStudyItem(); } - }else if(completeType==2){ + }else{ if(intTime>=completeSecond){ this.finishStudyItem(); } @@ -1286,29 +1371,33 @@ } }, audioPlay(){ - this.isAppendTime=false; - let $this=this; - if(this.curContent.status<9){ - let completeType=this.curriculumData.completeSetup; - //console.log(completeType,'completeType'); - if(completeType==0){ - //默认5秒后学习完成. - $this.handleTimeout= setTimeout(function() {$this.saveStudyInfo();}, 5000); //5秒后记录学习完成 - }else{ - //先记录进行中的学习内容 - this.saveStudyItem(); - } - } + this.isAppendTime=true;//开始记录音视频的学习时长 + this.appendStudyTime();//开始追加学习时长 + // let $this=this; + // if(this.curContent.status<9){ + // let completeType=this.curriculumData.completeSetup; + // //console.log(completeType,'completeType'); + // if(completeType==0){ + // //默认5秒后学习完成. + // $this.handleTimeout= setTimeout(function() {$this.saveStudyInfo();}, 5000); //5秒后记录学习完成 + // }else{ + // //先记录进行中的学习内容 + // this.saveStudyItem(); + // } + // } }, audioEnd(){ + this.stopStudyTime(); if(this.curContent.status<9){ this.finishStudyItem(); } }, audioPause(){ + this.stopStudyTime(); }, audioPlaying(e,second){ - this.isAppendTime=false;//禁止追加学习时间 + this.isAppendTime=true;//打开追加载学习时长 + let intTime=second;//当前播放时间 let videDuration=e.duration;//音频总时长,秒 if(!videDuration){ @@ -1321,17 +1410,17 @@ completeSecond=5;//如果没有就采用默认的时间了 } if(completeType>0 && this.curContent.status<9){ //因为1按进度,2按时长都是计算时间,所以这里直接大于0处理 - if(completeType==1){ + if(completeType==1){ let finishPercent=this.curriculumData.setupTage; let percent =intTime*100/videDuration; if(percent>=finishPercent){ this.finishStudyItem(); } - }else if(completeType==2){ + }else{ if(intTime>=completeSecond){ this.finishStudyItem(); } - } + } } //以下是每隔10秒存储一下进度 let saveTime=Math.floor(intTime%10); @@ -1366,8 +1455,10 @@ studyId: this.studyId,//学习id, courseId: this.courseId,//课程id, contentId: this.curContent.id,//内容id, + contentType: this.curContent.contentType, contentName: this.curContent.contentName,//内容名称 progress: 100, + status: 9, contentTotal:this.totalContent } apiCourseStudy.studyContent(params).then(res=>{ @@ -1499,7 +1590,8 @@ display: flex; justify-content: center; .cinfo-btn{ - margin:30upx 60upx; + margin:30upx 80upx; + color:#999999; } } } diff --git a/utils/study.js b/utils/study.js index 8c885d4..5d39856 100644 --- a/utils/study.js +++ b/utils/study.js @@ -3,7 +3,7 @@ const studyDurationKey='xus_duration'; const studyVideoSpeedKey='xus_video_speed'; const studyVideoKeyPre='xus_video'; - +/**保存播放速度*/ const setVideoSpeed=function(speed){ uni.setStorageSync(studyVideoSpeedKey,speed); }