mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-mobile.git
synced 2025-12-10 11:26:47 +08:00
文章计时
This commit is contained in:
@@ -91,9 +91,7 @@
|
||||
|
||||
},
|
||||
destroyed() {
|
||||
if(this.setTime){
|
||||
clearTimeout(this.setTime);
|
||||
}
|
||||
this.setTime && clearTimeout(this.setTime);
|
||||
},
|
||||
onReachBottom(){
|
||||
this.getDetail()
|
||||
@@ -104,10 +102,30 @@
|
||||
methods: {
|
||||
// 发送计时
|
||||
sendEventData(){
|
||||
let event = {
|
||||
this.setTime && clearTimeout(this.setTime);
|
||||
let startTime = new Date().getTime();
|
||||
this.setTime = setTimeout(()=>{
|
||||
let endTime = new Date().getTime();
|
||||
let totalTime = Math.round((endTime - startTime) / 1000);
|
||||
this.cumulativeDuration += totalTime;
|
||||
console.log(this.cumulativeDuration,'时间');
|
||||
if(this.cumulativeDuration <= this.defaultMaxTime){
|
||||
this.sendStudyTime(totalTime)
|
||||
this.secondTime = 60
|
||||
this.sendEventData()
|
||||
}else{
|
||||
this.cumulativeDuration = 0
|
||||
clearTimeout(this.setTime);
|
||||
this.setTime = null
|
||||
}
|
||||
},this.secondTime * 1000);//15秒记录一次之后1分钟后记录
|
||||
},
|
||||
//发送学习时间
|
||||
sendStudyTime(totalTime){
|
||||
apiStat.sendEvent({
|
||||
key: "ReadArticle",//后台的事件key 发布文章且审核通过
|
||||
title: "阅读文章",//事件的标题
|
||||
parameters:"second:" + this.secondTime,//用户自定义参数 name:value,name:value
|
||||
parameters:"second:" + totalTime,//用户自定义参数 name:value,name:value
|
||||
content: "阅读了文章",//事件的内容
|
||||
source:'page',
|
||||
objId: this.id,//关联的id
|
||||
@@ -117,19 +135,7 @@
|
||||
aname: this.userInfo.name,//当前人的姓名
|
||||
status: 1 ,//状态,直接写1
|
||||
source:"h5",
|
||||
}
|
||||
this.setTime = setTimeout(()=>{
|
||||
this.cumulativeDuration += this.secondTime
|
||||
if(this.cumulativeDuration <= this.defaultMaxTime){
|
||||
apiStat.sendEvent(event);
|
||||
this.secondTime = 60
|
||||
this.sendEventData()
|
||||
}else{
|
||||
this.cumulativeDuration = 0
|
||||
clearTimeout(this.setTime);
|
||||
this.setTime = null
|
||||
}
|
||||
},this.secondTime * 1000);//15秒记录一次之后1分钟后记录
|
||||
});
|
||||
},
|
||||
getDetail(){
|
||||
uni.showLoading({title:'加载中...'});
|
||||
|
||||
Reference in New Issue
Block a user