Selaa lähdekoodia

卡格式dpi逻辑

刘洋 8 kuukautta sitten
vanhempi
commit
a757b87692
1 muutettua tiedostoa jossa 29 lisäystä ja 18 poistoa
  1. 29 18
      src/render/views/BaseDataConfig/ImportCardDialog.vue

+ 29 - 18
src/render/views/BaseDataConfig/ImportCardDialog.vue

@@ -40,7 +40,7 @@ const params = reactive({
   file: null,
   paperCount: void 0,
   singlePage: false,
-  // dpi: 150,
+  dpi: 150,
 });
 const cardJson = ref(null);
 const fields = computed(() => {
@@ -80,27 +80,27 @@ const fields = computed(() => {
         ],
       },
     },
-    // params.file && isJson.value && cardJson.value && !cardJson.value.dpi
-    //   ? {
-    //       prop: "dpi",
-    //       type: "radio",
-    //       label: "DPI",
-    //       colSpan: 24,
-    //       attrs: {
-    //         options: [
-    //           { value: 150, label: "150" },
-    //           { value: 200, label: "200" },
-    //         ],
-    //         disabled: cardJson.value?.dpi,
-    //       },
-    //     }
-    //   : null,
+    params.file && isJson.value && cardJson.value && !cardJson.value.dpi
+      ? {
+          prop: "dpi",
+          type: "radio",
+          label: "DPI",
+          colSpan: 24,
+          attrs: {
+            options: [
+              { value: 150, label: "150" },
+              { value: 200, label: "200" },
+            ],
+            disabled: cardJson.value?.dpi,
+          },
+        }
+      : null,
   ];
 });
 const isJson = ref(true);
 const cardSizePass = ref(true);
 
-const isJsonString = (str) => {
+const isJsonString = (str: string) => {
   try {
     const toObj = JSON.parse(str);
     if (toObj && typeof toObj === "object") {
@@ -148,18 +148,29 @@ const rules = {
     },
   ],
 };
+let pageSizeStr = "";
 const compareSize = (content: any, img: any) => {
+  let target = content[pageSizeStr];
   console.log(content, img.width, img.height);
+  let w = img.width / params.dpi / 0.0394;
+  let h = img.height / params.dpi / 0.0394;
+  if (Math.abs(w - target.width) > 10 || Math.abs(h - target.height) > 10) {
+    cardSizePass.value = false;
+  } else {
+    cardSizePass.value = true;
+  }
 };
-const validateCardSize = async (json) => {
+const validateCardSize = async (json: any) => {
   if (!json.pages.length) {
     cardSizePass.value = false;
+    window.$message.error("卡格式文件里的pages为空");
     return;
   }
   window.electronApi?.getPageSizeIni((content: any) => {
     console.log(content);
     const img = new Image();
     img.onload = () => {
+      pageSizeStr = json.pages[0].exchange["page_size"];
       compareSize(content, img);
     };
     img.onerror = function () {