视频弹窗答题

v2
king 1 year ago
parent 8cb14727c0
commit b3fd259076
  1. 13
      src/components/topic/single.module.scss
  2. 46
      src/components/topic/single.tsx
  3. 7
      src/components/video/video.tsx
  4. 15
      src/pages/business/videoInfo/components/course.tsx
  5. 1
      src/pages/business/videoInfo/videoInfo.scss

@ -1,4 +1,5 @@
.single-cover {
.singleCover {
position: absolute; position: absolute;
bottom: 0; bottom: 0;
top: 0; top: 0;
@ -28,10 +29,12 @@
} }
.correct{ .correct {
background: #bdf6c1 !important;
color: #fff !important;
} }
.mistake{ .mistake {
background: #e7abab !important;
color: #fff !important;
} }

@ -12,8 +12,6 @@ interface Props {
type AnswerType = "true" | 'false' type AnswerType = "true" | 'false'
export const Single: FC<Props> = (props) => { export const Single: FC<Props> = (props) => {
if (!props.topic) return (<></>)
let timer: NodeJS.Timeout let timer: NodeJS.Timeout
const [lastState, setLastState] = useState<0 | 1>(0) // 0为竖屏,1为横屏 const [lastState, setLastState] = useState<0 | 1>(0) // 0为竖屏,1为横屏
const [result, setResult] = useState<AnswerType | undefined>(undefined) const [result, setResult] = useState<AnswerType | undefined>(undefined)
@ -58,18 +56,19 @@ export const Single: FC<Props> = (props) => {
}) })
useEffect(() => { useEffect(() => {
// timer = setTimeout(() => { timer = setTimeout(() => {
// props.examination(false) props.examination(false)
// }, 4000) }, 4000)
}, [props.topic]) }, [props.topic])
const style: React.CSSProperties = useMemo(() => ({ const style: React.CSSProperties = useMemo(() => ({
transform: lastState === 0 && props.full ? "rotate(-90deg)" : 'none' transform: lastState === 1 && props.full ? "rotate(90deg)" : 'none'
}), [lastState]) }), [lastState, props.full])
function examination(result: AnswerType) { function examination(answer: AnswerType) {
if (result) return;
clearTimeout(timer) clearTimeout(timer)
setResult(result) setResult(answer)
setTimeout(() => { setTimeout(() => {
props.examination(props.topic?.right_value === result) props.examination(props.topic?.right_value === result)
@ -78,24 +77,29 @@ export const Single: FC<Props> = (props) => {
} }
function judgment(answer: AnswerType): string { function judgment(answer: AnswerType): string {
if (props.topic?.right_value === answer && result === answer) { if (result !== answer) return ''
if (props.topic?.right_answer === answer && result === answer) {
return styles.correct return styles.correct
} }
return styles.mistake return styles.mistake
} }
return ( return (
<View className={styles.singleCover} style={style}> <>
<View>{props.topic.question}</View> {
<View className={judgment("true")} props.topic && <View className={styles.singleCover} style={style}>
onClick={() => examination("true")}> <View>{props.topic.question}</View>
{props.topic.right_value} <View className={judgment("true")}
</View> onClick={() => examination("true")}>
<View className={judgment("false")} {props.topic.right_value}
onClick={() => examination("false")}> </View>
{props.topic.error_value} <View className={judgment("false")}
</View> onClick={() => examination("false")}>
</View> {props.topic.error_value}
</View>
</View>
}
</>
) )
} }

@ -49,13 +49,6 @@ const HVideo: FC<HVideoOptions> = (opt: HVideoOptions) => {
}) })
} }
// opt.setTime((time?: number) => {
// if (typeof time === 'number') {
// video?.seek(time)
// }
// video?.play()
// })
function onEnded() { function onEnded() {
if (currentTime + 1 > opt.duration) { if (currentTime + 1 > opt.duration) {
opt.onEnded() opt.onEnded()

@ -1,4 +1,4 @@
import {FC, useEffect, useState} from "react"; import {FC, useCallback, useEffect, useState} from "react";
import HVideo from "@/components/video/video"; import HVideo from "@/components/video/video";
import {curriculum, HourPlayData} from "@/api"; import {curriculum, HourPlayData} from "@/api";
import {Profile} from '@/store' import {Profile} from '@/store'
@ -13,11 +13,9 @@ interface Props {
curEnd: (test?: boolean) => void curEnd: (test?: boolean) => void
} }
const Course: FC<Props> = ({id, courseId, preview, curEnd}) => { const Course: FC<Props> = ({id, courseId, preview, curEnd}) => {
const [breakpoints, setBreakpoints] = useState<number[]>([]) // 断点 const [breakpoints, setBreakpoints] = useState<number[]>([]) // 断点
const [isFull, setIsFull] = useState(false) const [isFull, setIsFull] = useState(false)
const [examAll, setExamAll] = useState<Record<number, ShareSubject[]>>([]) // 题库 const [examAll, setExamAll] = useState<Record<number, ShareSubject[]>>([]) // 题库
const [data, setData] = useState<HourPlayData | null>(null) const [data, setData] = useState<HourPlayData | null>(null)
const [time, setTime] = useState<number>(0) // 进入断点的时间 const [time, setTime] = useState<number>(0) // 进入断点的时间
@ -67,7 +65,8 @@ const Course: FC<Props> = ({id, courseId, preview, curEnd}) => {
getData() getData()
}, [id]) }, [id])
function examination(result: boolean) { const examination = useCallback((result: boolean) => {
if (!time) return
const {id: question_id, question_type} = examAll?.[time]?.[0] const {id: question_id, question_type} = examAll?.[time]?.[0]
curriculum.answerRecord(id, { curriculum.answerRecord(id, {
is_pass: result, is_pass: result,
@ -77,8 +76,7 @@ const Course: FC<Props> = ({id, courseId, preview, curEnd}) => {
question_id question_id
}) })
setTime(0) setTime(0)
} }, [time])
return ( return (
<> <>
@ -88,9 +86,10 @@ const Course: FC<Props> = ({id, courseId, preview, curEnd}) => {
src={data?.url || ''} src={data?.url || ''}
onEnded={onEnded} onEnded={onEnded}
breakpoint={breakpoints} breakpoint={breakpoints}
onBreakpoint={(time) => setTime(time)}
fullChange={(fullScreen) => setIsFull(fullScreen)} fullChange={(fullScreen) => setIsFull(fullScreen)}
> onBreakpoint={(now) => {
time !== now && setTime(now)
}}>
<Single <Single
full={isFull} full={isFull}
examination={examination} examination={examination}

@ -106,4 +106,3 @@
filter: saturate(0); filter: saturate(0);
} }

Loading…
Cancel
Save