学习记录

main
king 1 year ago
parent 98c6f8c3e5
commit b12641e1a7
  1. 9
      src/api/curriculum.ts
  2. 3
      src/app.tsx
  3. 5
      src/components/video/video.tsx
  4. 42
      src/hooks/unique_ident.ts
  5. 25
      src/pages/business/videoInfo/components/course.tsx
  6. 4
      src/pages/business/videoInfo/videoInfo.tsx
  7. BIN
      src/static/img/illnessTop.png
  8. 1
      types/curriculum.d.ts

@ -18,8 +18,6 @@ export interface CourseDepData {
}
export interface HourPlayData {
/** 独特的识别 */
unique_ident: number
/** 时间 */
duration: number
/** 格式 */
@ -117,10 +115,9 @@ export const curriculum = {
},
/** 学习记录 */
hourCache(courseId: number, data: HourCacheParam) {
return request(`/api/v1/course/${courseId}/hour/cache`, "PUT", data)
return request<number>(`/api/v1/course/${courseId}/hour/cache`, "PUT", data)
},
/** 删除 */
delCache(courseId: number) {
return request(`/api/v1/course/${courseId}/hour/cache`, "DELETE")
commit(courseId: number, data: HourCacheParam) {
return request(`/api/v1/course/${courseId}/hour/commit`, "PUT", data)
}
}

@ -1,7 +1,6 @@
import Taro, {useDidShow, useDidHide} from '@tarojs/taro'
import './app.scss'
import {CustomWrapper} from "@tarojs/components";
import unique_ident from "@/hooks/unique_ident";
import {Profile} from '@/store'
import storageDep from "@/hooks/storageDep";
@ -38,8 +37,6 @@ function App(props) {
Taro.useLaunch(() => {
updateApp()
storageDep.remove()
unique_ident.put()
unique_ident.del()
})
Taro.getSystemInfo({

@ -68,6 +68,7 @@ const HVideo: FC<HVideoOptions> = (opt: HVideoOptions) => {
opt.onEnded()
} else {
video?.seek(currentTime)
unique_ident.remove()
video?.play()
}
}
@ -96,7 +97,9 @@ const HVideo: FC<HVideoOptions> = (opt: HVideoOptions) => {
})
Taro.useUnload(() => {
unique_ident.del(currentTime, Date.now())
unique_ident.put(undefined, currentTime)
unique_ident.remove()
unique_ident.upload().then()
})

@ -5,44 +5,58 @@ const KEY = 'unique_ident'
/** 设置学习记录缓存 */
function set(data: HourCacheParam) {
async function set(courseId: number) {
Taro.removeStorageSync(KEY)
const res = await curriculum.hourCache(courseId, {duration: 0} as HourCacheParam)
Taro.setStorage({
key: KEY,
data
data: {
courseId,
duration: 0,
end_date: 0,
hour_id: 0,
start_date: Date.now(),
unique_ident: res
}
})
}
function remove() {
Taro.removeStorageSync(KEY)
}
/**
*
* @param duration
* @param hour_id id
* @param duration
* @param start_date
* @param upload
*/
function put(duration?: number, start_date?: number, upload = true) {
function put(hour_id?: number, duration?: number, start_date?: number) {
const data: HourCacheParam | undefined = Taro.getStorageSync(KEY)
if (data) {
data.duration = duration || data.duration
data.start_date = start_date || data.start_date
data.duration = duration || data.duration
data.hour_id = hour_id || data.hour_id
Taro.setStorageSync(KEY, data)
if (upload) {
curriculum.hourCache(data.courseId, data)
}
}
}
function del(duration?: number, start_date?: number, upload = true) {
put(duration, start_date, upload)
async function upload() {
const data: HourCacheParam | undefined = Taro.getStorageSync(KEY)
if (data) {
curriculum.delCache(data.courseId)
await curriculum.commit(data.courseId, data)
}
Taro.removeStorageSync(KEY)
}
function get(): HourCacheParam | undefined {
return Taro.getStorageSync(KEY)
}
export default {
set,
put,
del
remove,
upload,
get
}

@ -1,7 +1,7 @@
import {ScrollView, Text, View} from "@tarojs/components";
import {FC, useEffect, useState} from "react";
import HVideo from "@/components/video/video";
import {CurEndParam, curriculum, HourPlayData} from "@/api";
import {curriculum, HourPlayData} from "@/api";
import {Profile} from '@/store'
import Taro from "@tarojs/taro";
import Judge from "@/components/topic/judge";
@ -28,11 +28,10 @@ const Course: FC<Props> = ({id, courseId, preview, curEnd}) => {
const [validate, setValidate] = useState(false) // 开启验证
const [record, setRecord] = useState<boolean[]>([]) // 考题记录
const [testId, setTestId] = useState<number | null>(null)
const [startRecording, setStartRecording] = useState<CurEndParam | null>(null) // 视频开始记录
const {user} = Profile.useContainer()
async function onEnded() {
unique_ident.put(data?.duration, Date.now()) // 记录
const startRecording = unique_ident.get()
startRecording && await curriculum.curEnd(courseId, id, {...startRecording, duration: data?.duration!}) // 结束
if (testId) {
@ -64,31 +63,13 @@ const Course: FC<Props> = ({id, courseId, preview, curEnd}) => {
}
async function getData() {
unique_ident.put()
unique_ident.put(id, Date.now())
const res = await curriculum.hourPlay(courseId, id)
if (res) {
setData(res)
setBreakpoint(res.timeList)
setExamAll(res.hourExamQuestions || [])
setTestId(res?.hour_test?.id || null)
setStartRecording({
duration: 0,
unique_ident: res.unique_ident,
start_date: Date.now()
})
unique_ident.set({
courseId: Number(courseId),
user_id: user?.id!,
duration: 0,
start_date: Date.now(),
end_date: Date.now(),
hour_id: id,
unique_ident: res.unique_ident
})
}
}

@ -8,6 +8,7 @@ import Taro from "@tarojs/taro";
import eventsIndex from "@/hooks/eventsIndex";
import {formatMinute} from "@/utils/time";
import videoEvents from "@/hooks/videoEvents";
import unique_ident from "@/hooks/unique_ident";
const VideoInfo: FC = () => {
const {id, depId} = Taro.getCurrentInstance()?.router?.params as any
@ -40,7 +41,8 @@ const VideoInfo: FC = () => {
}
useEffect(() => {
getData(false)
getData(false).then()
unique_ident.set(id)
}, [id])

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

@ -106,7 +106,6 @@ interface HourCacheParam {
hour_id: number;
/** 课时开始学习时间 */
start_date: number;
user_id: number;
unique_ident: number
}

Loading…
Cancel
Save