Browse Source

feat: 轨迹颜色调整

zhangjie 1 year ago
parent
commit
539d33df25
2 changed files with 28 additions and 8 deletions
  1. 3 2
      electron/preload/api.ts
  2. 25 6
      src/views/base/track-export/useDraw.ts

+ 3 - 2
electron/preload/api.ts

@@ -64,10 +64,11 @@ function drawTrack(
         const { x, y, text, color, fontSize } =
           track.option as DrawTrackTextOption;
         const fsize = fontSize || defaultFontSize;
+        const textColor = color || defaultColor;
         const ny = y + fsize;
         gmObj
-          .stroke(defaultColor, 1)
-          .fill(color || defaultColor)
+          .stroke(textColor, 1)
+          .fill(textColor)
           .fontSize(fsize)
           .drawText(x, ny, text);
         return;

+ 25 - 6
src/views/base/track-export/useDraw.ts

@@ -71,6 +71,7 @@ type UserMapType = Record<
   {
     userId: string;
     userName: string;
+    color: string;
     scores: Array<{ subNumber: string; score: number }>;
   }
 >;
@@ -342,14 +343,18 @@ export default function useDraw(winId: number) {
   }
 
   // track ----- start->
+  const trackTextFontSize = 30;
+  const trackInfoFontSize = 20;
+  const trackInfoLineHeight = 20 * 1.2;
   function getDrawTrackItem(track: Track): DrawTrackItem {
     return {
       type: 'text',
       option: {
         x: track.offsetX,
-        y: track.offsetY,
+        y: track.offsetY - trackTextFontSize / 2,
         text: String(track.score),
         color: track.color,
+        fontSize: trackTextFontSize,
       },
     };
   }
@@ -392,9 +397,10 @@ export default function useDraw(winId: number) {
       type: 'text',
       option: {
         x: track.offsetX,
-        y: track.offsetY,
+        y: track.offsetY - trackTextFontSize / 2,
         text: track.tagName,
         color: track.color,
+        fontSize: trackTextFontSize,
       },
     };
   }
@@ -511,6 +517,7 @@ export default function useDraw(winId: number) {
             userMap[track.userId] = {
               userId: track.userId,
               userName: track.userName,
+              color: track.color || '',
               scores: [],
             };
           }
@@ -522,7 +529,7 @@ export default function useDraw(winId: number) {
       });
 
       // 填空题的打分需要自动换行,目前一行只展示最多7个评分
-      let offsetY = -20;
+      let offsetY = -1 * trackInfoLineHeight;
       Object.values(userMap).forEach((user, index) => {
         const zhs = ['一', '二', '三'];
         const prename = isDoubleMark ? `${zhs[index] || ''}评` : '评卷员';
@@ -541,13 +548,15 @@ export default function useDraw(winId: number) {
           );
         }
 
-        offsetY += 20;
+        offsetY += trackInfoLineHeight;
         dataArr.push({
           type: 'text',
           option: {
             x: area.x,
             y: area.y + offsetY,
             text: `${prename}:${user.userName},评分:`,
+            fontSize: trackInfoFontSize,
+            color: user.color,
           },
         });
         groups.forEach((group) => {
@@ -558,6 +567,8 @@ export default function useDraw(winId: number) {
               x: area.x,
               y: area.y + offsetY,
               text: group,
+              fontSize: trackInfoFontSize,
+              color: user.color,
             },
           });
         });
@@ -600,6 +611,7 @@ export default function useDraw(winId: number) {
           userMap[track.userId] = {
             userId: track.userId,
             userName: track.userName,
+            color: track.color || '',
             scores: [],
           };
         }
@@ -609,15 +621,21 @@ export default function useDraw(winId: number) {
         });
       });
 
+      const isDoubleMark = Object.values(userMap).length > 1;
       Object.values(userMap).forEach((user, index) => {
+        const zhs = ['一', '二', '三'];
+        const prename = isDoubleMark ? `${zhs[index] || ''}评` : '评卷员';
+
         const userScore = calcSum(user.scores.map((item) => item.score));
-        const content = `评卷员:${user.userName},评分:${userScore}`;
+        const content = `${prename}:${user.userName},评分:${userScore}`;
         dataArr.push({
           type: 'text',
           option: {
             x: area.x,
-            y: area.y + index * 20,
+            y: area.y + index * trackInfoLineHeight,
             text: content,
+            fontSize: trackInfoFontSize,
+            color: user.color,
           },
         });
       });
@@ -647,6 +665,7 @@ export default function useDraw(winId: number) {
         x: 0.15 * image.width,
         y: 0.01 * image.height,
         text: `总分:${totalScore},主观题得分:${subjectiveScore},客观题得分:${objectiveScore}`,
+        fontSize: 40,
       },
     };
   }