瀏覽代碼

Merge branch 'release_1.3.0' of http://git.qmth.com.cn/markingcloud/stmms-proxy into release_1.3.1_pdf_without_double

刘洋 1 年之前
父節點
當前提交
73ed87661b
共有 2 個文件被更改,包括 23 次插入26 次删除
  1. 6 6
      src/api/api.ts
  2. 17 20
      src/lib/watermark.ts

+ 6 - 6
src/api/api.ts

@@ -1,10 +1,10 @@
 import { httpApp } from "@/plugins/axiosApp";
 
-export function login() {
+export function login(): any {
   return httpApp.get("/api/user/login");
 }
 
-export function getExams(pageNumber: number, pageSize: number) {
+export function getExams(pageNumber: number, pageSize: number): any {
   return httpApp.get(
     "/api/exams?" +
       new URLSearchParams({
@@ -19,8 +19,8 @@ export function getStudents(
   pageNumber: number,
   pageSize: number,
   params: any
-) {
-  const form:any = {
+): any {
+  const form: any = {
     examId: examId,
     pageNumber: pageNumber,
     pageSize: pageSize,
@@ -35,13 +35,13 @@ export function getStudents(
   return httpApp.post("/api/exam/students", new URLSearchParams(form));
 }
 
-export function countStudents(examId: number, params:any) {
+export function countStudents(examId: number, params: any) {
   params = params || {};
   params.examId = examId;
   return httpApp.post("/api/exam/students/count", new URLSearchParams(params));
 }
 
-export function getPackages(examId:number, upload:any, withUrl:any) {
+export function getPackages(examId: number, upload: any, withUrl: any) {
   let uri = "/api/package/count/" + examId;
   const param = [];
   if (upload != undefined) {

+ 17 - 20
src/lib/watermark.ts

@@ -62,6 +62,11 @@ export async function addWatermark(
   // const size = sizeOf(image);
   // console.log(size);
   const imgData = gm(image);
+  const drawText = (l: number, t: number, content: string) => {
+    const top = t < 30 ? 30 : t > imageHeight ? imageHeight : t;
+    const left = l > imageWidth - 30 ? imageWidth - 30 : l;
+    imgData.drawText(left, top + 30, content);
+  };
   //添加第一页的得分明细
   if (index == 1) {
     //初始坐标
@@ -77,10 +82,10 @@ export async function addWatermark(
       (parseFloat(student.subjectiveScore) || 0);
     //显示总分明细
     imgData.font(fontFile, fontSize).fill(color);
-    imgData.drawText(x, (y += height), "成绩明细");
+    drawText(x, (y += height), "成绩明细");
     //普通考试模式,按客观+主观模式显示总分
     if (trackMode === "1") {
-      imgData.drawText(
+      drawText(
         x,
         (y += height),
         "总分=(客观+主观) | " +
@@ -93,7 +98,7 @@ export async function addWatermark(
     }
     //研究生考试模式,只显示总分
     else if (trackMode === "2") {
-      imgData.drawText(x, (y += height), "总分=" + totalScore + "分");
+      drawText(x, (y += height), "总分=" + totalScore + "分");
     }
     //显示客观题明细
     if (
@@ -127,20 +132,12 @@ export async function addWatermark(
         //   y = startY;
         //   x += width;
         // }
-        imgData.drawText(
-          x,
-          (y += height),
-          "客观题识别结果 | " + lines[l].join(";")
-        );
+        drawText(x, (y += height), "客观题识别结果 | " + lines[l].join(";"));
       }
     }
     //显示复核人
     if (student.inspector) {
-      imgData.drawText(
-        x,
-        (y += height),
-        "复核人: " + student.inspector.loginName
-      );
+      drawText(x, (y += height), "复核人: " + student.inspector.loginName);
     }
     //显示主观题明细
     if (
@@ -152,14 +149,14 @@ export async function addWatermark(
         const title = "主观题号 | 分数 | 评卷员 | 仲裁员";
         const startY = y;
         let width = title.length * fontSize;
-        imgData.drawText(x, (y += height), title);
+        drawText(x, (y += height), title);
         for (let i = 0; i < student.subjectiveScoreDetail.length; i++) {
           const detail = student.subjectiveScoreDetail[i];
           //超过最大高度了则另起一列
           if (y + height + 15 > imageHeight) {
             y = startY;
             x += width;
-            imgData.drawText(x, (y += height), title);
+            drawText(x, (y += height), title);
           }
           const content =
             detail.mainNumber +
@@ -172,7 +169,7 @@ export async function addWatermark(
             " " +
             (detail.header || "");
           width = Math.max(width, content.length * fontSize);
-          imgData.drawText(x, (y += height), content);
+          drawText(x, (y += height), content);
         }
       }
       //研究生考试模式,按分组显示明细
@@ -180,7 +177,7 @@ export async function addWatermark(
         const title = "评卷分组 | 总分 | 评卷员";
         const startY = y;
         let width = title.length * fontSize;
-        imgData.drawText(x, (y += height), title);
+        drawText(x, (y += height), title);
         //所有小题得分按评卷分组聚合
         let maxGroupNumber = 0;
         const groups = {};
@@ -222,7 +219,7 @@ export async function addWatermark(
             if (y + height + 15 > imageHeight) {
               y = startY;
               x += width;
-              imgData.drawText(x, (y += height), title);
+              drawText(x, (y += height), title);
             }
             const content =
               group.number +
@@ -236,7 +233,7 @@ export async function addWatermark(
               " " +
               " "; //+group.headerString.join(",");
             width = Math.max(width, content.length * fontSize);
-            imgData.drawText(x, (y += height), content);
+            drawText(x, (y += height), content);
           }
         }
       }
@@ -265,7 +262,7 @@ export async function addWatermark(
           .font(fontFile, fontSize)
           .fill(colorMap[tag.groupNumber + ""][tag.userId + ""] || "gray");
         for (let j = 0; j < tag.content.length; j++) {
-          imgData.drawText(tag.left, top, tag.content[j]);
+          drawText(tag.left, top, tag.content[j]);
           top += height;
         }
       }