Browse Source

pdf文件命名修改

刘洋 2 years ago
parent
commit
fe20f45329
3 changed files with 27 additions and 8 deletions
  1. 4 3
      .eslintrc.js
  2. 23 4
      src/features/ImageDownload/ImageDownload.vue
  3. 0 1
      src/plugins/axiosNotice.ts

+ 4 - 3
.eslintrc.js

@@ -16,8 +16,9 @@ module.exports = {
   rules: {
   rules: {
     "no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
     "no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
     "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
     "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
-    '@typescript-eslint/no-explicit-any' : 'off',
-    '@typescript-eslint/no-var-requires' : 'off',
-    "no-var-requires": "off"
+    "@typescript-eslint/no-explicit-any": "off",
+    "@typescript-eslint/no-var-requires": "off",
+    "no-var-requires": "off",
+    "no-console": "off",
   },
   },
 };
 };

+ 23 - 4
src/features/ImageDownload/ImageDownload.vue

@@ -161,7 +161,7 @@ onMounted(async () => {
               // colorMap[groupNumber + ""][tag.userId + ""] = c;
               // colorMap[groupNumber + ""][tag.userId + ""] = c;
             }
             }
           }
           }
-          console.log("colorMap:", colorMap);
+          // console.log("colorMap:", colorMap);
           let resultImgList: any[] = [];
           let resultImgList: any[] = [];
           let sheetUrlsLength = (student.sheetUrls || []).length;
           let sheetUrlsLength = (student.sheetUrls || []).length;
           for (const sheetUrl of student.sheetUrls) {
           for (const sheetUrl of student.sheetUrls) {
@@ -215,7 +215,6 @@ onMounted(async () => {
                 colorMap
                 colorMap
               );
               );
               resultImgList.push(fileLocation);
               resultImgList.push(fileLocation);
-              console.log(resultImgList.length, sheetUrlsLength);
             } catch (error) {
             } catch (error) {
               errorCount.value += 1;
               errorCount.value += 1;
               if (config.failover) {
               if (config.failover) {
@@ -228,11 +227,31 @@ onMounted(async () => {
           }
           }
           // 下载完一个学生
           // 下载完一个学生
           finishedCount.value += 1;
           finishedCount.value += 1;
-          console.log(resultImgList.length, sheetUrlsLength);
           if (resultImgList.length === sheetUrlsLength) {
           if (resultImgList.length === sheetUrlsLength) {
+            let imgName = "";
+            if (config.template.lastIndexOf("/") > -1) {
+              imgName = config.template.slice(
+                config.template.lastIndexOf("/") + 1
+              );
+            } else {
+              imgName = config.template;
+            }
+            let n = imgName.slice(0, imgName.lastIndexOf("."));
+            let pdfName = n
+              .match(/{{.*?}}/g)
+              ?.map((item: any) => {
+                return item.replace("{{", "").replace("}}", "");
+              })
+              .filter((v) => !!v)
+              .map((item: any) => {
+                return item === "index" ? "" : student[item];
+              })
+              .filter((v) => !!v)
+              .join("-");
+
             window.electron.saveToPDF(resultImgList, [
             window.electron.saveToPDF(resultImgList, [
               config.dir,
               config.dir,
-              `/pdfs/${store.env.examId}/${student.subjectCode}/${student.examNumber}.pdf`,
+              `/pdfs/${store.env.examId}/${student.subjectCode}/${pdfName}.pdf`,
             ]);
             ]);
           }
           }
         }
         }

+ 0 - 1
src/plugins/axiosNotice.ts

@@ -1,4 +1,3 @@
-import Vue from "vue";
 import { throttle } from "lodash";
 import { throttle } from "lodash";
 import { message } from "ant-design-vue";
 import { message } from "ant-design-vue";
 // import { doLogout } from "@/api/markPage";
 // import { doLogout } from "@/api/markPage";