|
|
@@ -28,7 +28,7 @@
|
|
|
<el-radio-button
|
|
|
v-for="option in questions[currentQuestionIndex]?.questionOptionsList || []"
|
|
|
:key="option.oid"
|
|
|
- :label="option.ovalue"
|
|
|
+ :label="option.oid"
|
|
|
>{{ option.ovalue }}. {{ option.oname }}</el-radio-button
|
|
|
>
|
|
|
</el-radio-group>
|
|
|
@@ -83,7 +83,7 @@ import { ref,watch ,onMounted} from 'vue'
|
|
|
import { ArrowLeftBold } from '@element-plus/icons-vue'
|
|
|
import { useRouter,useRoute } from 'vue-router'
|
|
|
|
|
|
-import { QuestionTopicList } from '@/api/question/test.js'
|
|
|
+import {QuestionTopicList, QuestionTopicSave} from '@/api/question/test.js'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
|
|
|
const router = useRouter()
|
|
|
@@ -94,6 +94,7 @@ const clickedNumbers = ref([])
|
|
|
// 当前题目索引
|
|
|
const currentQuestionIndex = ref(0)
|
|
|
const userAnswers = ref([]) // 存储用户答案
|
|
|
+const userQuestAnswers = ref([]) // 存储用户答案
|
|
|
|
|
|
const handleClick = () => {
|
|
|
router.push({
|
|
|
@@ -107,16 +108,18 @@ const topicTitle = ref(
|
|
|
)
|
|
|
|
|
|
// 添加题目数据
|
|
|
+const qrId = ref()
|
|
|
+const questResultId = ref()
|
|
|
const questions = ref([])
|
|
|
onMounted(()=>{
|
|
|
// 获取路由参数中的id
|
|
|
- const id = route.query.id
|
|
|
- console.log(id);
|
|
|
- if (id) {
|
|
|
+ qrId.value = route.query.id
|
|
|
+ if (qrId.value) {
|
|
|
// 将id作为参数传递给QuestionTopicList接口
|
|
|
- QuestionTopicList({ qrId: id }).then(res=>{
|
|
|
+ QuestionTopicList({ qrId: qrId.value }).then(res=>{
|
|
|
+ questResultId.value = res.data.qrResultId
|
|
|
// 将接口返回的题目数据赋值给questions
|
|
|
- questions.value = res.data.questionList || []
|
|
|
+ questions.value = res.data.questionnaire.questionList || []
|
|
|
// 初始化用户答案数组
|
|
|
userAnswers.value = new Array(questions.value.length).fill(null)
|
|
|
// 初始化currentQuestionIndex
|
|
|
@@ -134,10 +137,13 @@ onMounted(()=>{
|
|
|
const handlePrevQuestion = () => {
|
|
|
if (currentQuestionIndex.value > 0) {
|
|
|
// 保存当前题目的答案
|
|
|
- userAnswers.value[currentQuestionIndex.value] = selectedOption.value;
|
|
|
+ userAnswers.value[currentQuestionIndex.value] = {
|
|
|
+ qid: questions.value[currentQuestionIndex.value].qid,
|
|
|
+ oid: selectedOption.value
|
|
|
+ };
|
|
|
currentQuestionIndex.value--;
|
|
|
// 加载上一题的答案
|
|
|
- selectedOption.value = userAnswers.value[currentQuestionIndex.value] || null;
|
|
|
+ selectedOption.value = userAnswers.value[currentQuestionIndex.value]?.oid || null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -145,25 +151,40 @@ const handlePrevQuestion = () => {
|
|
|
const handleNextQuestion = () => {
|
|
|
if (currentQuestionIndex.value < questions.value.length - 1) {
|
|
|
// 保存当前题目的答案
|
|
|
- userAnswers.value[currentQuestionIndex.value] = selectedOption.value;
|
|
|
+ userAnswers.value[currentQuestionIndex.value] = {
|
|
|
+ qid: questions.value[currentQuestionIndex.value].qid,
|
|
|
+ oid: selectedOption.value
|
|
|
+ };
|
|
|
currentQuestionIndex.value++;
|
|
|
// 加载下一题的答案
|
|
|
- selectedOption.value = userAnswers.value[currentQuestionIndex.value] || null;
|
|
|
+ selectedOption.value = userAnswers.value[currentQuestionIndex.value]?.oid || null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 提交
|
|
|
const handleSubmit = () => {
|
|
|
// 保存最后一题答案
|
|
|
- userAnswers.value[currentQuestionIndex.value] = selectedOption.value;
|
|
|
+ userAnswers.value[currentQuestionIndex.value] = {
|
|
|
+ qid: questions.value[currentQuestionIndex.value].qid,
|
|
|
+ oid: selectedOption.value
|
|
|
+ };
|
|
|
// 检查是否所有题目都已回答
|
|
|
- const allAnswered = userAnswers.value.every(answer => answer !== null && answer !== undefined)
|
|
|
+ const allAnswered = userAnswers.value.every(answer => answer?.oid !== null && answer?.oid !== undefined)
|
|
|
if(!allAnswered){
|
|
|
ElMessage.error('检测到有题目未完成,请回答所有题目后再提交')
|
|
|
return;
|
|
|
}
|
|
|
+ console.log("userAnswers.value----", qrId.value,questResultId.value)
|
|
|
+
|
|
|
// 答完全部答完跳转到提交页面
|
|
|
- router.push('/testSubmit')
|
|
|
+ QuestionTopicSave({
|
|
|
+ "qrId": Number(qrId.value),
|
|
|
+ "qrResultId": Number(questResultId.value),
|
|
|
+ "questionList": userAnswers.value
|
|
|
+ }).then(res=>{
|
|
|
+ ElMessage.success('提交成功')
|
|
|
+ router.push('/testSubmit')
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
// 答题卡
|
|
|
@@ -171,7 +192,7 @@ const handleButtonClick = (num) => {
|
|
|
// 切换到对应题目
|
|
|
currentQuestionIndex.value = num - 1
|
|
|
// 加载该题目的答案
|
|
|
- selectedOption.value = userAnswers.value[currentQuestionIndex.value] || null
|
|
|
+ selectedOption.value = userAnswers.value[currentQuestionIndex.value]?.oid || null
|
|
|
}
|
|
|
|
|
|
// 监听选项变化,自动更新答题卡状态
|
|
|
@@ -179,7 +200,10 @@ watch(selectedOption, (newVal) => {
|
|
|
if (newVal !== null) {
|
|
|
const currentQuestionNumber = currentQuestionIndex.value + 1
|
|
|
// 保存当前题目的答案
|
|
|
- userAnswers.value[currentQuestionIndex.value] = newVal
|
|
|
+ userAnswers.value[currentQuestionIndex.value] = {
|
|
|
+ qid: questions.value[currentQuestionIndex.value].qid,
|
|
|
+ oid: newVal
|
|
|
+ }
|
|
|
if (!clickedNumbers.value.includes(currentQuestionNumber)) {
|
|
|
clickedNumbers.value.push(currentQuestionNumber)
|
|
|
}
|