diff --git a/src/views/QuestionVariant.vue b/src/views/QuestionVariant.vue index 8380816..01f04c5 100644 --- a/src/views/QuestionVariant.vue +++ b/src/views/QuestionVariant.vue @@ -39,7 +39,7 @@ const originalAnalysis = computed(() => { const raw = rawContent.value; const match = raw.match(/###\s*原题分析([\s\S]*?)(?=###\s*变式题|$)/); if (!match) return null; - + const content = match[1].trim(); return { type: extractField(content, "题型"), @@ -53,15 +53,15 @@ const originalAnalysis = computed(() => { const variantQuestions = computed(() => { const raw = rawContent.value; const result = []; - + // 匹配所有变式题块 const regex = /###\s*变式题\s*(\d+)([\s\S]*?)(?=###\s*变式题|$)/g; let match; - + while ((match = regex.exec(raw)) !== null) { const index = parseInt(match[1]); const content = match[2].trim(); - + result.push({ index, type: extractField(content, "题目类型"), @@ -73,7 +73,7 @@ const variantQuestions = computed(() => { knowledge: extractField(content, "考查知识点"), }); } - + return result; }); @@ -81,12 +81,14 @@ const variantQuestions = computed(() => { function extractOptions(text) { const options = []; // 匹配题目内容中的选项 A. xxx B. xxx C. xxx D. xxx - const contentMatch = text.match(/\*\*题目内容\*\*[::]\s*([\s\S]*?)(?=\*\*正确答案\*\*|$)/i); + const contentMatch = text.match( + /\*\*题目内容\*\*[::]\s*([\s\S]*?)(?=\*\*正确答案\*\*|$)/i + ); if (!contentMatch) return options; - + const contentBlock = contentMatch[1]; - const lines = contentBlock.split('\n'); - + const lines = contentBlock.split("\n"); + for (const line of lines) { const match = line.match(/^([A-D])[\..。::]\s*(.+)$/i); if (match) { @@ -96,13 +98,16 @@ function extractOptions(text) { }); } } - + return options; } // ── 提取字段值 ── function extractField(text, fieldName) { - const regex = new RegExp(`\\*\\*${fieldName}\\*\\*[::]\\s*([\\s\\S]*?)(?=\\n\\*\\*|$)`, "i"); + const regex = new RegExp( + `\\*\\*${fieldName}\\*\\*[::]\\s*([\\s\\S]*?)(?=\\n\\*\\*|$)`, + "i" + ); const match = text.match(regex); return match ? match[1].trim() : ""; } @@ -113,9 +118,9 @@ const buildRequestBody = () => { model: VARIANT_MODEL, messages: [ { role: "system", content: QUESTION_VARIANT_PROMPT }, - { - role: "user", - content: `请分析以下试题,并生成 ${variantCount.value} 道变式题:\n\n${textInput.value}` + { + role: "user", + content: `请分析以下试题,并生成 ${variantCount.value} 道变式题:\n\n${textInput.value}`, }, ], temperature: VARIANT_TEMPERATURE, @@ -221,11 +226,11 @@ const renderContent = (text) => { // ── 难度颜色映射 ── const getDifficultyColor = (difficulty) => { const colors = { - "容易": "#10b981", - "较易": "#34d399", - "适中": "#f59e0b", - "较难": "#f97316", - "困难": "#ef4444", + 容易: "#10b981", + 较易: "#34d399", + 适中: "#f59e0b", + 较难: "#f97316", + 困难: "#ef4444", }; return colors[difficulty] || "#6366f1"; }; @@ -243,7 +248,16 @@ onUnmounted(() => { - +