学习记录

v2
king 1 year ago committed by xing
parent 7e03c67400
commit 0e46e2d76b
  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 { export interface HourPlayData {
/** 独特的识别 */
unique_ident: number
/** 时间 */ /** 时间 */
duration: number duration: number
/** 格式 */ /** 格式 */
@ -117,10 +115,9 @@ export const curriculum = {
}, },
/** 学习记录 */ /** 学习记录 */
hourCache(courseId: number, data: HourCacheParam) { 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)
}, },
/** 删除 */ commit(courseId: number, data: HourCacheParam) {
delCache(courseId: number) { return request(`/api/v1/course/${courseId}/hour/commit`, "PUT", data)
return request(`/api/v1/course/${courseId}/hour/cache`, "DELETE")
} }
} }

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

@ -68,6 +68,7 @@ const HVideo: FC<HVideoOptions> = (opt: HVideoOptions) => {
opt.onEnded() opt.onEnded()
} else { } else {
video?.seek(currentTime) video?.seek(currentTime)
unique_ident.remove()
video?.play() video?.play()
} }
} }
@ -96,7 +97,9 @@ const HVideo: FC<HVideoOptions> = (opt: HVideoOptions) => {
}) })
Taro.useUnload(() => { 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) Taro.removeStorageSync(KEY)
const res = await curriculum.hourCache(courseId, {duration: 0} as HourCacheParam)
Taro.setStorage({ Taro.setStorage({
key: KEY, 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 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) const data: HourCacheParam | undefined = Taro.getStorageSync(KEY)
if (data) { if (data) {
data.duration = duration || data.duration
data.start_date = start_date || data.start_date 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) Taro.setStorageSync(KEY, data)
if (upload) {
curriculum.hourCache(data.courseId, data)
}
} }
} }
function del(duration?: number, start_date?: number, upload = true) { async function upload() {
put(duration, start_date, upload)
const data: HourCacheParam | undefined = Taro.getStorageSync(KEY) const data: HourCacheParam | undefined = Taro.getStorageSync(KEY)
if (data) { 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 { export default {
set, set,
put, put,
del remove,
upload,
get
} }

@ -1,7 +1,7 @@
import {ScrollView, Text, View} from "@tarojs/components"; import {ScrollView, Text, View} from "@tarojs/components";
import {FC, useEffect, useState} from "react"; import {FC, useEffect, useState} from "react";
import HVideo from "@/components/video/video"; import HVideo from "@/components/video/video";
import {CurEndParam, curriculum, HourPlayData} from "@/api"; import {curriculum, HourPlayData} from "@/api";
import {Profile} from '@/store' import {Profile} from '@/store'
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
import Judge from "@/components/topic/judge"; import Judge from "@/components/topic/judge";
@ -28,11 +28,10 @@ const Course: FC<Props> = ({id, courseId, preview, curEnd}) => {
const [validate, setValidate] = useState(false) // 开启验证 const [validate, setValidate] = useState(false) // 开启验证
const [record, setRecord] = useState<boolean[]>([]) // 考题记录 const [record, setRecord] = useState<boolean[]>([]) // 考题记录
const [testId, setTestId] = useState<number | null>(null) const [testId, setTestId] = useState<number | null>(null)
const [startRecording, setStartRecording] = useState<CurEndParam | null>(null) // 视频开始记录
const {user} = Profile.useContainer() const {user} = Profile.useContainer()
async function onEnded() { 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!}) // 结束 startRecording && await curriculum.curEnd(courseId, id, {...startRecording, duration: data?.duration!}) // 结束
if (testId) { if (testId) {
@ -64,31 +63,13 @@ const Course: FC<Props> = ({id, courseId, preview, curEnd}) => {
} }
async function getData() { async function getData() {
unique_ident.put() unique_ident.put(id, Date.now())
const res = await curriculum.hourPlay(courseId, id) const res = await curriculum.hourPlay(courseId, id)
if (res) { if (res) {
setData(res) setData(res)
setBreakpoint(res.timeList) setBreakpoint(res.timeList)
setExamAll(res.hourExamQuestions || []) setExamAll(res.hourExamQuestions || [])
setTestId(res?.hour_test?.id || null) 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 eventsIndex from "@/hooks/eventsIndex";
import {formatMinute} from "@/utils/time"; import {formatMinute} from "@/utils/time";
import videoEvents from "@/hooks/videoEvents"; import videoEvents from "@/hooks/videoEvents";
import unique_ident from "@/hooks/unique_ident";
const VideoInfo: FC = () => { const VideoInfo: FC = () => {
const {id, depId} = Taro.getCurrentInstance()?.router?.params as any const {id, depId} = Taro.getCurrentInstance()?.router?.params as any
@ -40,7 +41,8 @@ const VideoInfo: FC = () => {
} }
useEffect(() => { useEffect(() => {
getData(false) getData(false).then()
unique_ident.set(id)
}, [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; hour_id: number;
/** 课时开始学习时间 */ /** 课时开始学习时间 */
start_date: number; start_date: number;
user_id: number;
unique_ident: number unique_ident: number
} }

Loading…
Cancel
Save