|
|
|
@ -1,4 +1,4 @@ |
|
|
|
|
import {ScrollView, Swiper, SwiperItem, View} from "@tarojs/components"; |
|
|
|
|
import {ScrollView, Swiper, SwiperItem, Text, View} from "@tarojs/components"; |
|
|
|
|
import {FC, useEffect, useState} from "react"; |
|
|
|
|
import HVideo from "@/components/video/video"; |
|
|
|
|
import {CurEndParam, curriculum, HourPlayData} from "@/api"; |
|
|
|
@ -10,6 +10,7 @@ import ShortAnswer from "@/components/topic/shortAnswer"; |
|
|
|
|
import unique_ident from "@/hooks/unique_ident"; |
|
|
|
|
import CustomPageContainer from "@/components/custom-page-container/custom-page-container"; |
|
|
|
|
import MyButton from "@/components/button/MyButton"; |
|
|
|
|
import {formatMinute} from "@/utils/time"; |
|
|
|
|
|
|
|
|
|
interface Props { |
|
|
|
|
id: number, |
|
|
|
@ -100,28 +101,34 @@ const Course: FC<Props> = ({id, courseId, preview, curEnd}: Props) => { |
|
|
|
|
setNewRecord(record) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function init() { |
|
|
|
|
function init(show = true) { |
|
|
|
|
record = [] |
|
|
|
|
setTime(0) |
|
|
|
|
setShow(false) |
|
|
|
|
setIndex(0) |
|
|
|
|
show && setShow(false) |
|
|
|
|
setValidate(false) |
|
|
|
|
setNewRecord([]) |
|
|
|
|
setTime(0) |
|
|
|
|
|
|
|
|
|
if (process.env.TARO_ENV === 'h5') { |
|
|
|
|
setTimeout(() => { |
|
|
|
|
setIndex(0) |
|
|
|
|
}, 200) |
|
|
|
|
} else { |
|
|
|
|
setIndex(0) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** 再来一次 */ |
|
|
|
|
function onceMore() { |
|
|
|
|
const oldTime: number = time |
|
|
|
|
init() |
|
|
|
|
init(false) |
|
|
|
|
setTimeout(() => { |
|
|
|
|
setShow(true) |
|
|
|
|
setTime(oldTime) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** 重新看 */ |
|
|
|
|
function again() { |
|
|
|
|
if (frequency === 0 && show) { |
|
|
|
|
if (examAll?.[time]?.length) { |
|
|
|
|
const {id: question_id, question_type} = examAll?.[time]?.[0] |
|
|
|
|
curriculum.answerRecord(id, { |
|
|
|
|
is_pass: false, |
|
|
|
@ -159,7 +166,24 @@ const Course: FC<Props> = ({id, courseId, preview, curEnd}: Props) => { |
|
|
|
|
seek(time) |
|
|
|
|
init() |
|
|
|
|
} else { |
|
|
|
|
Taro.showToast({title: '答案错误', icon: 'error', duration: 3000}) |
|
|
|
|
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]) |
|
|
|
|
|
|
|
|
@ -186,18 +210,17 @@ const Course: FC<Props> = ({id, courseId, preview, curEnd}: Props) => { |
|
|
|
|
position='bottom' |
|
|
|
|
round |
|
|
|
|
onAfterLeave={again} |
|
|
|
|
onClickOverlay={again} |
|
|
|
|
> |
|
|
|
|
<View className='text-center mt-2 text-muted'> |
|
|
|
|
<Text className='mr-2'>{formatMinute(time)}考题</Text> |
|
|
|
|
<Text>{index + 1}/{examAll?.[time]?.length}</Text> |
|
|
|
|
</View> |
|
|
|
|
<Swiper |
|
|
|
|
style={{height: "60vh"}} |
|
|
|
|
snapToEdge |
|
|
|
|
current={index} |
|
|
|
|
onChange={(e) => { |
|
|
|
|
if ((e.target as any)?.current) { |
|
|
|
|
setIndex((e.target as any).current) |
|
|
|
|
} |
|
|
|
|
}}> |
|
|
|
|
{examAll?.[time]?.map((d, index) => |
|
|
|
|
onChange={(e) => setIndex(e.detail.current)}> |
|
|
|
|
{examAll?.[time]?.map((d) => |
|
|
|
|
<SwiperItem key={d.id}> |
|
|
|
|
<ScrollView style='height:70vh' scrollY> |
|
|
|
|
{d.question_type === 1 && |
|
|
|
@ -205,43 +228,51 @@ const Course: FC<Props> = ({id, courseId, preview, curEnd}: Props) => { |
|
|
|
|
frequency={frequency} |
|
|
|
|
data={d as Multi} |
|
|
|
|
onAnswer={onAnswer} |
|
|
|
|
onUpAndDown={(index) => setIndex(index)} |
|
|
|
|
index={index} |
|
|
|
|
validate={validate} |
|
|
|
|
end={index === examAll?.[time].length - 1} |
|
|
|
|
/>} |
|
|
|
|
{d.question_type === 2 && |
|
|
|
|
<Judge |
|
|
|
|
frequency={frequency} |
|
|
|
|
onUpAndDown={(index) => setIndex(index)} |
|
|
|
|
index={index} |
|
|
|
|
data={d as ShareSubject} |
|
|
|
|
validate={validate} |
|
|
|
|
onAnswer={onAnswer} |
|
|
|
|
end={index === examAll?.[time].length - 1} |
|
|
|
|
/>} |
|
|
|
|
{d.question_type === 3 && |
|
|
|
|
<ShortAnswer |
|
|
|
|
frequency={frequency} |
|
|
|
|
data={d as ShareSubject} |
|
|
|
|
onAnswer={onAnswer} |
|
|
|
|
onUpAndDown={(index) => setIndex(index)} |
|
|
|
|
index={index} |
|
|
|
|
validate={validate} |
|
|
|
|
end={index === examAll?.[time].length - 1} |
|
|
|
|
/>} |
|
|
|
|
</ScrollView> |
|
|
|
|
</SwiperItem> |
|
|
|
|
)} |
|
|
|
|
</Swiper> |
|
|
|
|
<View> |
|
|
|
|
<View className='statistics'> |
|
|
|
|
<View>{frequency}次机会</View> |
|
|
|
|
<View>{index + 1}/{examAll?.[time]?.length}</View> |
|
|
|
|
<View>考试次数:{frequency}</View> |
|
|
|
|
|
|
|
|
|
{!validate && <MyButton width={150} fillet onClick={() => setValidate(true)}>提交</MyButton>} |
|
|
|
|
{frequency > 0 && validate && <MyButton width={150} fillet onClick={onceMore}>再来一次</MyButton>} |
|
|
|
|
{ |
|
|
|
|
(index + 1) === examAll?.[time]?.length && <View> |
|
|
|
|
{!validate && <MyButton width={150} fillet onClick={() => setValidate(true)}>交卷</MyButton>} |
|
|
|
|
{frequency > 0 && validate && <MyButton width={150} fillet onClick={onceMore}>重考</MyButton>} |
|
|
|
|
{frequency === 0 && validate && <MyButton width={150} fillet onClick={again}>重新学习</MyButton>} |
|
|
|
|
</View> |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
</View> |
|
|
|
|
<View className='upAndDown'> |
|
|
|
|
<View> |
|
|
|
|
{index !== 0 && <MyButton size='mini' width={150} onClick={() => setIndex(index - 1)}>上一题</MyButton>} |
|
|
|
|
</View> |
|
|
|
|
<View> |
|
|
|
|
{ |
|
|
|
|
(index + 1) !== examAll?.[time]?.length |
|
|
|
|
&& <MyButton size='mini' width={150} onClick={() => setIndex(index + 1)}>下一题</MyButton> |
|
|
|
|
} |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
</CustomPageContainer> |
|
|
|
|
</View> |
|
|
|
|
</> |
|
|
|
|