课程学习时长的记录

This commit is contained in:
daihh
2022-10-10 17:24:54 +08:00
parent d74e487e49
commit 92fa7ebf76
2 changed files with 104 additions and 72 deletions

View File

@@ -10,6 +10,7 @@ const baseURL = process.env.VUE_APP_STAT_BASE_API;
"title": "浏览案例【案例名称】",//事件的标题 "title": "浏览案例【案例名称】",//事件的标题
"parameters":"",//用户自定义参数 name:value,name:value "parameters":"",//用户自定义参数 name:value,name:value
"content": "案例名称",//事件的内容 "content": "案例名称",//事件的内容
"source":"页面事件",
"objId": "案例id",//关联的id "objId": "案例id",//关联的id
"objType": "3",//关联的类型 "objType": "3",//关联的类型
"objInfo": "记录一般折内容部分", "objInfo": "记录一般折内容部分",

View File

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