Browse Source

多媒体阅卷完善类型信息

Michael Wang 3 years ago
parent
commit
7a771c6867
3 changed files with 64 additions and 24 deletions
  1. 20 7
      src/api/jsonMark.ts
  2. 7 14
      src/features/mark/MultiMediaMarkBody.vue
  3. 37 3
      src/types/index.ts

+ 20 - 7
src/api/jsonMark.ts

@@ -1,17 +1,30 @@
 import { httpApp } from "@/plugins/axiosApp";
-import { RichTextQuestion, MarkStore } from "@/types";
+import {
+  RichTextQuestion,
+  MarkStore,
+  StudentAnswer,
+  OExamPaperJSON,
+  ECSPaperJSON,
+} from "@/types";
 
-/** 清理复核任务 */
-export async function getJSON(url: string) {
-  return httpApp.get(url, { withCredentials: false });
+/** 获取学生答案JSON */
+export async function getStudentAnswerJSON(url: string) {
+  return httpApp.get<StudentAnswer[]>(url, { withCredentials: false });
+}
+
+/** 获取试卷JSON */
+async function getPaperJSON(url: string) {
+  return httpApp.get(url, {
+    withCredentials: false,
+  });
 }
 
 export async function getPaper(store: MarkStore) {
-  const res = await getJSON(store.setting.subject.paperUrl);
+  const res = await getPaperJSON(store.setting.subject.paperUrl);
   store.setting.subject.questions = [];
   if (res.data.questions) {
     // 云平台格式
-    const questions = res.data.questions; // TODO: add type
+    const questions: ECSPaperJSON = res.data.questions;
     for (const q of questions) {
       const tempQuestion = {
         unionOrder: q.mainNumber + "-" + q.subNumber,
@@ -22,7 +35,7 @@ export async function getPaper(store: MarkStore) {
       store.setting.subject.questions.push(tempQuestion);
     }
   } else {
-    const details = res.data.details;
+    const details: OExamPaperJSON = res.data.details;
     for (let order1 of details) {
       for (let order2 of order1.questions) {
         if (order2.subQuestions) {

+ 7 - 14
src/features/mark/MultiMediaMarkBody.vue

@@ -64,7 +64,7 @@
 </template>
 
 <script setup lang="ts">
-import { getJSON } from "@/api/jsonMark";
+import { getStudentAnswerJSON } from "@/api/jsonMark";
 import { store } from "@/store/store";
 import { onUpdated, watch } from "vue";
 import { renderRichText } from "@/utils/renderJSON";
@@ -78,13 +78,6 @@ const isSeePaper = route.name === "StudentTrack";
 const showScore = (question: QuestionForRender) =>
   route.name !== "Mark" && question.totalScore;
 
-interface StudentAnswer {
-  mainNumber: number;
-  subNumber: string;
-  subIndex: string;
-  answer: Array<RichTextJSON> | null;
-}
-
 interface QuestionForRender {
   unionOrder: string;
   parentBody: RichTextJSON | null;
@@ -99,7 +92,7 @@ interface QuestionForRender {
 
 let questions: QuestionForRender[] = $ref([]);
 async function updateStudentAnswerJSON() {
-  return getJSON(store.currentTask?.jsonUrl as string);
+  return getStudentAnswerJSON(store.currentTask?.jsonUrl as string);
 }
 
 function getDomByRichTextJSON(rt: Array<RichTextJSON> | RichTextJSON | null) {
@@ -122,7 +115,7 @@ watch(
     if (!store.currentTask?.jsonUrl) return;
     const res = await updateStudentAnswerJSON();
 
-    const stuAnswers: StudentAnswer[] = res.data;
+    const stuAnswers = res.data;
     for (const ans of stuAnswers) {
       if (ans.answer && !Array.isArray(ans.answer)) {
         ans.answer = [ans.answer];
@@ -134,8 +127,8 @@ watch(
         const questionForRender = {} as QuestionForRender;
 
         const [mainNumber, subNumber] = questionBody.unionOrder.split("-");
-        const stuAns: StudentAnswer = stuAnswers.find(
-          (v: StudentAnswer) =>
+        const stuAns = stuAnswers.find(
+          (v) =>
             questionBody.unionOrder ===
             [v.mainNumber, v.subNumber, v.subIndex]
               .filter((v) => typeof v !== "undefined")
@@ -172,8 +165,8 @@ watch(
         );
         if (!questionBody) continue;
 
-        const stuAns: StudentAnswer = stuAnswers.find(
-          (v: StudentAnswer) =>
+        const stuAns = stuAnswers.find(
+          (v) =>
             questionBody.unionOrder ===
             [v.mainNumber, v.subNumber, v.subIndex]
               .filter((v) => typeof v !== "undefined")

+ 37 - 3
src/types/index.ts

@@ -254,6 +254,11 @@ export interface getHistory {
   (historyQuery: HistoryQueryParams): any;
 }
 
+export interface CommonResponse {
+  success: boolean; // 请求是否成功
+  message: string; // 错误消息
+}
+
 // 仲裁用:评卷明细
 export interface MarkDetail {
   markerName: string;
@@ -262,6 +267,7 @@ export interface MarkDetail {
   scoreList: string;
 }
 
+// 多媒体评卷 start
 export interface RichTextQuestion {
   unionOrder: string; // 题目的综合题号 1-2-4
   body: RichTextJSON;
@@ -288,7 +294,35 @@ export interface RichTextBlockJSON {
   } | null;
 }
 
-export interface CommonResponse {
-  success: boolean; // 请求是否成功
-  message: string; // 错误消息
+export interface StudentAnswer {
+  mainNumber: number;
+  subNumber: string;
+  subIndex: string;
+  answer: Array<RichTextJSON> | null;
+}
+
+// 云平台试卷格式
+export type ECSPaperJSON = {
+  mainNumber: number;
+  subNumber: string;
+  body: RichTextJSON;
+  parentBody: RichTextJSON | null;
+  answer: RichTextJSON;
+}[];
+
+// 在线考试平台试卷格式
+export type OExamPaperJSON = OExamPaperJSONQuestionList[];
+
+interface OExamPaperJSONQuestionList {
+  number: number; // 大题号
+  questions: OExamPaperJSONQuestion[];
+}
+interface OExamPaperJSONQuestion {
+  number: number;
+  body: RichTextJSON;
+  answer: RichTextJSON[] | null;
+  objective: boolean | null;
+  options: Array<{ number: number; body: RichTextJSON }>;
+  subQuestions: OExamPaperJSONQuestion[] | null;
 }
+// 多媒体评卷 end