diff --git a/src/api/phase2/stat.js b/src/api/phase2/stat.js index 11fb7a21..ffd539b9 100644 --- a/src/api/phase2/stat.js +++ b/src/api/phase2/stat.js @@ -10,6 +10,7 @@ const baseURL = process.env.VUE_APP_STAT_BASE_API; "title": "浏览案例【案例名称】",//事件的标题 "parameters":"",//用户自定义参数 name:value,name:value "content": "案例名称",//事件的内容 + "source":"页面事件", "objId": "案例id",//关联的id "objType": "3",//关联的类型 "objInfo": "记录一般折内容部分", diff --git a/src/views/study/coursenew.vue b/src/views/study/coursenew.vue index afca6a4b..be21f63e 100644 --- a/src/views/study/coursenew.vue +++ b/src/views/study/coursenew.vue @@ -219,6 +219,7 @@ import studyUtil from '@/utils/study.js'; import { encrypt } from '@/utils/jsencrypt.js'; import cookies from 'vue-cookies'; + import apiStat from '@/api/phase2/stat.js'; import apiStudy from '@/api/modules/courseStudy.js'; import apiVideoStudy from "@/api/modules/videoStudy.js"; import apiCourseGrade from '@/api/modules/courseGrade.js'; @@ -318,10 +319,10 @@ isPraise: false, isTrample: false, appendStartTime: null, //记录追加的开始时间 - appendHandle: null, + appendHandle: null, //追加学习时长的timeout句柄 isAppendTime: false, //是否追加学习时长 - appentId: '', //当前追加的学习时长的id - appentInterval: 30000, //追加学习时间的间隔 30秒加一次 + appentId: '', //当前追加的学习时长的id,此字段已经不再使用 + appentInterval: 5000, //追加学习时间的间隔 5秒加一次 handleTimeout: null, completed: [], tab: 1, @@ -371,20 +372,6 @@ } }, methods: { - /** - * 定时保存学习时长,每5秒保存在本地,每1分钟保存到服务端,清空本地数据 - * 如果一进入,本地数据存在,就先保存到服务器,然后再重新计算时长 - */ - autoLocalStudying(){ - - }, - autoSaveStudying(){ - let timeStr = localStorage.getItem(this.localTimeKey); - if(timeStr){ - let timeJson=JSON.parse(timeStr); - - } - }, //关注功能 toFollow(item) { apiFollow.save(item.teacherId).then(res => { @@ -429,7 +416,7 @@ } else { this.blobUrl = process.env.VUE_APP_BASE_API + '/xboe/m/course/cware/resource?sign=' + urlSign; } - console.log(this.blobUrl,'this.blobUrl'); + //console.log(this.blobUrl,'this.blobUrl'); }, widthOpen(url) { window.open(url, '_blank'); @@ -536,7 +523,7 @@ } else if (r.contentType == 62) { // 评估 //评估不需要查找,因为内容就是content中 - console.log('评估处理'); + //console.log('评估处理'); } if (this.contentData.status < 2) { this.contentData.status = 2; //进行中 @@ -737,6 +724,9 @@ //console.log("开始播放"); this.playerBoxShow = false; let $this = this; + //这里有些不准备,如果文件未能加载,这个事件就是错误的 + this.isAppendTime=true; + this.appendStudyTime();//启动追加学习时长 //console.log(this.contentData.status,'this.contentData.status'); // if(this.contentData.status<9){ // let completeType=this.curriculumData.completeSetup; @@ -777,16 +767,17 @@ }, onPlayerPause() { //console.log("暂停"); + this.stopStudyTime(); }, onPlayerEnded() { this.playerBoxShow = true; - if (this.contentData.status < 9) { + this.stopStudyTime(); + if(this.contentData.status < 9) { this.finishStudyItem(); } }, onPlayerPlaying(itme) { - this.isAppendTime = false; - this.appendStartTime = null; + this.isAppendTime = true;//可以追加学习时长 this.intTimeNote = parseInt(itme); //console.log("当前播放"+itme); //console.log("当前播放11"+itme); @@ -873,12 +864,16 @@ audioPlay() { //console.log("开始播放"); let $this = this; + this.isAppendTime=true; + this.appendStudyTime();//启动追加学习时长 }, audioPause() { //console.log("暂停"); + this.stopStudyTime();//启动追加学习时长 }, audioEnd() { //console.log("播放结束"); + this.stopStudyTime();//启动追加学习时长 if (this.contentData.status < 9) { this.finishStudyItem(); } @@ -1035,30 +1030,63 @@ } }); }, - saveStudyDuration() { //保存本地存储的学习时长 - let duration = studyUtil.getStudyDuration(); + saveStudyDuration(duration) { //保存本地存储的学习时长 if (duration > 0) { - let postData = { - id: this.appentId, - studyId: this.studyId, - courseId: this.courseInfo.id, - contentId: this.contentData.id, - studyInfo: this.courseInfo.name + - "-" + - this.contentData.contentName, - duration: duration - }; - apiStudy.appendStudyTime(postData).then(rs => { - if (rs.status == 200) { - this.appentId = rs.result; - studyUtil.clearStudyDuration(); //清除本地存储 - } else { - console.log(rs.message); + //发送用户学习事件 + 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":"页面事件", + "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); + } + }); + // let postData = { + // id: this.appentId, + // studyId: this.studyId, + // courseId: this.courseInfo.id, + // contentId: this.contentData.id, + // studyInfo: this.courseInfo.name + + // "-" + + // this.contentData.contentName, + // duration: duration + // }; + // apiStudy.appendStudyTime(postData).then(rs => { + // if (rs.status == 200) { + // this.appentId = rs.result; + // studyUtil.clearStudyDuration(); //清除本地存储 + // } else { + // console.log(rs.message); + // } + // }); } }, - appendStudyTime(flag) { + //结束追加学习时长 + stopStudyTime(){ + console.log('停止追加学习时长'); + this.isAppendTime=false; + if (this.appendHandle != null) { + window.clearTimeout(this.appendHandle); + } + }, + //追加学习时长, flag是否提交到后台 + appendStudyTime() { + //console.log('开始追加学习时长',this.isAppendTime); if (this.studyId == '') { return; } @@ -1075,50 +1103,53 @@ } //首先从本地读取 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 && flag) { - this.saveStudyDuration(); + }, $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 + sen; - if (flag) { - if (duration > 0) { - let postData = { - id: this.appentId, - studyId: this.studyId, - courseId: this.courseInfo.id, - contentId: this.contentData.id, - studyInfo: this.courseInfo.name + - "-" + - this.contentData.contentName, - duration: duration - }; - apiStudy.appendStudyTime(postData).then(rs => { - if (rs.status == 200) { - $this.appentId = rs.result; - $this.appendStartTime = new Date(); //重置开始时间 - studyUtil.clearStudyDuration(); //清除本地存储 - //this.appendHandle=setTimeout(function() {$this.appendStudyTime();}, $this.appentInterval); - } else { - console.log(rs.message); - } - }); - } + duration = duration + $this.appentInterval/1000;//追加的是秒 + if (sen>=60) { //一分钟保存一次 + this.saveStudyDuration(duration); + // if (duration > 0) { + // let postData = { + // id: this.appentId, + // studyId: this.studyId, + // courseId: this.courseInfo.id, + // contentId: this.contentData.id, + // studyInfo: this.courseInfo.name + + // "-" + + // this.contentData.contentName, + // duration: duration + // }; + // apiStudy.appendStudyTime(postData).then(rs => { + // if (rs.status == 200) { + // $this.appentId = rs.result; + // $this.appendStartTime = new Date(); //重置开始时间 + // studyUtil.clearStudyDuration(); //清除本地存储 + // //this.appendHandle=setTimeout(function() {$this.appendStudyTime();}, $this.appentInterval); + // } else { + // console.log(rs.message); + // } + // }); + // } } else { - $this.appendStartTime = new Date(); //重置开始时间 studyUtil.setStudyDuration(duration); //添加到本地存储中 } + //启动下次追加学习时长 this.appendHandle = setTimeout(function() { $this.appendStudyTime(); }, $this.appentInterval);