Jelajahi Sumber

多媒体阅卷:显示客观题答案

Michael Wang 3 tahun lalu
induk
melakukan
3c2d527e14
3 mengubah file dengan 70 tambahan dan 18 penghapusan
  1. 4 0
      src/api/jsonMark.ts
  2. 64 18
      src/features/mark/MultiMediaMarkBody.vue
  3. 2 0
      src/types/index.ts

+ 4 - 0
src/api/jsonMark.ts

@@ -33,6 +33,8 @@ export async function getPaper(store: UnionStore) {
               body: order3.body,
               parentBody: order2.body,
               answer: order3.answer,
+              objective: order3.objective,
+              options: order3.options,
             } as RichTextQuestion;
             store.setting.subject.questions.push(tempQuestion);
           }
@@ -42,6 +44,8 @@ export async function getPaper(store: UnionStore) {
             body: order2.body,
             parentBody: null,
             answer: order2.answer,
+            objective: order2.objective,
+            options: order2.options,
           } as RichTextQuestion;
           store.setting.subject.questions.push(tempQuestion);
         }

+ 64 - 18
src/features/mark/MultiMediaMarkBody.vue

@@ -10,23 +10,47 @@
           <div class="tw-text-xl">题干:</div>
           <div v-html="getDomByRichTextJSON(question.parentBody)?.innerHTML" />
           <div v-html="getDomByRichTextJSON(question.body)?.innerHTML" />
+          <template v-if="question.objective">
+            <div v-if="question.options">
+              <div
+                v-for="(option, index) in question.options"
+                :key="index"
+                class="tw-flex tw-gap-1"
+              >
+                {{ indexToABCD(option.number) }}.
+                <div v-html="getDomByRichTextJSON(option.body)?.innerHTML" />
+              </div>
+            </div>
+          </template>
         </div>
         <div>
-          <div style="color: blue">
-            考生答案:(字数统计:{{
-              getDomByRichTextJSON(question.studentAnswer)?.innerText.length ??
-              0
-            }})
-          </div>
-          <div
-            v-html="getDomByRichTextJSON(question.studentAnswer)?.innerHTML"
-          />
+          <template v-if="question.objective">
+            <span class="tw-text-blue-600">考生答案:</span
+            >{{ renderObjective(question.studentAnswer) }}
+          </template>
+          <template v-else>
+            <div class="tw-text-blue-600">
+              考生答案:(字数统计:{{
+                getDomByRichTextJSON(question.studentAnswer)?.innerText
+                  .length ?? 0
+              }})
+            </div>
+            <div
+              v-html="getDomByRichTextJSON(question.studentAnswer)?.innerHTML"
+            />
+          </template>
         </div>
         <div>
-          <div style="color: blue">标准答案:</div>
-          <div
-            v-html="getDomByRichTextJSON(question.standardAnswerr)?.innerHTML"
-          />
+          <template v-if="question.objective">
+            <span class="tw-text-blue-600">标准答案:</span
+            >{{ renderObjective(question.standardAnswer) }}
+          </template>
+          <template v-else>
+            <div class="tw-text-blue-600">考生答案:</div>
+            <div
+              v-html="getDomByRichTextJSON(question.standardAnswer)?.innerHTML"
+            />
+          </template>
         </div>
         <div v-if="showScore(question)" style="color: blue">
           得分 / 总分 :{{
@@ -57,6 +81,7 @@ const showScore = (question: QuestionForRender) =>
 interface StudentAnswer {
   mainNumber: number;
   subNumber: string;
+  subIndex: string;
   answer: Array<RichTextJSON> | null;
 }
 
@@ -65,9 +90,11 @@ interface QuestionForRender {
   parentBody: RichTextJSON | null;
   body: RichTextJSON;
   studentAnswer: Array<RichTextJSON> | null;
-  standardAnswerr: Array<RichTextJSON> | null;
+  standardAnswer: Array<RichTextJSON> | null;
   score: number | null;
   totalScore: number;
+  objective: boolean | null;
+  options: Array<{ number: number; body: RichTextJSON }>;
 }
 
 const questions = ref([] as Array<QuestionForRender>);
@@ -109,13 +136,15 @@ watch(
         const [mainNumber, subNumber] = questionBody.unionOrder.split("-");
         const q: StudentAnswer = stuQuestions.find(
           (v: StudentAnswer) =>
-            questionBody.unionOrder === v.mainNumber + "-" + v.subNumber
+            questionBody.unionOrder ===
+            [v.mainNumber, v.subNumber, v.subIndex]
+              .filter((v) => typeof v !== "undefined")
+              .join("-")
         ) || {
           mainNumber: mainNumber,
           subNumber: subNumber,
           answer: [],
         };
-
         const taskQuestion = (store.currentTask?.questionList || []).find(
           (v) => v.mainNumber + "" == mainNumber && v.subNumber == subNumber
         );
@@ -127,7 +156,9 @@ watch(
         questionForRender.unionOrder = questionBody.unionOrder;
         questionForRender.parentBody = questionBody.parentBody;
         questionForRender.body = questionBody.body;
-        questionForRender.standardAnswerr = questionBody.answer;
+        questionForRender.options = questionBody.options;
+        questionForRender.objective = questionBody.objective;
+        questionForRender.standardAnswer = questionBody.answer;
         questionForRender.studentAnswer = q.answer;
         questionForRender.score = taskQuestion?.score || null;
         questionForRender.totalScore = taskQuestion?.maxScore || 0;
@@ -154,7 +185,7 @@ watch(
         questionForRender.unionOrder = questionBody.unionOrder;
         questionForRender.parentBody = questionBody.parentBody;
         questionForRender.body = questionBody.body;
-        questionForRender.standardAnswerr = questionBody.answer;
+        questionForRender.standardAnswer = questionBody.answer;
         questionForRender.studentAnswer = q.answer;
         questionForRender.score = taskQuestion.score;
         questionForRender.totalScore = taskQuestion.maxScore;
@@ -165,6 +196,21 @@ watch(
   { immediate: true }
 );
 
+const indexToABCD = (index: number) => "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[index - 1];
+const renderObjective = (ans: any) => {
+  if (typeof ans === "boolean") {
+    return ans ? "正确" : "错误";
+  } else if (Array.isArray(ans) && typeof ans[0] === "boolean") {
+    return ans[0] ? "正确" : "错误";
+  } else if (Array.isArray(ans) && typeof ans[0] === "number") {
+    return ans.map((v) => indexToABCD(v)).join("");
+  } else if (Array.isArray(ans) && ans.length === 0) {
+    return "";
+  } else {
+    console.log("错误的答案类型", JSON.stringify(ans));
+  }
+};
+
 let viewer: Viewer = null as unknown as Viewer;
 onUpdated(() => {
   viewer && viewer.destroy();

+ 2 - 0
src/types/index.ts

@@ -237,6 +237,8 @@ export interface RichTextQuestion {
   body: RichTextJSON;
   parentBody: RichTextJSON | null;
   answer: Array<RichTextJSON> | null;
+  objective: boolean | null;
+  options: Array<{ number: number; body: RichTextJSON }>;
 }
 export interface RichTextJSON {
   sections: RichTextSectionJSON[];