mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-mobile.git
synced 2025-12-07 01:46:44 +08:00
74 lines
1.5 KiB
JavaScript
74 lines
1.5 KiB
JavaScript
/**用于控制学习情况*/
|
|
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
|
|
}
|