瀏覽代碼

feat: 轨迹图兼容旧版数据

zhangjie 2 月之前
父節點
當前提交
512bd2308f
共有 4 個文件被更改,包括 102 次插入34 次删除
  1. 3 0
      src/features/track/Track.vue
  2. 13 2
      src/features/track/TrackBody.vue
  3. 85 32
      src/features/track/composables/useTrackTag.ts
  4. 1 0
      src/types/index.ts

+ 3 - 0
src/features/track/Track.vue

@@ -108,6 +108,9 @@ async function updateTask() {
         splitConfig: item.picList || [],
       };
     }),
+    hasMarkArea: taskData.subjectiveQuestions.some((item) => {
+      return item.picList?.length;
+    }),
   };
 
   // 获取客观题选项信息

+ 13 - 2
src/features/track/TrackBody.vue

@@ -150,8 +150,12 @@ import useTrack from "./composables/useTrack";
 
 const markStore = useMarkStore();
 const { answerPaperScale } = useBodyScroll();
-const { parseMarkDetailList, paserRecogData, parseObjectiveAnswerTags } =
-  useTrackTag();
+const {
+  parseMarkDetailList,
+  paserRecogData,
+  parseObjectiveAnswerTags,
+  parseMode4Data,
+} = useTrackTag();
 const { addTrackColorAttr, addTagColorAttr, addHeaderTrackColorAttr } =
   useTrack();
 
@@ -256,6 +260,13 @@ async function processImage() {
       objectiveAnswerTags: objectiveAnswerTagList[indexInSliceUrls - 1],
     });
   }
+
+  if (
+    !markStore.currentTask.hasMarkArea &&
+    !markStore.currentTask.cardData?.length
+  ) {
+    sliceImagesWithTrackList[0].summarys = parseMode4Data();
+  }
 }
 
 // should not render twice at the same time

+ 85 - 32
src/features/track/composables/useTrackTag.ts

@@ -140,6 +140,19 @@ export default function useTrackTag() {
 
   // 解析各试题答题区域
   function parseQuestionAreas(questions: Question[]) {
+    if (!questions.length) return [];
+    let pictureConfigs = [];
+    if (markStore.currentTask.hasMarkAreas) {
+      pictureConfigs = parseMarkQuestionAreas(questions);
+    } else {
+      pictureConfigs = parseCardQuestionAreas(questions);
+    }
+
+    return shrinkQuestionArea(pictureConfigs);
+  }
+
+  // 通过评卷区设置获取试题评卷区
+  function parseMarkQuestionAreas(questions: Question[]) {
     if (!questions.length || !markStore.currentTask?.markAreas?.length)
       return [];
 
@@ -169,7 +182,57 @@ export default function useTrackTag() {
     const combinePictureConfigList: QuestionArea[] =
       combinePictureConfig(pictureConfigs);
     // console.log(combinePictureConfigList);
-    return shrinkQuestionArea(combinePictureConfigList);
+    return combinePictureConfigList;
+  }
+
+  // 通过题卡获取试题评卷区
+  function parseCardQuestionAreas(questions: QuestionItem[]) {
+    if (!questions.length || !markStore.currentTask.cardData?.length) return [];
+
+    const pictureConfigs: QuestionArea[] = [];
+    const structs = questions.map(
+      (item) => `${item.mainNumber}_${item.subNumber}`
+    );
+    markStore.currentTask.cardData.forEach((page, pindex) => {
+      page.exchange.answer_area.forEach((area) => {
+        const [x, y, w, h] = area.area;
+        const qStruct = `${area.main_number}_${area.sub_number}`;
+
+        const pConfig: QuestionArea = {
+          i: pindex + 1,
+          x,
+          y,
+          w,
+          h,
+          qStruct,
+        };
+
+        if (typeof area.sub_number === "number") {
+          if (!structs.includes(qStruct)) return;
+          pictureConfigs.push(pConfig);
+          return;
+        }
+        // 复合区域处理,比如填空题,多个小题合并为一个区域
+        if (typeof area.sub_number === "string") {
+          const areaStructs = area.sub_number
+            .split(",")
+            .map((subNumber) => `${area.main_number}_${subNumber}`);
+          if (
+            structs.some((struct) => areaStructs.includes(struct)) &&
+            !pictureConfigs.find((item) => item.qStruct === qStruct)
+          ) {
+            pictureConfigs.push(pConfig);
+          }
+        }
+      });
+    });
+    // console.log(pictureConfigs);
+
+    // 合并相邻区域
+    const combinePictureConfigList: QuestionArea[] =
+      combinePictureConfig(pictureConfigs);
+    // console.log(combinePictureConfigList);
+    return combinePictureConfigList;
   }
 
   // 缩小区域
@@ -590,44 +653,34 @@ export default function useTrackTag() {
   }
 
   // 模式4的解析
-  function parseMode4Data(): TrackSummaryItem[] {
-    // 只有单评才展示summary
-    const isDoubleMark = (markStore.currentTask.questionList || []).some(
-      (question) => {
-        let userIds = question.markerTrackList.map((track) => track.userId);
-        if (
-          !userIds.length &&
-          question.markerList &&
-          question.markerList.length
-        ) {
-          userIds = question.markerList
-            .filter((marker) => !marker.header)
-            .map((marker) => marker.userId);
-        }
-        const uids = new Set(userIds);
-        return uids.size === 2;
+  function getMode4MarkerName(q: Question): string {
+    let markerName = "";
+    if (q.headerTrackList && q.headerTrackList.length) {
+      const names = new Set(q.headerTrackList.map((item) => item.userName));
+      markerName = Array.from(names).join(",");
+    } else if (q.markerTrackList && q.markerTrackList.length) {
+      const names = new Set(q.markerTrackList.map((item) => item.userName));
+      markerName = Array.from(names).join(",");
+    } else if (q.markerList && q.markerList.length) {
+      let markers = q.markerList.filter((marker) => marker.header);
+      if (!markers.length) {
+        markers = q.markerList.filter((marker) => !marker.header);
       }
-    );
-    if (isDoubleMark) return [];
+      if (markers.length) {
+        const names = new Set(markers.map((item) => item.userName));
+        markerName = Array.from(names).join(",");
+      }
+    }
+    return markerName;
+  }
 
+  function parseMode4Data(): TrackSummaryItem[] {
     return (markStore.currentTask.questionList || []).map((q) => {
-      let markerName = "";
-      if (q.headerTrackList && q.headerTrackList.length) {
-        markerName = q.headerTrackList[0].userName;
-      } else if (q.markerTrackList && q.markerTrackList.length) {
-        markerName = q.markerTrackList[0].userName;
-      } else if (q.markerList && q.markerList.length) {
-        let markers = q.markerList.filter((marker) => marker.header);
-        if (!markers.length) {
-          markers = q.markerList.filter((marker) => !marker.header);
-        }
-        if (markers.length) markerName = markers[0].userName;
-      }
       return {
         mainNumber: q.mainNumber,
         subNumber: q.subNumber,
         score: q.score,
-        markerName,
+        markerName: getMode4MarkerName(q),
       };
     });
   }

+ 1 - 0
src/types/index.ts

@@ -311,6 +311,7 @@ export interface Task extends RawTask {
   recogDatas?: string[];
   cardData?: Array<CardDataItem>;
   markAreas?: MarkArea[];
+  hasMarkArea?: boolean;
 }
 
 interface RawQuestion {