From 702cee4693c2f063db4340c88524cc16c0ed6fca Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Thu, 17 Aug 2023 16:01:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A4=E6=96=AD=E9=A2=98=20&&=20=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E7=AD=94=E9=A2=98=E6=AC=A1=E6=95=B0=E5=92=8C=E5=AE=B9?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 +- src/api/curriculum.ts | 2 - src/components/topic/judge.tsx | 9 +- src/components/topic/multi.tsx | 5 +- src/components/topic/shortAnswer.tsx | 7 +- src/components/topic/topic.scss | 3 - src/components/video/video.tsx | 13 -- .../business/videoInfo/components/course.tsx | 186 ++++-------------- types/topic.d.ts | 2 + 9 files changed, 50 insertions(+), 181 deletions(-) diff --git a/.env b/.env index 0cde6d6..1eee7ad 100644 --- a/.env +++ b/.env @@ -1,5 +1,5 @@ -#TARO_APP_API=https://yjx.dev.yaojiankang.top -TARO_APP_API=https://playedu.yaojiankang.top +TARO_APP_API=https://yjx.dev.yaojiankang.top +#TARO_APP_API=https://playedu.yaojiankang.top TARO_APP_LGOIN=true diff --git a/src/api/curriculum.ts b/src/api/curriculum.ts index 7115159..b304600 100644 --- a/src/api/curriculum.ts +++ b/src/api/curriculum.ts @@ -28,8 +28,6 @@ export interface HourPlayData { url: string /** 断点题 */ hourExamQuestions: Record - /** 次数 */ - fault_count: Record[] /** 断点 */ timeList: number[] hour_test?: { id: number } diff --git a/src/components/topic/judge.tsx b/src/components/topic/judge.tsx index c8444e6..0df4153 100644 --- a/src/components/topic/judge.tsx +++ b/src/components/topic/judge.tsx @@ -6,10 +6,9 @@ interface Props { data: ShareSubject onAnswer: (isAnswer: boolean) => void validate: boolean - frequency?: number } -const Judge: FC = ({data, onAnswer, validate, frequency}) => { +const Judge: FC = ({data, onAnswer, validate}) => { const [rightAnswer, setRightAnswer] = useState(null) //答案 const rightKey = data.right_answer === 'true' ? 'correct' : 'error' // 正确答案数组 const [error, setError] = useState(false) @@ -43,19 +42,19 @@ const Judge: FC = ({data, onAnswer, validate, frequency}) => { color={validate ? 'correct' !== rightKey ? 'red' : '#45d4a8' : '#45d4a8'} disabled={validate ? 'correct' !== rightAnswer : false} > - 正确 + {data.right_value} - 错误 + {data.error_value} - {error && frequency == 0 && + {error && 正确答案:{data.right_answer ? '正确' : '错误'} 题目解析 {data.analysis} diff --git a/src/components/topic/multi.tsx b/src/components/topic/multi.tsx index e97e30d..d5ac83e 100644 --- a/src/components/topic/multi.tsx +++ b/src/components/topic/multi.tsx @@ -6,10 +6,9 @@ interface Props { data: Multi onAnswer: (isAnswer: boolean) => void validate: boolean - frequency?: number } -const Multi: FC = ({data, onAnswer, validate, frequency}) => { +const Multi: FC = ({data, onAnswer, validate}) => { const [rightAnswer, setRightAnswer] = useState([]) //答案 const rightKey = data?.right_answer?.split(',') || [] // 正确答案数组 @@ -90,7 +89,7 @@ const Multi: FC = ({data, onAnswer, validate, frequency}) => { } - {error && frequency == 0 && + {error && 正确答案:{data.right_answer} 题目解析 {data.analysis} diff --git a/src/components/topic/shortAnswer.tsx b/src/components/topic/shortAnswer.tsx index 7649acc..62db98b 100644 --- a/src/components/topic/shortAnswer.tsx +++ b/src/components/topic/shortAnswer.tsx @@ -6,10 +6,9 @@ interface Props { data: ShareSubject onAnswer: (isAnswer: boolean) => void validate: boolean - frequency?: number } -const ShortAnswer: FC = ({data, onAnswer, validate, frequency}) => { +const ShortAnswer: FC = ({data, onAnswer, validate}) => { const [value, setValue] = useState('') useEffect(() => { @@ -36,10 +35,10 @@ const ShortAnswer: FC = ({data, onAnswer, validate, frequency}) => { onInput={(e) => setValue(e.detail.value)}/> - {frequency == 0 && + 题目解析 {data.analysis} - } + ) diff --git a/src/components/topic/topic.scss b/src/components/topic/topic.scss index 2cd631e..9936847 100644 --- a/src/components/topic/topic.scss +++ b/src/components/topic/topic.scss @@ -35,9 +35,6 @@ border-top: 1px solid #F5F8F7; height: 60rpx; padding: 20rpx 0; - display: flex; - align-items: center; - justify-content: space-between; } .upAndDown { diff --git a/src/components/video/video.tsx b/src/components/video/video.tsx index 7dd0f60..6275ffa 100644 --- a/src/components/video/video.tsx +++ b/src/components/video/video.tsx @@ -41,7 +41,6 @@ const HVideo: FC = (opt: HVideoOptions) => { /** 判断是否进入断点 */ opt.breakpoint.forEach(d => { if (time < d + deviation && time > d - deviation) { - video?.pause() video?.seek(d - deviation) if (process.env.TARO_ENV === 'h5') { @@ -51,17 +50,6 @@ const HVideo: FC = (opt: HVideoOptions) => { } } video?.exitFullScreen() - - // if (opt.preview) { - // Taro.showModal({ - // title: '是否答题', - // success({confirm, cancel}) { - // confirm && opt.onBreakpoint(d) - // cancel && video?.play() - // } - // }) - // return; - // } opt.onBreakpoint(d) return } @@ -131,7 +119,6 @@ const HVideo: FC = (opt: HVideoOptions) => { onPlay={onPlay} onPause={onPause} /> - {/*1221*/} ) } diff --git a/src/pages/business/videoInfo/components/course.tsx b/src/pages/business/videoInfo/components/course.tsx index 2459c25..a2ce75d 100644 --- a/src/pages/business/videoInfo/components/course.tsx +++ b/src/pages/business/videoInfo/components/course.tsx @@ -1,12 +1,10 @@ -import {ScrollView, Swiper, SwiperItem, Text, View} from "@tarojs/components"; +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 {Profile} from '@/store' import Taro from "@tarojs/taro"; -import Multi from "@/components/topic/multi"; import Judge from "@/components/topic/judge"; -import ShortAnswer from "@/components/topic/shortAnswer"; import unique_ident from "@/hooks/unique_ident"; import MyButton from "@/components/button/MyButton"; import {formatMinute} from "@/utils/time"; @@ -21,21 +19,16 @@ interface Props { let seek: (time: number) => void -let record: boolean[] = [] //答案记录 const Course: FC = ({id, courseId, preview, curEnd}) => { const [breakpoint, setBreakpoint] = useState([]) // 断点 const [show, setShow] = useState(false) // 题 const [data, setData] = useState(null) const [examAll, setExamAll] = useState>([]) // 题库 - const [index, setIndex] = useState(0) const [time, setTime] = useState(0) // 进入断点的时间 const [validate, setValidate] = useState(false) // 开启验证 - const [newRecord, setNewRecord] = useState([]) - const [faultCount, setFaultCount] = useState | null>(null) - const [frequency, setFrequency] = useState(1) // 次数 + const [record, setRecord] = useState([]) // 考题记录 const [testId, setTestId] = useState(null) const [startRecording, setStartRecording] = useState(null) // 视频开始记录 - const [topicRecord, setRecord] = useState([]) // 考题正确记录 const {user} = Profile.useContainer() async function onEnded() { @@ -66,9 +59,6 @@ const Course: FC = ({id, courseId, preview, curEnd}) => { /** 进入断点 */ function onBreakpoint(breakpoint: number) { - if (breakpoint !== time) { - setFrequency(faultCount?.[breakpoint] || 1) - } setTime(breakpoint) setShow(true) } @@ -82,9 +72,7 @@ const Course: FC = ({id, courseId, preview, curEnd}) => { setData(res) setBreakpoint(res.timeList) setExamAll(res.hourExamQuestions || []) - setFaultCount(res.fault_count?.[0] || {}) setTestId(res?.hour_test?.id || null) - setRecord([]) setStartRecording({ duration: 0, @@ -109,97 +97,39 @@ const Course: FC = ({id, courseId, preview, curEnd}) => { getData() }, [id]) - /** 统计答案 */ - function onAnswer(isAnswer: boolean) { - record.push(isAnswer) - setNewRecord(record) - } function init(show = true) { - record = [] show && setShow(false) setValidate(false) - setNewRecord([]) + setRecord([]) setTime(0) - setIndex(0) - } - - /** 再来一次 */ - function onceMore() { - const oldTime: number = time - init(false) - setTimeout(() => { - setTime(oldTime) - }) } - /** 重新看 */ - function again() { - if (examAll?.[time]?.length) { - const {id: question_id, question_type} = examAll?.[time]?.[0] - curriculum.answerRecord(id, { - is_pass: false, - user_id: user?.id!, - time: time, - question_id, - question_type - }).then(res => { - seek(res.time) - }) - init() - } - setShow(false) - setIndex(0) - } useEffect(() => { - if (!newRecord.length) return; - setFrequency(frequency - 1) // 减少一次学习记录 - const pass = newRecord.every(d => d) + if (!record.length) return; + const pass = record.every(d => d) /** 考题正确 */ - if (pass) { - const {id: question_id, question_type} = examAll?.[time]?.[0] - curriculum.answerRecord(id, { - is_pass: pass, - user_id: user?.id!, - time: time, - question_type, - question_id - }).then() + const {id: question_id, question_type} = examAll?.[time]?.[0] + curriculum.answerRecord(id, { + is_pass: pass, + user_id: user?.id!, + time: time, + question_type, + question_id + }).then() + + /** 删除断点 */ + const old: number[] = JSON.parse(JSON.stringify(breakpoint)) + const index = old.indexOf(time) + old.splice(index, 1) + setBreakpoint(old) - /** 删除断点 */ - const old: number[] = JSON.parse(JSON.stringify(breakpoint)) - const index = old.indexOf(time) - old.splice(index, 1) - setBreakpoint(old) - - setRecord([...topicRecord, time]) + if (pass) { seek(time) - - Taro.showToast({title: '答题正确', duration: 2000}) init() - - } else { - if ((frequency - 1) !== 0) { - Taro.showModal({ - title: '考试未通过', - content: '剩余考试次数:' + (frequency - 1), - confirmText: '重考', - success({confirm}) { - confirm && onceMore() - } - }) - } else { - Taro.showModal({ - title: '考试未通过', - content: '请重新学习', - success({confirm}) { - confirm && again() - } - }) - } } - }, [newRecord]) + }, [record]) function videoSeek(fn: (time: number) => void) { seek = fn @@ -220,73 +150,31 @@ const Course: FC = ({id, courseId, preview, curEnd}) => { {formatMinute(time)}考题 - {index + 1}/{examAll?.[time]?.length} - setIndex(e.detail.current ?? index)}> - {examAll?.[time]?.map((d) => - - - {d.question_type === 1 && - } - {d.question_type === 2 && - } - {d.question_type === 3 && - } - - - )} - + {examAll?.[time]?.slice(0, 1)?.map((d) => + + {d.question_type === 2 && + setRecord([isAnswer])} + />} + + )} - - - { - index !== 0 && - setIndex(index - 1)}>上一题 - } - - - { - (index + 1) !== examAll?.[time]?.length && - setIndex(index + 1)}>下一题 - } - - - - 考试次数:{frequency} { - (index + 1) === examAll?.[time]?.length && - {!validate && setValidate(true)}>交卷} - {frequency > 0 && validate && 重考} - {frequency === 0 && validate && 重新学习} - + record.length > 0 + ? { + init(); + seek(time) + }}>关闭 + : setValidate(true)}>交卷 } diff --git a/types/topic.d.ts b/types/topic.d.ts index a8ba605..47f7367 100644 --- a/types/topic.d.ts +++ b/types/topic.d.ts @@ -8,6 +8,8 @@ interface ShareSubject { analysis: string //课题解析 course_id: number hour_id: number + right_value:string + error_value:string } /** 选择题 */