|
@@ -8,6 +8,7 @@ import {
|
|
|
Icon,
|
|
|
Image,
|
|
|
Popup,
|
|
|
+ showDialog,
|
|
|
Swipe,
|
|
|
SwipeItem,
|
|
|
Tag
|
|
@@ -30,6 +31,7 @@ import { QuestionType } from '../unit'
|
|
|
import request from '@/helpers/request'
|
|
|
import { useRect } from '@vant/use'
|
|
|
import OHeader from '@/components/o-header'
|
|
|
+import { useInterval } from '@vueuse/core'
|
|
|
|
|
|
export default defineComponent({
|
|
|
name: 'unit-detail',
|
|
@@ -39,24 +41,33 @@ export default defineComponent({
|
|
|
const countDownRef = ref()
|
|
|
const swipeRef = ref()
|
|
|
const state = reactive({
|
|
|
- name: route.query.id,
|
|
|
+ examId: route.query.examId,
|
|
|
+ name: route.query.name,
|
|
|
visiableError: false,
|
|
|
visiableAnswer: false,
|
|
|
visiableResult: false,
|
|
|
id: route.query.id,
|
|
|
currentIndex: 0,
|
|
|
questionList: [],
|
|
|
- questionResultList: [],
|
|
|
- time: 0,
|
|
|
visiableSure: false,
|
|
|
resultInfo: {} as any,
|
|
|
resultStatusType: 'SUCCESS', // 'SUCCESS' | 'FAIL'
|
|
|
visiableExam: false, // 考试已结束
|
|
|
nextStatus: false,
|
|
|
swipeHeight: 'auto' as any,
|
|
|
- answerAnalysis: ''
|
|
|
+ answerAnalysis: '',
|
|
|
+ overResult: {
|
|
|
+ time: '00:00', // 时长
|
|
|
+ questionLength: 0, // 答题数
|
|
|
+ errorLength: 0, // 错题数
|
|
|
+ rate: 0 // 正确率
|
|
|
+ },
|
|
|
+ knowledgelist: [] as any // 知识点列表
|
|
|
})
|
|
|
|
|
|
+ // 计时
|
|
|
+ const { counter, resume, pause } = useInterval(1000, { controls: true })
|
|
|
+
|
|
|
const getExamDetails = async () => {
|
|
|
try {
|
|
|
const { data } = await request.post('/api-student/examinationQuestion/randomPage', {
|
|
@@ -82,6 +93,21 @@ export default defineComponent({
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 获取所在知识点
|
|
|
+ const getDetails = async () => {
|
|
|
+ try {
|
|
|
+ const { data } = await request.post('/api-student/unitExamination/queryKnowledgePoint', {
|
|
|
+ requestType: 'form',
|
|
|
+ data: {
|
|
|
+ unitExaminationId: state.examId
|
|
|
+ }
|
|
|
+ })
|
|
|
+ state.knowledgelist = data || []
|
|
|
+ } catch {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @description 下一题 | 测试完成
|
|
|
*/
|
|
@@ -134,10 +160,12 @@ export default defineComponent({
|
|
|
//
|
|
|
const getAnswerResult = computed(() => {
|
|
|
const questionList = state.questionList || []
|
|
|
+ let count = 0
|
|
|
let passCount = 0
|
|
|
let noPassCount = 0
|
|
|
questionList.forEach((item: any) => {
|
|
|
if (item.showAnalysis) {
|
|
|
+ count += 1
|
|
|
if (item.analysis.userResult) {
|
|
|
passCount += 1
|
|
|
} else {
|
|
@@ -147,8 +175,9 @@ export default defineComponent({
|
|
|
})
|
|
|
|
|
|
return {
|
|
|
- passCount: passCount,
|
|
|
- noPassCount: noPassCount
|
|
|
+ count,
|
|
|
+ passCount,
|
|
|
+ noPassCount
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -167,14 +196,98 @@ export default defineComponent({
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- const onCloseExam = () => {
|
|
|
- state.visiableSure = true
|
|
|
+ const onConfirmExam = () => {
|
|
|
+ const answerResult = getAnswerResult.value
|
|
|
+ let rate = 0
|
|
|
+
|
|
|
+ if (answerResult.count > 0) {
|
|
|
+ rate = Math.floor((answerResult.passCount / answerResult.count) * 100)
|
|
|
+ }
|
|
|
+
|
|
|
+ const times = counter.value
|
|
|
+ const minute =
|
|
|
+ Math.floor(times / 60) >= 10 ? Math.floor(times / 60) : '0' + Math.floor(times / 60)
|
|
|
+ const seconds = times % 60 >= 10 ? times % 60 : '0' + (times % 60)
|
|
|
+ state.overResult = {
|
|
|
+ time: minute + ':' + seconds, // 时长
|
|
|
+ questionLength: answerResult.count, // 答题数
|
|
|
+ errorLength: answerResult.noPassCount, // 错题数
|
|
|
+ rate // 正确率
|
|
|
+ }
|
|
|
+ // 重置计时
|
|
|
+ pause()
|
|
|
+ counter.value = 0
|
|
|
+ state.visiableResult = true
|
|
|
}
|
|
|
|
|
|
- onMounted(() => {
|
|
|
- getExamDetails()
|
|
|
+ // 重新练习
|
|
|
+ const onCloseResult = async () => {
|
|
|
+ state.questionList = []
|
|
|
+ await getExamDetails()
|
|
|
+ swipeRef.value?.swipeTo(0, {
|
|
|
+ immediate: true
|
|
|
+ })
|
|
|
+ state.swipeHeight = 'auto'
|
|
|
+ state.answerAnalysis = ''
|
|
|
+ state.overResult = {
|
|
|
+ time: '00:00', // 时长
|
|
|
+ questionLength: 0, // 答题数
|
|
|
+ errorLength: 0, // 错题数
|
|
|
+ rate: 0 // 正确率
|
|
|
+ }
|
|
|
+ state.visiableResult = false
|
|
|
+ // 恢复计时
|
|
|
+ resume()
|
|
|
+ resizeSwipeItemHeight()
|
|
|
+ }
|
|
|
+
|
|
|
+ // 下一个考点
|
|
|
+ const onConfirmResult = () => {
|
|
|
+ const knowledgelist = state.knowledgelist || []
|
|
|
+ console.log('🚀 ~ file: index.tsx:246 ~ onConfirmResult ~ knowledgelist', knowledgelist)
|
|
|
+ // 当前正在考试的节点
|
|
|
+ const knownleIndex = knowledgelist.findIndex((item: any) => item.id === state.id)
|
|
|
+ console.log('🚀 ~ file: index.tsx:249 ~ onConfirmResult ~ knownleIndex', knownleIndex)
|
|
|
+
|
|
|
+ let currentKnowle: any = {}
|
|
|
+
|
|
|
+ if (knownleIndex + 1 >= knowledgelist.length || knownleIndex < 0) {
|
|
|
+ currentKnowle = knowledgelist[0]
|
|
|
+ } else {
|
|
|
+ currentKnowle = knowledgelist[knownleIndex + 1]
|
|
|
+ }
|
|
|
+
|
|
|
+ state.id = currentKnowle.id
|
|
|
+
|
|
|
+ state.visiableResult = false
|
|
|
+ // 重置
|
|
|
+ onCloseResult()
|
|
|
+ }
|
|
|
+
|
|
|
+ // 拦截
|
|
|
+ const onBack = () => {
|
|
|
+ showDialog({
|
|
|
+ title: '提示',
|
|
|
+ message: '您是否退出 ',
|
|
|
+ theme: 'round-button',
|
|
|
+ confirmButtonColor: '#ff8057'
|
|
|
+ }).then(() => {
|
|
|
+ onAfter()
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ const onAfter = () => {
|
|
|
+ window.removeEventListener('popstate', onBack, false)
|
|
|
+ }
|
|
|
+
|
|
|
+ onMounted(async () => {
|
|
|
+ await getExamDetails()
|
|
|
+ await getDetails()
|
|
|
|
|
|
resizeSwipeItemHeight()
|
|
|
+
|
|
|
+ window.history.pushState(null, '', document.URL)
|
|
|
+ window.addEventListener('popstate', onBack, false)
|
|
|
})
|
|
|
return () => (
|
|
|
<div class={styles.unitDetail}>
|
|
@@ -182,7 +295,10 @@ export default defineComponent({
|
|
|
<OHeader
|
|
|
v-slots={{
|
|
|
right: () => (
|
|
|
- <span style="color: var(--van-primary-color)" onClick={onCloseExam}>
|
|
|
+ <span
|
|
|
+ style="color: var(--van-primary-color)"
|
|
|
+ onClick={() => (state.visiableSure = true)}
|
|
|
+ >
|
|
|
结束练习
|
|
|
</span>
|
|
|
)
|
|
@@ -360,29 +476,26 @@ export default defineComponent({
|
|
|
>
|
|
|
<ResultFinish
|
|
|
status="PRACTICE"
|
|
|
- confirmButtonText="继续练习本考点"
|
|
|
- cancelButtonText="下一个考点"
|
|
|
- onClose={() => (state.visiableResult = false)}
|
|
|
- onConform={() => {
|
|
|
- console.log('Success')
|
|
|
- state.visiableResult = false
|
|
|
- }}
|
|
|
+ confirmButtonText="下一个考点"
|
|
|
+ cancelButtonText="继续练习本考点"
|
|
|
+ onClose={onCloseResult}
|
|
|
+ onConform={onConfirmResult}
|
|
|
v-slots={{
|
|
|
content: () => (
|
|
|
<div class={styles.practiceResult}>
|
|
|
<div class={styles.practiceTitle}>本次练习正确率</div>
|
|
|
- <div class={styles.practiceRate}>80%</div>
|
|
|
+ <div class={styles.practiceRate}>{state.overResult.rate}%</div>
|
|
|
<Grid border={false} columnNum={3}>
|
|
|
<GridItem>
|
|
|
- <p class={styles.title}>12</p>
|
|
|
+ <p class={styles.title}>{state.overResult.time}</p>
|
|
|
<p class={styles.name}>练习时长</p>
|
|
|
</GridItem>
|
|
|
<GridItem>
|
|
|
- <p class={[styles.title]}>12</p>
|
|
|
+ <p class={[styles.title]}>{state.overResult.questionLength | 0}</p>
|
|
|
<p class={styles.name}>答题数</p>
|
|
|
</GridItem>
|
|
|
<GridItem>
|
|
|
- <p class={styles.title}>12</p>
|
|
|
+ <p class={styles.title}>{state.overResult.errorLength | 0}</p>
|
|
|
<p class={styles.name}>错题数</p>
|
|
|
</GridItem>
|
|
|
</Grid>
|
|
@@ -405,9 +518,7 @@ export default defineComponent({
|
|
|
showCancelButton
|
|
|
cancelButtonText="再等等"
|
|
|
confirmButtonText="确认完成"
|
|
|
- onConfirm={() => {
|
|
|
- state.visiableResult = true
|
|
|
- }}
|
|
|
+ onConfirm={onConfirmExam}
|
|
|
/>
|
|
|
</div>
|
|
|
)
|