优化新实例

This commit is contained in:
Guarp 2025-02-27 07:40:11 +08:00
parent 9926056f71
commit c3b455b05d
3 changed files with 63 additions and 20 deletions

View File

@ -21,7 +21,10 @@ const formattedLatex = ref('');
// //
watch(() => props.contentInput, (newValue) => { watch(() => props.contentInput, (newValue) => {
localInput.value = newValue; localInput.value = newValue.replaceAll('<code>', '$')
.replaceAll('</code>', '$')
.replaceAll('/lt', '<')
.replaceAll('/gt', '>');
}); });
// localInput // localInput

View File

@ -1,9 +1,11 @@
<template> <template>
<div v-html="processedText" class="question-text"></div> <general-renderer :content-input="processedText" class="question-text"></general-renderer>
<!-- <div v-html="" class="question-text"></div>-->
</template> </template>
<script setup> <script setup>
import { computed } from 'vue'; import { computed } from 'vue';
import GeneralRenderer from "../../../components/GeneralRenderer.vue";
const props = defineProps({ const props = defineProps({
text: { text: {

View File

@ -17,7 +17,7 @@
:name="'question'" :name="'question'"
:disabled="submitted" :disabled="submitted"
/> />
<span v-html="processMedia(answer, data.medias)"></span> <general-renderer :content-input="processMedia(answer, data.medias)"></general-renderer>
</label> </label>
</div> </div>
</div> </div>
@ -30,10 +30,10 @@
<div v-if="submitted" class="result"> <div v-if="submitted" class="result">
<p v-if="isCorrect" class="correct-text">答对了</p> <p v-if="isCorrect" class="correct-text">答对了</p>
<p v-else class="incorrect-text">答错了</p> <p v-else class="incorrect-text">答错了</p>
<p>正确答案是<span v-html="processMedia(correctAnswerText, data.medias)"></span></p> <p>正确答案是<general-renderer :content-input="processMedia(correctAnswerText, data.medias)"></general-renderer></p>
<div v-if="currentQuestion.explanation" class="explanation"> <div v-if="currentQuestion.explanation" class="explanation">
<h3>解题思路</h3> <h3>解题思路</h3>
<div v-html="processMedia(currentQuestion.explanation, data.medias)"></div> <general-renderer :content-input="processMedia(currentQuestion.explanation, data.medias)"></general-renderer>
</div> </div>
<!-- 类似题目对比 --> <!-- 类似题目对比 -->
@ -42,7 +42,7 @@
<div v-for="(similar, index) in similarQuestions" :key="index" class="similar-question"> <div v-for="(similar, index) in similarQuestions" :key="index" class="similar-question">
<h4>题目 {{ index + 1 }}</h4> <h4>题目 {{ index + 1 }}</h4>
<QuestionText :text="similar.text" :medias="data.medias" /> <QuestionText :text="similar.text" :medias="data.medias" />
<p>正确答案<span v-html="processMedia(similar.correctAnswer, data.medias)"></span></p> <p>正确答案<general-renderer :content-input="processMedia(similar.correctAnswer, data.medias)"></general-renderer></p>
</div> </div>
</div> </div>
</div> </div>
@ -67,6 +67,7 @@
import { reactive, ref, onMounted, computed } from 'vue'; import { reactive, ref, onMounted, computed } from 'vue';
import axios from 'axios'; import axios from 'axios';
import QuestionText from './QuestionText.vue'; import QuestionText from './QuestionText.vue';
import GeneralRenderer from "../../../components/GeneralRenderer.vue";
// JSON // JSON
const data = reactive({ const data = reactive({
@ -87,17 +88,19 @@ const isCorrect = ref(false);
const correctAnswerText = ref(''); const correctAnswerText = ref('');
const correctIndex = ref(null); const correctIndex = ref(null);
const isLoading = ref(true); const isLoading = ref(true);
const questionCount = ref(1); const questionCount = ref(1); //
const similarQuestions = ref([]); // const similarQuestions = ref([]);
// 20
const recentResults = ref([]); const recentResults = ref([]);
const examQuestions = ref([]); //
const totalQuestions = ref(0);
// 40
// //
const progressPercentage = computed(() => { const progressPercentage = computed(() => {
if (recentResults.value.length === 0) return 0; if (recentResults.value.length === 0) return 0;
const correctCount = recentResults.value.filter(result => result).length; const correctCount = recentResults.value.filter(result => result).length;
return (correctCount / Math.min(recentResults.value.length, 20)) * 100; return (correctCount / Math.min(recentResults.value.length, totalQuestions.value)) * 100;
}); });
// //
@ -106,9 +109,7 @@ onMounted(async () => {
const response = await axios.get('https://mva-cyber.club/data/file/phy250226.json'); const response = await axios.get('https://mva-cyber.club/data/file/phy250226.json');
const jsonData = response.data; const jsonData = response.data;
Object.assign(data, jsonData); Object.assign(data, jsonData);
generateNewExam(); //
//
selectRandomQuestion();
} catch (error) { } catch (error) {
console.error('加载数据失败:', error); console.error('加载数据失败:', error);
alert('数据加载失败,请稍后重试。'); alert('数据加载失败,请稍后重试。');
@ -201,6 +202,31 @@ function calculateStringSimilarity(str1, str2) {
// //
return Number(similarity.toFixed(2)); return Number(similarity.toFixed(2));
} }
//
function generateNewExam() {
if (data.texts.length <= 1) return;
//
const indices = Array.from({ length: data.texts.length - 1 }, (_, i) => i + 1);
for (let i = indices.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[indices[i], indices[j]] = [indices[j], indices[i]];
}
//
examQuestions.value = indices.map(index => ({
text: data.texts[index],
answers: data.answers[index],
answerkeys: data.answerkeys[index],
explanation: data.explanations[index],
type: data.itemtypes[index]
}));
totalQuestions.value = examQuestions.value.length;
questionCount.value = 1;
recentResults.value = [];
selectCurrentQuestion();
}
// //
function findSimilarQuestions() { function findSimilarQuestions() {
const currentText = currentQuestion.value.text; const currentText = currentQuestion.value.text;
@ -208,7 +234,7 @@ function findSimilarQuestions() {
for (let i = 1; i < data.itemtypes.length; i++) { for (let i = 1; i < data.itemtypes.length; i++) {
console.log(calculateStringSimilarity(data.texts[i], currentText), {1: data.texts[i]}) console.log(calculateStringSimilarity(data.texts[i], currentText), {1: data.texts[i]})
if ( if (
calculateStringSimilarity(data.texts[i], currentText) > 80 && // calculateStringSimilarity(data.texts[i], currentText) > 50 && //
data.texts[i] !== currentQuestion.value.text// data.texts[i] !== currentQuestion.value.text//
// similar.length < 2 // 2 // similar.length < 2 // 2
) { ) {
@ -221,7 +247,14 @@ function findSimilarQuestions() {
} }
similarQuestions.value = similar; similarQuestions.value = similar;
} }
function selectCurrentQuestion() {
if (questionCount.value <= totalQuestions.value) {
currentQuestion.value = examQuestions.value[questionCount.value - 1];
userAnswer.value = null;
submitted.value = false;
similarQuestions.value = [];
}
}
// //
function submitAnswer() { function submitAnswer() {
if (userAnswer.value === null) { if (userAnswer.value === null) {
@ -233,9 +266,9 @@ function submitAnswer() {
correctAnswerText.value = currentQuestion.value.answers[correctIndex.value + 1]; correctAnswerText.value = currentQuestion.value.answers[correctIndex.value + 1];
submitted.value = true; submitted.value = true;
// 20 // 40
recentResults.value.push(isCorrect.value); recentResults.value.push(isCorrect.value);
if (recentResults.value.length > 20) { if (recentResults.value.length > 40) {
recentResults.value.shift(); recentResults.value.shift();
} }
@ -245,8 +278,13 @@ function submitAnswer() {
// //
function nextQuestion() { function nextQuestion() {
questionCount.value++; if (questionCount.value < totalQuestions.value) {
selectRandomQuestion(); questionCount.value++;
selectCurrentQuestion();
} else {
alert('试卷已完成!将生成新试卷。');
generateNewExam(); //
}
} }
</script> </script>