|
@@ -47,12 +47,14 @@ export default defineComponent({
|
|
|
examDetail: {} as any,
|
|
|
visiableAnswer: false,
|
|
|
currentIndex: 0,
|
|
|
- questionList: [5],
|
|
|
- answerList: {},
|
|
|
+ questionList: [],
|
|
|
time: 0,
|
|
|
visiableSure: false,
|
|
|
visiableResult: false,
|
|
|
- visiableExam: false // 考试已结束
|
|
|
+ resultInfo: {} as any,
|
|
|
+ resultStatusType: 'SUCCESS', // 'SUCCESS' | 'FAIL'
|
|
|
+ visiableExam: false, // 考试已结束
|
|
|
+ nextStatus: false
|
|
|
})
|
|
|
|
|
|
const getExamDetails = async () => {
|
|
@@ -66,21 +68,25 @@ export default defineComponent({
|
|
|
}
|
|
|
}
|
|
|
)
|
|
|
-
|
|
|
const { questionJson, studentAnswerJson, ...res } = data
|
|
|
- ;(questionJson || []).forEach((item: any) => {
|
|
|
- if (item.questionTypeCode === 'RADIO') {
|
|
|
- }
|
|
|
+ const temp = questionJson || []
|
|
|
+ temp.forEach((item: any) => {
|
|
|
+ item.userAnswer = formatUserAnswers(item, studentAnswerJson)
|
|
|
})
|
|
|
- state.questionList = state.examDetail = { ...res } || {}
|
|
|
+ console.log(temp)
|
|
|
+ state.questionList = temp
|
|
|
+
|
|
|
+ state.examDetail = { ...res } || {}
|
|
|
|
|
|
calcTime()
|
|
|
} catch {
|
|
|
//
|
|
|
- state.visiableExam = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @description 计算考试时间剩余时间
|
|
|
+ */
|
|
|
const calcTime = () => {
|
|
|
const examDetail = state.examDetail || {}
|
|
|
const startTime = examDetail.startTime
|
|
@@ -88,11 +94,8 @@ export default defineComponent({
|
|
|
const timeMinutes = examDetail.timeMinutes || 0 // 测验时间
|
|
|
// 返回秒
|
|
|
const minu = dayjs(startTime).add(timeMinutes, 'minute').diff(dayjs(nowTime))
|
|
|
-
|
|
|
- // console.log(dayjs(startTime).add(timeMinutes, 'minute').valueOf() - dayjs(nowTime).valueOf())
|
|
|
- // console.log(minu, dayjs(startTime).add(timeMinutes, 'minute'), dayjs(nowTime))
|
|
|
if (minu <= 0) {
|
|
|
- console.log('考试已结束')
|
|
|
+ state.visiableExam = true
|
|
|
} else {
|
|
|
state.time = Math.ceil(minu / 1000) * 1000
|
|
|
setTimeout(() => {
|
|
@@ -101,6 +104,95 @@ export default defineComponent({
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @description 初始化用户答案
|
|
|
+ */
|
|
|
+ const formatUserAnswers = (item: any, userAnswer: any) => {
|
|
|
+ // 判断是否有结果
|
|
|
+ if (!userAnswer) return []
|
|
|
+ const answers = JSON.parse(userAnswer) || []
|
|
|
+
|
|
|
+ const questionItem = answers.find((child: any) => child.questionId === item.id)
|
|
|
+ return questionItem ? questionItem.details : []
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description 下一题 | 测试完成
|
|
|
+ */
|
|
|
+ const onNextQuestion = async () => {
|
|
|
+ try {
|
|
|
+ const questionList = state.questionList || []
|
|
|
+ const userAnswerList: any = [] // 所有题目的答案
|
|
|
+
|
|
|
+ let currentResult = false // 当前题目是否已经答题
|
|
|
+
|
|
|
+ questionList.forEach((question: any, index: number) => {
|
|
|
+ // 格式化所有题目的答案
|
|
|
+ if (question.userAnswer && question.userAnswer.length > 0) {
|
|
|
+ userAnswerList.push({
|
|
|
+ questionId: question.id,
|
|
|
+ details: question.userAnswer
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ if (index === state.currentIndex) {
|
|
|
+ currentResult = question.userAnswer && question.userAnswer.length > 0 ? true : false
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // 判断是否答题了
|
|
|
+ if (!currentResult) {
|
|
|
+ swipeRef.value?.next()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ state.nextStatus = true
|
|
|
+ // 判断是否是最后一题
|
|
|
+ if (state.questionList.length === state.currentIndex + 1) {
|
|
|
+ // api-student/studentUnitExamination/completionExamination
|
|
|
+ const { data } = await request.post(
|
|
|
+ '/api-student/studentUnitExamination/completionExamination',
|
|
|
+ {
|
|
|
+ data: {
|
|
|
+ answers: userAnswerList,
|
|
|
+ studentUnitExaminationId: state.id
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ if (data.score >= state.examDetail.passScore) {
|
|
|
+ state.resultStatusType = 'SUCCESS'
|
|
|
+ state.resultInfo = {
|
|
|
+ tips: '恭喜你,测验通过!',
|
|
|
+ score: data.score,
|
|
|
+ examName: data.unitExaminationName
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ state.resultStatusType = 'FAIL'
|
|
|
+ state.resultInfo = {
|
|
|
+ tips: '本次测验不合格!',
|
|
|
+ score: data.score,
|
|
|
+ examName: data.unitExaminationName
|
|
|
+ }
|
|
|
+ }
|
|
|
+ state.visiableResult = true
|
|
|
+ } else {
|
|
|
+ await request.post('/api-student/studentUnitExamination/submitAnswer', {
|
|
|
+ hideLoading: true,
|
|
|
+ data: {
|
|
|
+ answers: userAnswerList,
|
|
|
+ studentUnitExaminationId: state.id
|
|
|
+ }
|
|
|
+ })
|
|
|
+ swipeRef.value?.next()
|
|
|
+ }
|
|
|
+
|
|
|
+ state.nextStatus = false
|
|
|
+ } catch {
|
|
|
+ //
|
|
|
+ state.nextStatus = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
onMounted(() => {
|
|
|
getExamDetails()
|
|
|
})
|
|
@@ -114,8 +206,11 @@ export default defineComponent({
|
|
|
<div class={styles.unitCount}>
|
|
|
<div class={styles.qNums}>
|
|
|
<Icon class={styles.icon} name={iconQuestionNums} />
|
|
|
- 题目数量 <span class={styles.num}>{state.currentIndex + 1}</span>/
|
|
|
- {state.examDetail.questionNum}
|
|
|
+ 题目数量{' '}
|
|
|
+ <span class={styles.num} style={{ paddingLeft: '6px' }}>
|
|
|
+ {state.currentIndex + 1}
|
|
|
+ </span>
|
|
|
+ /{state.examDetail.questionNum}
|
|
|
</div>
|
|
|
<div class={styles.qNums}>
|
|
|
<Icon class={styles.icon} name={iconCountDown} />
|
|
@@ -145,14 +240,33 @@ export default defineComponent({
|
|
|
}}
|
|
|
>
|
|
|
{state.questionList.map((item: any, index: number) => (
|
|
|
+ // item.questionTypeCode === QuestionType.LINK && (
|
|
|
+ // <SwipeItem>
|
|
|
+ // <KeepLookQuestion v-model:value={item.userAnswer} data={item} index={index + 1} />
|
|
|
+ // </SwipeItem>
|
|
|
+ // )
|
|
|
<SwipeItem>
|
|
|
{item.questionTypeCode === QuestionType.RADIO && (
|
|
|
- <ChoiceQuestion index={index + 1} data={item} type="radio" />
|
|
|
+ <ChoiceQuestion
|
|
|
+ v-model:value={item.userAnswer}
|
|
|
+ index={index + 1}
|
|
|
+ data={item}
|
|
|
+ type="radio"
|
|
|
+ />
|
|
|
)}
|
|
|
- {item.questionTypeCode === 'CHECKBOX' && <ChoiceQuestion type="checkbox" />}
|
|
|
- {item.questionTypeCode === 'SORT' && <DragQuestion />}
|
|
|
- {item.questionTypeCode === 'LINK' && <KeepLookQuestion />}
|
|
|
- {item.questionTypeCode === 'PLAY' && <PlayQuestion />}
|
|
|
+ {item.questionTypeCode === QuestionType.CHECKBOX && (
|
|
|
+ <ChoiceQuestion
|
|
|
+ v-model:value={item.userAnswer}
|
|
|
+ index={index + 1}
|
|
|
+ data={item}
|
|
|
+ type="checkbox"
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ {item.questionTypeCode === QuestionType.SORT && <DragQuestion />}
|
|
|
+ {item.questionTypeCode === QuestionType.LINK && (
|
|
|
+ <KeepLookQuestion v-model:value={item.userAnswer} data={item} index={index + 1} />
|
|
|
+ )}
|
|
|
+ {item.questionTypeCode === QuestionType.PLAY && <PlayQuestion />}
|
|
|
</SwipeItem>
|
|
|
))}
|
|
|
</Swipe>
|
|
@@ -176,16 +290,11 @@ export default defineComponent({
|
|
|
block
|
|
|
round
|
|
|
type="primary"
|
|
|
- onClick={() => {
|
|
|
- // if (state.questionList.length - 1 === state.currentIndex) {
|
|
|
- // state.visiableSure = true
|
|
|
- // } else {
|
|
|
- swipeRef.value?.next()
|
|
|
- // }
|
|
|
- }}
|
|
|
+ onClick={onNextQuestion}
|
|
|
+ loading={state.nextStatus}
|
|
|
+ disabled={state.nextStatus}
|
|
|
>
|
|
|
- 下一题
|
|
|
- {/* {state.questionList.length === state.currentIndex + 1 ? '测试完成' : '下一题'} */}
|
|
|
+ {state.questionList.length === state.currentIndex + 1 ? '测试完成' : '下一题'}
|
|
|
</Button>
|
|
|
<Image
|
|
|
src={iconButtonList}
|
|
@@ -198,7 +307,7 @@ export default defineComponent({
|
|
|
{/* 题目集合 */}
|
|
|
<ActionSheet v-model:show={state.visiableAnswer} title="题目列表" safeAreaInsetBottom>
|
|
|
<AnswerList
|
|
|
- value={[1, 3, 4]}
|
|
|
+ value={state.questionList}
|
|
|
onSelect={(item: any) => {
|
|
|
// 跳转,并且跳过动画
|
|
|
swipeRef.value?.swipeTo(item, {
|
|
@@ -215,13 +324,18 @@ export default defineComponent({
|
|
|
style={{ background: 'transparent', width: '96%' }}
|
|
|
>
|
|
|
<ResultFinish
|
|
|
- // status="FAIL"
|
|
|
+ status={state.resultStatusType as any}
|
|
|
+ result={state.resultInfo}
|
|
|
confirmButtonText="我知道了"
|
|
|
cancelButtonText="去练习"
|
|
|
- onClose={() => (state.visiableResult = false)}
|
|
|
+ onClose={() => {
|
|
|
+ state.visiableResult = false
|
|
|
+ router.back()
|
|
|
+ }}
|
|
|
onConform={() => {
|
|
|
console.log('Success')
|
|
|
state.visiableResult = false
|
|
|
+ router.back()
|
|
|
}}
|
|
|
/>
|
|
|
</Popup>
|