Forráskód Böngészése

新增清楚任务数据按钮

zhangjie 2 éve
szülő
commit
0a01d401f1

+ 1 - 1
src/modules/client/components/ScanTaskProcessDialog.vue

@@ -227,9 +227,9 @@ export default {
       logger.info(`04-1开始保存数据`);
       let res = true;
       await this.saveScanImage().catch(() => {
-        this.submiting = false;
         res = false;
       });
+      this.submiting = false;
       logger.info(`04-2保存数据结束`);
       if (!res) {
         this.$message.error("保存数据错误!");

+ 40 - 10
src/modules/client/views/TaskManage.vue

@@ -64,19 +64,16 @@
           label="学生数"
           min-width="100"
         ></el-table-column>
-        <el-table-column
-          prop="studentCount"
-          label="实扫/已上传(采集)"
-          min-width="100"
-        >
+        <el-table-column label="实扫/已上传(采集)" width="100" align="center">
           <span slot-scope="scope">
-            {{ scope.row.scanCount }} / {{ scope.row.uploadCount }}
+            {{ scope.row.clientScanCount }} / {{ scope.row.clientUploadCount }}
           </span>
         </el-table-column>
         <el-table-column
           prop="scanCount"
           label="已上传(后台)"
-          min-width="100"
+          width="80"
+          align="center"
         ></el-table-column>
         <el-table-column
           v-if="curTab === 'my'"
@@ -99,7 +96,7 @@
         <el-table-column
           class-name="action-column"
           label="操作"
-          width="80"
+          width="100"
           fixed="right"
         >
           <template slot-scope="scope">
@@ -111,6 +108,14 @@
             >
               扫描
             </el-button>
+            <el-button
+              v-if="scope.row.scanCount && scope.row.clientScanCount"
+              class="btn-danger"
+              type="text"
+              @click="toClean(scope.row)"
+            >
+              清除
+            </el-button>
           </template>
         </el-table-column>
       </el-table>
@@ -148,6 +153,7 @@ import db from "../../../plugins/db";
 import { taskListPage, enableScanTask } from "../api";
 import ScanTaskProcessDialog from "../components/ScanTaskProcessDialog.vue";
 import OcrAreaSetDialog from "../components/OcrAreaSetDialog.vue";
+import { clearTaskOriginDir } from "../../../plugins/imageOcr";
 // import ScanTaskProcessDialog from "../components/ScanTaskDialog.vue";
 
 export default {
@@ -234,12 +240,12 @@ export default {
       for (let i = 0; i < this.dataList.length; i++) {
         const task = this.dataList[i];
         const scanCount = await db.countScanList({ taskId: task.id });
-        this.$set(task, "scanCount", scanCount);
+        this.$set(task, "clientScanCount", scanCount);
         const uploadCount = await db.countScanList({
           taskId: task.id,
           isUpload: 1
         });
-        this.$set(task, "uploadCount", uploadCount);
+        this.$set(task, "clientUploadCount", uploadCount);
       }
     },
     selectMenu(curTab) {
@@ -278,6 +284,30 @@ export default {
         enable: !row.enable
       });
       row.enable = !row.enable;
+    },
+    async toClean(row) {
+      if (!row.clientScanCount || !row.scanCount) return;
+
+      this.$parent.$parent.stopUpload();
+
+      const res = await db.deleteScanByTaskId(row.id).catch(err => {
+        console.error(err);
+      });
+      if (!res) {
+        this.$message.error("本地数据删除错误!");
+        this.$parent.$parent.initUploadTask();
+        return;
+      }
+
+      try {
+        clearTaskOriginDir(row.id);
+      } catch (error) {
+        console.error(error);
+        this.$message.error("本地文件删除错误!");
+      }
+      this.$parent.$parent.initUploadTask();
+
+      this.getList();
     }
   }
 };

+ 3 - 3
src/plugins/db.js

@@ -141,8 +141,8 @@ function updateUploadState(id) {
   });
 }
 
-function deleteScanById(id) {
-  const sql = `DELETE FROM scan WHERE id=$id`;
+function deleteScanByTaskId(id) {
+  const sql = `DELETE FROM scan WHERE taskId=$id`;
   const datas = {
     $id: id
   };
@@ -214,7 +214,7 @@ export default {
   countScanList,
   getUploadCount,
   updateUploadState,
-  deleteScanById,
+  deleteScanByTaskId,
   // dict
   getDict,
   setDict,

+ 6 - 0
src/plugins/imageOcr.js

@@ -102,6 +102,12 @@ export function clearDir(dir) {
   });
 }
 
+export function clearTaskOriginDir(taskId) {
+  const outputDir = path.join(getOutputDir("origin"), taskId + "");
+  if (!fs.existsSync(outputDir)) return;
+  clearDir(outputDir);
+}
+
 export function getPreUploadFiles(dir) {
   const ddir = dir || getInputDir();
   const files = fs