|
@@ -39,8 +39,8 @@
|
|
|
class="option"
|
|
class="option"
|
|
|
:class="{
|
|
:class="{
|
|
|
selected: selectedIdx === index,
|
|
selected: selectedIdx === index,
|
|
|
- rightOption: questionList[currentQuestionIdx].rightOptionIdx === index,
|
|
|
|
|
- wrongOption: questionList[currentQuestionIdx].rightOptionIdx !== index,
|
|
|
|
|
|
|
+ rightOption: isCorrect === true,
|
|
|
|
|
+ wrongOption: isCorrect === false,
|
|
|
submitted: isSubmitted,
|
|
submitted: isSubmitted,
|
|
|
notSubmitted: !isSubmitted,
|
|
notSubmitted: !isSubmitted,
|
|
|
}"
|
|
}"
|
|
@@ -58,7 +58,7 @@
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<div
|
|
<div
|
|
|
- v-show="isSubmitted && selectedIdx === index && questionList[currentQuestionIdx].rightOptionIdx === index"
|
|
|
|
|
|
|
+ v-show="isSubmitted && selectedIdx === index && isCorrect"
|
|
|
class="result-tip"
|
|
class="result-tip"
|
|
|
>
|
|
>
|
|
|
<img
|
|
<img
|
|
@@ -69,7 +69,7 @@
|
|
|
>
|
|
>
|
|
|
</div>
|
|
</div>
|
|
|
<div
|
|
<div
|
|
|
- v-show="isSubmitted && selectedIdx === index && questionList[currentQuestionIdx].rightOptionIdx !== index"
|
|
|
|
|
|
|
+ v-show="isSubmitted && selectedIdx === index && isCorrect === false"
|
|
|
class="result-tip"
|
|
class="result-tip"
|
|
|
>
|
|
>
|
|
|
<img
|
|
<img
|
|
@@ -113,6 +113,7 @@
|
|
|
</div>
|
|
</div>
|
|
|
<button
|
|
<button
|
|
|
class="next"
|
|
class="next"
|
|
|
|
|
+ :disabled="isSubmitted && isCorrect === undefined"
|
|
|
@click="onClickNext"
|
|
@click="onClickNext"
|
|
|
>
|
|
>
|
|
|
下一题
|
|
下一题
|
|
@@ -146,13 +147,12 @@ import { ref, computed, watch, onMounted, onBeforeUnmount, nextTick } from "vue"
|
|
|
import { useRoute, useRouter } from "vue-router"
|
|
import { useRoute, useRouter } from "vue-router"
|
|
|
import { useStore } from "vuex"
|
|
import { useStore } from "vuex"
|
|
|
import dayjs from 'dayjs'
|
|
import dayjs from 'dayjs'
|
|
|
-import { addScore, getScore, getExamQuestionList, notifyQuit } from '@/api.js'
|
|
|
|
|
|
|
+import { addScore, getScore, getExamQuestionList, checkExamAnswer, notifyQuit } from '@/api.js'
|
|
|
import GameRule from '@/components/GameRule.vue'
|
|
import GameRule from '@/components/GameRule.vue'
|
|
|
import NotifyComp from '@/components/NotifyComp.vue'
|
|
import NotifyComp from '@/components/NotifyComp.vue'
|
|
|
import { Base64 } from "js-base64"
|
|
import { Base64 } from "js-base64"
|
|
|
import MusicBg from '@/assets/audio/1.mp3'
|
|
import MusicBg from '@/assets/audio/1.mp3'
|
|
|
|
|
|
|
|
-
|
|
|
|
|
const route = useRoute()
|
|
const route = useRoute()
|
|
|
const router = useRouter()
|
|
const router = useRouter()
|
|
|
const store = useStore()
|
|
const store = useStore()
|
|
@@ -169,27 +169,14 @@ const isShowLoading = ref(true)
|
|
|
getExamQuestionList().then((res) => {
|
|
getExamQuestionList().then((res) => {
|
|
|
questionList.value = res.map((questionItem) => {
|
|
questionList.value = res.map((questionItem) => {
|
|
|
const optionsAndAnswer = JSON.parse(questionItem.answer)
|
|
const optionsAndAnswer = JSON.parse(questionItem.answer)
|
|
|
-
|
|
|
|
|
- // 对正确答案解密
|
|
|
|
|
- const decodeStr = (str) => {
|
|
|
|
|
- const NUM = 2
|
|
|
|
|
- const str1 = str.substring(8)
|
|
|
|
|
- const str2 = str1.substring(0, str1.length - 8)
|
|
|
|
|
- const front = str2.slice(-NUM)
|
|
|
|
|
- const end = str2.substring(0, str2.length - 8 - NUM)
|
|
|
|
|
- return front + end
|
|
|
|
|
- }
|
|
|
|
|
- optionsAndAnswer.correct = Base64.decode(decodeStr(optionsAndAnswer.correct))
|
|
|
|
|
-
|
|
|
|
|
- // console.log(optionsAndAnswer)
|
|
|
|
|
-
|
|
|
|
|
const ret = {
|
|
const ret = {
|
|
|
|
|
+ id: questionItem.id,
|
|
|
question: questionItem.question,
|
|
question: questionItem.question,
|
|
|
answerOptions: optionsAndAnswer.answer.map((answerItem) => {
|
|
answerOptions: optionsAndAnswer.answer.map((answerItem) => {
|
|
|
return answerItem.name
|
|
return answerItem.name
|
|
|
}),
|
|
}),
|
|
|
- rightOptionIdx: optionsAndAnswer.answer.findIndex((answerItem) => {
|
|
|
|
|
- return answerItem.val === optionsAndAnswer.correct
|
|
|
|
|
|
|
+ answerOptionValues: optionsAndAnswer.answer.map((answerItem) => {
|
|
|
|
|
+ return answerItem.val
|
|
|
}),
|
|
}),
|
|
|
desc: questionItem.description
|
|
desc: questionItem.description
|
|
|
}
|
|
}
|
|
@@ -255,25 +242,6 @@ const questionList = ref([
|
|
|
// '是',
|
|
// '是',
|
|
|
// '不是',
|
|
// '不是',
|
|
|
// ],
|
|
// ],
|
|
|
- // rightOptionIdx: 0,
|
|
|
|
|
- // desc: '这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本',
|
|
|
|
|
- // },
|
|
|
|
|
- // {
|
|
|
|
|
- // question: '你是sb吗?',
|
|
|
|
|
- // answerOptions: [
|
|
|
|
|
- // '是',
|
|
|
|
|
- // '不是',
|
|
|
|
|
- // ],
|
|
|
|
|
- // rightOptionIdx: 0,
|
|
|
|
|
- // desc: '这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本',
|
|
|
|
|
- // },
|
|
|
|
|
- // {
|
|
|
|
|
- // question: '你是sb吗?',
|
|
|
|
|
- // answerOptions: [
|
|
|
|
|
- // '是',
|
|
|
|
|
- // '不是',
|
|
|
|
|
- // ],
|
|
|
|
|
- // rightOptionIdx: 0,
|
|
|
|
|
// desc: '这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本',
|
|
// desc: '这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本这是一段文本',
|
|
|
// },
|
|
// },
|
|
|
])
|
|
])
|
|
@@ -281,19 +249,27 @@ const currentQuestionIdx = ref(0)
|
|
|
const isSubmitted = computed(() => {
|
|
const isSubmitted = computed(() => {
|
|
|
return selectedIdx.value !== null
|
|
return selectedIdx.value !== null
|
|
|
})
|
|
})
|
|
|
-function onClickOption(idx) {
|
|
|
|
|
|
|
+const isCorrect = ref(undefined)
|
|
|
|
|
+async function onClickOption(idx) {
|
|
|
selectedIdx.value = idx
|
|
selectedIdx.value = idx
|
|
|
- if (selectedIdx.value === questionList.value[currentQuestionIdx.value].rightOptionIdx) {
|
|
|
|
|
- if (store.state.loginStatus && !store.state.ifScoreLimitReached) {
|
|
|
|
|
- bonusPoint.value += store.state.gameRuleList[1].score
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ isCorrect.value = await checkExamAnswer(questionList.value[currentQuestionIdx.value].id, questionList.value[currentQuestionIdx.value].answerOptionValues[selectedIdx.value])
|
|
|
|
|
+ console.log(isCorrect.value)
|
|
|
|
|
+ if (isCorrect.value) {
|
|
|
|
|
+ if (store.state.loginStatus && !store.state.ifScoreLimitReached) {
|
|
|
|
|
+ bonusPoint.value += store.state.gameRuleList[1].score
|
|
|
|
|
+ }
|
|
|
|
|
+ correntCount.value++
|
|
|
}
|
|
}
|
|
|
- correntCount.value++
|
|
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
function onClickNext() {
|
|
function onClickNext() {
|
|
|
if (currentQuestionIdx.value < questionList.value.length - 1) {
|
|
if (currentQuestionIdx.value < questionList.value.length - 1) {
|
|
|
currentQuestionIdx.value++
|
|
currentQuestionIdx.value++
|
|
|
selectedIdx.value = null
|
|
selectedIdx.value = null
|
|
|
|
|
+ isCorrect.value = undefined
|
|
|
} else {
|
|
} else {
|
|
|
if (store.state.loginStatus && !store.state.ifScoreLimitReached && bonusPoint.value !== 0) {
|
|
if (store.state.loginStatus && !store.state.ifScoreLimitReached && bonusPoint.value !== 0) {
|
|
|
addScore(bonusPoint.value, '一起来助农').then(() => {
|
|
addScore(bonusPoint.value, '一起来助农').then(() => {
|