Browse Source

接口调试

zhangjie 2 years ago
parent
commit
5a564554f5

+ 2 - 0
.gitignore

@@ -2,6 +2,8 @@
 node_modules*
 /dist*
 modules-old*
+stores
+logs
 
 # local env files
 .env.local

+ 0 - 0
logs/scan.log


+ 3 - 3
package.json

@@ -3,14 +3,14 @@
   "version": "1.0.1",
   "description": "paper-library client",
   "scripts": {
-    "start": "yarn run e:serve",
+    "start": "npm run e:serve",
     "serve": "vue-cli-service serve",
     "build": "vue-cli-service build",
     "lint": "vue-cli-service lint",
     "win:build": "vue-cli-service electron:build",
     "e:build": "vue-cli-service electron:build --win --x64 --ia32",
     "e:serve": "vue-cli-service electron:serve",
-    "postinstall": "electron-builder install-app-deps",
+    "postinstall": "electron-builder install-app-deps --arch=x64",
     "postuninstall": "electron-builder install-app-deps"
   },
   "main": "background.js",
@@ -61,4 +61,4 @@
       "git add"
     ]
   }
-}
+}

+ 62 - 6
src/assets/styles/pages.scss

@@ -1,8 +1,9 @@
-.task-manage{
+.task-manage {
   padding: 20px;
 }
-.scan-task-dialog{
-  .scan-head-btn{
+
+.scan-task-dialog {
+  .scan-head-btn {
     position: absolute;
     top: 10px;
     right: 20px;
@@ -12,6 +13,19 @@
   }
 }
 
+// ocr-area-dialog
+.ocr-area-dialog {
+  .el-dialog__header {
+    display: none;
+  }
+
+  .el-dialog__body {
+    position: relative;
+    height: 100%;
+    padding: 0 !important;
+  }
+}
+
 
 
 /* ocr-area */
@@ -19,6 +33,27 @@
   height: 100%;
   position: relative;
 
+  &-head {
+    position: absolute;
+    height: 50px;
+    top: 0;
+    left: 0;
+    width: 100%;
+    z-index: 9;
+    padding: 0 15px;
+    display: flex;
+    justify-content: space-between;
+    align-items: center;
+  }
+
+  &-body {
+    position: absolute;
+    left: 0;
+    right: 0;
+    bottom: 0;
+    top: 50px;
+  }
+
   &-cont {
     position: absolute;
     top: 0;
@@ -26,6 +61,7 @@
     right: 300px;
     bottom: 0;
     overflow: hidden;
+
     &-disabled::before {
       content: "";
       display: block;
@@ -36,15 +72,18 @@
       left: 0;
       z-index: 99;
     }
-    &-disabled .cropper-container > .cropper-modal,
-    &-disabled .cropper-container > .cropper-crop-box {
+
+    &-disabled .cropper-container>.cropper-modal,
+    &-disabled .cropper-container>.cropper-crop-box {
       display: none;
     }
   }
+
   &-cont img {
     display: block;
     width: 100%;
   }
+
   &-side {
     position: absolute;
     width: 300px;
@@ -63,6 +102,7 @@
     background-color: $--color-text-gray-5;
     padding: 10px;
   }
+
   &-preview {
     position: absolute;
     width: 300px;
@@ -70,10 +110,12 @@
     right: 0;
     transform: translateY(-50%);
   }
+
   &-spin {
     height: 300px;
     position: relative;
   }
+
   &-spin-img {
     position: absolute;
     width: 300px;
@@ -84,6 +126,7 @@
     overflow: hidden;
     box-shadow: 0 0 10px rgba(4, 5, 17, 0.3);
   }
+
   &-icon {
     margin: 20px auto 0;
     text-align: center;
@@ -105,27 +148,32 @@
   &-modal {
     opacity: 0.7;
   }
+
   &-line {
     background-color: $--color-cyan;
     opacity: 1;
+
     &.line-e {
       right: -2px;
       top: 3px;
       bottom: 3px;
       width: 2px;
     }
+
     &.line-n {
       height: 2px;
       top: -2px;
       left: 3px;
       right: 3px;
     }
+
     &.line-w {
       left: -2px;
       top: 3px;
       bottom: 3px;
       width: 2px;
     }
+
     &.line-s {
       height: 2px;
       bottom: -2px;
@@ -133,6 +181,7 @@
       right: 3px;
     }
   }
+
   &-point {
     background-color: rgba(51, 51, 51, 0.7);
     border: 2px solid $--color-cyan;
@@ -145,33 +194,40 @@
       margin-top: -5px;
       right: -6px;
     }
+
     &.point-w {
       margin-top: -5px;
       left: -6px;
     }
+
     &.point-n {
       margin-left: -5px;
       top: -6px;
     }
+
     &.point-s {
       margin-left: -5px;
       bottom: -6px;
     }
+
     &.point-ne {
       top: -6px;
       right: -6px;
     }
+
     &.point-nw {
       top: -6px;
       left: -6px;
     }
+
     &.point-sw {
       bottom: -6px;
       left: -6px;
     }
+
     &.point-se {
       bottom: -6px;
       right: -6px;
     }
   }
-}
+}

+ 17 - 0
src/background.js

@@ -121,6 +121,7 @@ app.on("ready", async () => {
   }
 
   createWindow();
+  registerLocalResourceProtocol();
 });
 
 // Exit cleanly on request from parent process in development mode.
@@ -137,3 +138,19 @@ if (isDevelopment) {
     });
   }
 }
+
+function registerLocalResourceProtocol() {
+  protocol.registerFileProtocol("file", (request, callback) => {
+    const url = request.url.replace(/^file:\/\//, "");
+    // Decode URL to prevent errors when loading filenames with UTF-8 chars or chars like "#"
+    const decodedUrl = decodeURI(url); // Needed in case URL contains spaces
+    try {
+      return callback(decodedUrl);
+    } catch (error) {
+      console.error(
+        "ERROR: registerLocalResourceProtocol: Could not get file path:",
+        error
+      );
+    }
+  });
+}

+ 2 - 2
src/components/base/CourseSelect.vue

@@ -10,8 +10,8 @@
   >
     <el-option
       v-for="item in optionList"
-      :key="item.id"
-      :value="item.id"
+      :key="item.code"
+      :value="item.code"
       :label="item.name"
     >
     </el-option>

+ 2 - 2
src/components/base/TeachClazzSelect.vue

@@ -51,7 +51,7 @@ export default {
         this.selected = val;
       }
     },
-    "filterData.courseName": {
+    "filterData.courseCode": {
       handler(val, oldval) {
         console.log(val);
         if (val !== oldval) {
@@ -68,7 +68,7 @@ export default {
   methods: {
     async search() {
       this.optionList = [];
-      if (!this.filterData.courseName) return;
+      if (!this.filterData.courseCode) return;
       const res = await commonTeachClazzQuery({
         ...this.filterData
       });

+ 11 - 4
src/modules/client/components/OcrAreaSetDialog.vue

@@ -2,19 +2,19 @@
   <el-dialog
     class="ocr-area-dialog"
     :visible.sync="modalIsShow"
-    top="10vh"
-    width="550px"
+    fullscreen
     :close-on-click-modal="false"
     :close-on-press-escape="false"
     :show-close="false"
     append-to-body
     @opened="dialogOpened"
+    @closed="dialogClosed"
   >
     <div class="ocr-area-head">
       <h3>条码识别区设置</h3>
       <div>
         <el-button type="primary" @click="confirm">确认</el-button>
-        <el-button @click="cancel">取消</el-button>
+        <el-button @click="close">取消</el-button>
       </div>
     </div>
 
@@ -77,11 +77,12 @@ export default {
       this.ocrArea = ocrArea ? JSON.parse(ocrArea) : {};
 
       const res = getPreUploadFiles(this.GLOBAL.input);
+      console.log(res);
       if (!res.succeed) {
         this.$message.error(res.errorMsg);
         return;
       }
-      this.curImageUrl = res.data[0];
+      this.curImageUrl = "file:///" + res.data[0].frontFile;
     },
     initCropper() {
       const _this = this;
@@ -123,6 +124,12 @@ export default {
       this.$store.commit("client/setOcrArea", ocrArea);
       this.$emit("modified", ocrArea);
       this.close();
+    },
+    dialogClosed() {
+      if (this.cropper) {
+        this.cropper.destroy();
+        this.cropper = false;
+      }
     }
   },
   beforeDestroy() {

+ 9 - 5
src/modules/client/components/ScanTaskProcessDialog.vue

@@ -117,8 +117,8 @@ export default {
   },
   computed: {
     ...mapState("client", ["ocrArea"]),
-    openScan() {
-      return this.$store.state.user.openScan;
+    openBarCode() {
+      return this.$store.state.user.openBarCode;
     },
     taskBound() {
       return this.user.id === this.taskScanUserId;
@@ -270,7 +270,7 @@ export default {
           taskName: this.task.scanTaskName,
           courseCode: "",
           courseName: this.task.courseName,
-          teachingClassName: this.task.teachClazzName,
+          teachingClassName: "1",
           frontOriginImgPath: ouputImageList[0],
           versoOriginImgPath: ouputImageList[1],
           examNumber: "",
@@ -279,11 +279,15 @@ export default {
           clientUserLoginTime: this.user.loginTime
         };
 
-        if (this.openScan) {
-          const num = await decodeImageCode(ouputImageList[0]).catch(err => {
+        if (this.openBarCode) {
+          const num = await decodeImageCode(
+            ouputImageList[0],
+            this.ocrArea
+          ).catch(err => {
             console.error(err);
             logger.error(`04-2条码解析失败,${err}`);
           });
+          console.log(num);
           fileInfo.examNumber = num || "";
         }
 

+ 13 - 21
src/modules/client/views/TaskManage.vue

@@ -11,23 +11,15 @@
         </el-form-item>
         <el-form-item label="课程:">
           <course-select
-            v-model="filter.courseName"
+            v-model="filter.courseCode"
             :filter-data="filter"
             placeholder="请选择课程"
           >
           </course-select>
         </el-form-item>
-        <el-form-item label="教学班:">
-          <teach-clazz-select
-            v-model="filter.teachClazzName"
-            placeholder="请选择教学班"
-            :filter-data="filter"
-          >
-          </teach-clazz-select>
-        </el-form-item>
         <el-form-item label-width="0px">
           <el-button type="primary" @click="search">查询</el-button>
-          <el-button v-if="openScan" type="primary" @click="search"
+          <el-button v-if="openBarCode" type="primary" @click="toSetOrcArea"
             >设置条码识别区</el-button
           >
         </el-form-item>
@@ -58,12 +50,10 @@
           min-width="160"
         ></el-table-column>
         <el-table-column prop="courseName" label="课程" min-width="200">
+          <span slot-scope="scope">
+            {{ scope.row.courseName }}({{ scope.row.courseCode }})
+          </span>
         </el-table-column>
-        <el-table-column
-          prop="teachClazzName"
-          label="教学班"
-          min-width="100"
-        ></el-table-column>
         <el-table-column
           prop="studentCount"
           label="学生数"
@@ -131,7 +121,7 @@
     ></scan-task-process-dialog>
     <!-- OcrAreaSetDialog -->
     <ocr-area-set-dialog
-      v-if="openScan"
+      v-if="openBarCode"
       ref="OcrAreaSetDialog"
       @modified="getOcrArea"
     >
@@ -171,8 +161,7 @@ export default {
       },
       filter: {
         paperArchivesId: "",
-        courseName: "",
-        teachClazzName: "",
+        courseCode: "",
         isMine: false
       },
       current: 1,
@@ -187,8 +176,8 @@ export default {
     };
   },
   computed: {
-    openScan() {
-      return this.$store.state.user.openScan;
+    openBarCode() {
+      return this.$store.state.user.openBarCode;
     }
   },
   mounted() {
@@ -246,13 +235,16 @@ export default {
     },
     toScan(row) {
       if (row.enable) return;
-      if (this.openScan && !this.ocrArea) {
+      if (this.openBarCode && !this.ocrArea) {
         this.$message.error("请先设置条形码识别区!");
         return;
       }
       this.curRow = row;
       this.$refs.ScanTaskProcessDialog.open();
     },
+    toSetOrcArea() {
+      this.$refs.OcrAreaSetDialog.open();
+    },
     async toEnable(row) {
       await enableScanTask({
         paperScanTaskId: row.id,

+ 8 - 1
src/plugins/env.js

@@ -1,5 +1,6 @@
 const path = window.nodeRequire("path");
 const fs = window.nodeRequire("fs");
+const process = window.nodeRequire('process')
 const homePath = path.dirname(process.execPath);
 const storePath = path.join(homePath, "stores");
 const extraPath =
@@ -7,7 +8,6 @@ const extraPath =
     ? path.join(homePath, "extra")
     : path.join(__static, "../extra");
 
-initPath();
 function initPath() {
   const paths = [
     storePath,
@@ -16,16 +16,22 @@ function initPath() {
     getOutputDir("origin"),
     getTmpDir(),
   ];
+  console.log(paths);
   paths.forEach(path => {
     if (!fs.existsSync(path)) fs.mkdirSync(path);
   });
 }
+initPath();
+
 // base
 function getHomeDir(name) {
+  const homePath = path.dirname(process.execPath);
   return path.join(homePath, name);
 }
 
 function getStoresDir(name) {
+  const homePath = path.dirname(process.execPath);
+  const storePath = path.join(homePath, "stores");
   return path.join(storePath, name);
 }
 
@@ -84,6 +90,7 @@ function initConfigData(data) {
   if (!configData.input) configData.input = getInputDir();
 
   if (process.env.NODE_ENV === "development") return configData;
+  const homePath = path.dirname(process.execPath);
 
   const configPath = path.join(homePath, "config.json");
   if (fs.existsSync(configPath)) {

+ 1 - 1
src/plugins/imageOcr.js

@@ -181,7 +181,7 @@ export function decodeImageCode(imgPath, codeArea) {
   // 裁剪条形码区域
   imgObj.crop(codeArea.width, codeArea.height, codeArea.x, codeArea.y);
   // 旋转
-  const rotate = parseInt(codeArea.codeRotate);
+  const rotate = parseInt(codeArea.rotate);
   if (rotate) imgObj.rotate("#FFFFFF", rotate);
 
   return new Promise((resolve, reject) => {

+ 1 - 1
src/plugins/imageUpload.js

@@ -24,7 +24,7 @@ function toUploadImg(options) {
   formData.append("versoFile", versoFile);
 
   formData.append("paperScanTaskId", options.taskId);
-  formData.append("examNumber", options.examNumber);
+  formData.append("studentCode", options.examNumber);
 
   return uploadFormalImage(formData);
 }

+ 1 - 0
src/plugins/scanner.js

@@ -13,4 +13,5 @@ export function evokeScanner(inputDir) {
   const commandStr = `${getScanExePath()} -scan -d${inputDir}`;
   // console.log(commandStr);
   return childProcessExec(commandStr);
+  // return Promise.resolve({ succeed: true });
 }

+ 9 - 5
vue.config.js

@@ -9,11 +9,15 @@ var config = {
     electronBuilder: {
       externals: [],
       builderOptions: {
-        extraFiles: [
-          "extra/scan/**",
-          "extra/database/org.rdb",
-          "config.sample.json"
-        ],
+        // extraFiles: [
+        //   "extra/scan/**",
+        //   "extra/database/org.rdb",
+        //   "config.sample.json",
+        //   "extra/imagemagick/**",
+        //   "extra/zxing/**",
+        //   "extra/zxingA/**",
+        // ],
+        extraFiles: ["extra/**"],
         win: {
           target: "portable",
           signAndEditExecutable: false