/**用于控制学习情况*/ const studyDurationKey='xus_duration'; const studyVideoSpeedKey='xus_video_speed'; const studyVideoKeyPre='xus_video'; /**保存播放速度*/ const setVideoSpeed=function(speed){ uni.setStorageSync(studyVideoSpeedKey,speed); } const getVideoSpeed=function(){ let speed=uni.getStorageSync(studyVideoSpeedKey); if(speed){ return Number(speed); }else{ return 1.0; } } /** * 设置视频的播放时间 * @param {} courseId * @param {*} time */ const setVideoTime=function(courseId,time){ uni.setStorageSync(studyVideoKeyPre+'_'+courseId,time); } /** * 获取本地存储的学习时长 */ const setStudyDuration=function(duration){ console.log(duration,'设置时长'); uni.setStorageSync(studyDurationKey,duration); } /** * 清除本地记录的学习时长 */ const clearStudyDuration=function(){ uni.setStorageSync(studyDurationKey,0); } const getStudyDuration=function(){ let speedValue=uni.getStorageSync(studyDurationKey); if(speedValue){ //console.log(speedValue,'speedValue'); return Number(speedValue); }else{ return 0; } } /** * 追加学习时长 * @param Number duration 学习时长(秒) */ const appendStudyDuration=function(duration){ let speedValue=uni.getStorageSync(studyDurationKey); if(speedValue){ localStorage.setStorageSync(studyDurationKey,Number(speedValue)+duration); }else{ localStorage.setStorageSync(studyDurationKey,duration); } } export default { setVideoSpeed, getVideoSpeed, getStudyDuration, setStudyDuration, clearStudyDuration, appendStudyDuration }