mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-11 20:06:44 +08:00
59 lines
1.2 KiB
JavaScript
59 lines
1.2 KiB
JavaScript
/**
|
|
* 用于处理,记录 学习的情况
|
|
*/
|
|
const studyDurationKey='xus_duration';
|
|
const studyVideoKeyPre='xus_video';
|
|
|
|
/**
|
|
* 设置视频的播放时间
|
|
* @param {} courseId
|
|
* @param {*} time
|
|
*/
|
|
const setVideoTime=function(courseId,time){
|
|
localStorage.setItem(studyVideoKeyPre+'_'+courseId,time);
|
|
}
|
|
|
|
/**
|
|
* 设置本地存储的学习时长
|
|
*/
|
|
const setStudyDuration=function(duration){
|
|
//console.log(duration,'设置时长');
|
|
localStorage.setItem(studyDurationKey,duration);
|
|
}
|
|
|
|
/**
|
|
* 清除本地记录的学习时长
|
|
*/
|
|
const clearStudyDuration=function(){
|
|
localStorage.setItem(studyDurationKey,0);
|
|
}
|
|
|
|
const getStudyDuration=function(){
|
|
let speedValue=localStorage.getItem(studyDurationKey);
|
|
if(speedValue){
|
|
//console.log(speedValue,'speedValue');
|
|
return Number(speedValue);
|
|
}else{
|
|
return 0;
|
|
}
|
|
}
|
|
/**
|
|
* 追加学习时长
|
|
* @param Number duration 学习时长(秒)
|
|
*/
|
|
const appendStudyDuration=function(duration){
|
|
let speedValue=localStorage.getItem(studyDurationKey);
|
|
if(speedValue){
|
|
localStorage.setItem(studyDurationKey,Number(speedValue)+duration);
|
|
}else{
|
|
localStorage.setItem(studyDurationKey,duration);
|
|
}
|
|
}
|
|
|
|
export default {
|
|
getStudyDuration,
|
|
setStudyDuration,
|
|
clearStudyDuration,
|
|
appendStudyDuration
|
|
}
|