医学道
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
video/src/hooks/unique_ident.ts

48 lines
987 B

import Taro from "@tarojs/taro";
import {curriculum} from "@/api";
const KEY = 'unique_ident'
/** 设置学习记录缓存 */
function set(data: HourCacheParam) {
Taro.removeStorageSync(KEY)
Taro.setStorage({
key: KEY,
data
})
}
/**
* 上传学习记录
* @param duration 视频播放的学习时长
* @param start_date 记录当前的时间戳
* @param upload 是否上传
*/
function put(duration?: number, start_date?: number, upload = true) {
const data: HourCacheParam | undefined = Taro.getStorageSync(KEY)
if (data) {
data.duration = duration || data.duration
data.start_date = start_date || data.start_date
Taro.setStorageSync(KEY, data)
if (upload) {
curriculum.hourCache(data.courseId, data)
}
}
}
function del() {
put()
const data: HourCacheParam | undefined = Taro.getStorageSync(KEY)
if (data) {
curriculum.delCache(data.courseId)
}
Taro.removeStorageSync(KEY)
}
export default {
set,
put,
del
}