|
|
@@ -3,7 +3,7 @@
|
|
|
<!-- 测试标题 -->
|
|
|
<div class="test-title" @click="handleClick">
|
|
|
<el-icon><ArrowLeftBold /></el-icon>
|
|
|
- 在线测试
|
|
|
+ {{ topicTitle }}
|
|
|
</div>
|
|
|
<!-- 测试内容 -->
|
|
|
<div class="test-content">
|
|
|
@@ -43,12 +43,12 @@
|
|
|
@click="handlePrevQuestion"
|
|
|
>上一题</el-button
|
|
|
>
|
|
|
- <!-- 修改下一题按钮样式 -->
|
|
|
+ <!-- 下一题按钮样式 最后一题显示为提交 -->
|
|
|
<el-button
|
|
|
type="primary"
|
|
|
class="next-question-btn"
|
|
|
- @click="handleNextQuestion"
|
|
|
- >下一题</el-button
|
|
|
+ @click="currentQuestionIndex === questions.length - 1 ? handleSubmit() : handleNextQuestion()"
|
|
|
+ >{{ currentQuestionIndex === questions.length - 1 ? '提交' : '下一题' }}</el-button
|
|
|
>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -63,7 +63,10 @@
|
|
|
v-for="num in questions.length"
|
|
|
:key="num"
|
|
|
class="circle-btn"
|
|
|
- :class="{ clicked: clickedNumbers.includes(num) }"
|
|
|
+ :class="{
|
|
|
+ clicked: clickedNumbers.includes(num),
|
|
|
+ current: num === currentQuestionIndex + 1
|
|
|
+ }"
|
|
|
@click="handleButtonClick(num)"
|
|
|
>{{ num }}</el-button
|
|
|
>
|
|
|
@@ -81,6 +84,7 @@ import { ArrowLeftBold } from '@element-plus/icons-vue'
|
|
|
import { useRouter,useRoute } from 'vue-router'
|
|
|
|
|
|
import { QuestionTopicList } from '@/api/question/test.js'
|
|
|
+import { ElMessage } from 'element-plus'
|
|
|
|
|
|
const router = useRouter()
|
|
|
const route = useRoute()
|
|
|
@@ -97,10 +101,13 @@ const handleClick = () => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-// 添加题目数据
|
|
|
-const questions = ref([
|
|
|
-])
|
|
|
+// 渲染列表标题
|
|
|
+const topicTitle = ref(
|
|
|
+ route.query.title
|
|
|
+)
|
|
|
|
|
|
+// 添加题目数据
|
|
|
+const questions = ref([])
|
|
|
onMounted(()=>{
|
|
|
// 获取路由参数中的id
|
|
|
const id = route.query.id
|
|
|
@@ -108,10 +115,11 @@ onMounted(()=>{
|
|
|
if (id) {
|
|
|
// 将id作为参数传递给QuestionTopicList接口
|
|
|
QuestionTopicList({ qrId: id }).then(res=>{
|
|
|
- console.log(res);
|
|
|
// 将接口返回的题目数据赋值给questions
|
|
|
questions.value = res.data.questionList || []
|
|
|
- // 初始化currentQuestionIndex,防止越界
|
|
|
+ // 初始化用户答案数组
|
|
|
+ userAnswers.value = new Array(questions.value.length).fill(null)
|
|
|
+ // 初始化currentQuestionIndex
|
|
|
if (questions.value.length > 0) {
|
|
|
currentQuestionIndex.value = 0
|
|
|
}
|
|
|
@@ -144,19 +152,28 @@ const handleNextQuestion = () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 提交
|
|
|
+const handleSubmit = () => {
|
|
|
+ // 保存最后一题答案
|
|
|
+ userAnswers.value[currentQuestionIndex.value] = selectedOption.value;
|
|
|
+ // 检查是否所有题目都已回答
|
|
|
+ const allAnswered = userAnswers.value.every(answer => answer !== null && answer !== undefined)
|
|
|
+ if(!allAnswered){
|
|
|
+ ElMessage.error('检测到有题目未完成,请回答所有题目后再提交')
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 答完全部答完跳转到提交页面
|
|
|
+ router.push('/testSubmit')
|
|
|
+}
|
|
|
+
|
|
|
// 答题卡
|
|
|
const handleButtonClick = (num) => {
|
|
|
// 切换到对应题目
|
|
|
currentQuestionIndex.value = num - 1
|
|
|
// 加载该题目的答案
|
|
|
selectedOption.value = userAnswers.value[currentQuestionIndex.value] || null
|
|
|
- // 答题卡选中状态切换逻辑
|
|
|
- // if (clickedNumbers.value.includes(num)) {
|
|
|
- // clickedNumbers.value = clickedNumbers.value.filter(n => n !== num)
|
|
|
- // } else {
|
|
|
- // clickedNumbers.value.push(num)
|
|
|
- // }
|
|
|
}
|
|
|
+
|
|
|
// 监听选项变化,自动更新答题卡状态
|
|
|
watch(selectedOption, (newVal) => {
|
|
|
if (newVal !== null) {
|
|
|
@@ -373,6 +390,9 @@ watch(selectedOption, (newVal) => {
|
|
|
color: #909090;
|
|
|
min-width: auto; // 移除Element Plus按钮默认最小宽度
|
|
|
}
|
|
|
+.circle-btn.current {
|
|
|
+ border: 2px solid #9e78e7;
|
|
|
+}
|
|
|
|
|
|
.circle-btn:focus,
|
|
|
.circle-btn:active,
|