Browse Source

采集流程完毕

zhangjie 2 years ago
parent
commit
720f631f3f

BIN
extra/scan/scan.exe


+ 16 - 6
src/modules/client/components/ScanTaskProcessDialog.vue

@@ -65,10 +65,12 @@
 </template>
 
 <script>
+import { bingScanUser } from "../api";
 import {
   getPreUploadFiles,
   getPreUploadFileCount,
   saveOutputImage,
+  renamePreUploadJsonFile,
   clearDir
 } from "../../../plugins/imageOcr";
 import setTimeMixins from "../../../mixins/setTimeMixins";
@@ -90,6 +92,7 @@ export default {
     return {
       modalIsShow: false,
       loading: false,
+      user: this.$ls.get("user", { id: "" }),
       scanStatus: "INIT", // INIT:初始状态,START:已开始,PAUSE:已暂停
       modalForm: {
         preScanCount: 0
@@ -108,8 +111,8 @@ export default {
     };
   },
   computed: {
-    user() {
-      return this.$store.state.user;
+    taskBound() {
+      return this.user.id === this.task.scanUserId;
     }
   },
   beforeDestroy() {
@@ -150,6 +153,13 @@ export default {
       if (this.loading) return;
       this.loading = true;
 
+      if (!this.taskBound) {
+        await bingScanUser({
+          paperScanTaskId: this.task.id,
+          userId: this.user.id
+        });
+      }
+
       this.scaningImageList = [];
       this.scanStatus = "START";
       this.getInitFile();
@@ -166,7 +176,7 @@ export default {
       console.log("唤起扫描仪");
       // console.log(commandStr);
       await evokeScanner(this.GLOBAL.input).catch(error => {
-        console.dir(error);
+        console.error(error);
       });
       console.log("扫描仪停止");
       this.scanStatus = "PAUSE";
@@ -178,8 +188,8 @@ export default {
         return;
       }
       this.scaningImageList.push(...res.data);
-
-      console.log(this.scaningImageList);
+      // console.log(this.scaningImageList);
+      renamePreUploadJsonFile(this.GLOBAL.input);
     },
     async confirm() {
       if (!this.scaningImageList.length) {
@@ -246,7 +256,7 @@ export default {
         };
 
         await db.saveUploadInfo(fileInfo).catch(err => {
-          console.log(err);
+          console.error(err);
         });
       }
     },

+ 16 - 1
src/plugins/imageOcr.js

@@ -98,7 +98,7 @@ export function getPreUploadFiles(dir) {
   let imageList = [];
   if (!files.length) return { succeed: false, errorMsg: "当前无扫描文件!" };
 
-  const fileCont = fs.readFileSync(path.join(dir, files[0]));
+  const fileCont = fs.readFileSync(path.join(ddir, files[0]));
   const fileInfo = JSON.parse(fileCont);
 
   if (!fileInfo.succeed) {
@@ -117,6 +117,21 @@ export function getPreUploadFiles(dir) {
   return { succeed: true, data: imageList };
 }
 
+export function renamePreUploadJsonFile(dir) {
+  const ddir = dir || getInputDir();
+  const files = fs
+    .readdirSync(ddir)
+    .filter(fileName => fileName.toLowerCase().match(/\.(json)/));
+  if (!files.length) return;
+
+  files.forEach(file => {
+    fs.renameSync(
+      path.join(ddir, file),
+      path.join(ddir, path.basename(file, ".json") + ".txt")
+    );
+  });
+}
+
 /**
 扫描仪返回的数据
 {