|
@@ -6,6 +6,7 @@
|
|
|
width="550px"
|
|
|
:close-on-click-modal="false"
|
|
|
:close-on-press-escape="false"
|
|
|
+ :show-close="false"
|
|
|
append-to-body
|
|
|
@open="visibleChange"
|
|
|
>
|
|
@@ -32,22 +33,33 @@
|
|
|
<span class="color-danger">
|
|
|
{{ realScanCount }}
|
|
|
</span>
|
|
|
+ <i v-if="scanStatus === 'START'" class="el-icon-loading"></i>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
<div slot="footer">
|
|
|
- <el-button v-if="!isScaning" type="primary" @click="startTask"
|
|
|
+ <el-button v-if="scanStatus === 'INIT'" type="primary" @click="startTask"
|
|
|
>开始扫描</el-button
|
|
|
>
|
|
|
- <el-button v-if="isScaning" type="primary" @click="confirm"
|
|
|
+ <el-button
|
|
|
+ v-if="scanStatus === 'PAUSE'"
|
|
|
+ type="primary"
|
|
|
+ @click="continueTask"
|
|
|
+ >继续扫描</el-button
|
|
|
+ >
|
|
|
+ <el-button v-if="scanStatus === 'PAUSE'" type="primary" @click="confirm"
|
|
|
>确认</el-button
|
|
|
>
|
|
|
- <el-button @click="cancel">取消</el-button>
|
|
|
+ <el-button v-if="scanStatus === 'PAUSE'" @click="cancel">取消</el-button>
|
|
|
</div>
|
|
|
</el-dialog>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { getEarliestFile, saveOutputImage } from "../../../plugins/imageOcr";
|
|
|
+import {
|
|
|
+ getPreUploadFilesAutoSerial,
|
|
|
+ getPreUploadFileCount,
|
|
|
+ saveOutputImage
|
|
|
+} from "../../../plugins/imageOcr";
|
|
|
import setTimeMixins from "../../../mixins/setTimeMixins";
|
|
|
import db from "../../../plugins/db";
|
|
|
const fs = require("fs");
|
|
@@ -67,10 +79,9 @@ export default {
|
|
|
return {
|
|
|
modalIsShow: false,
|
|
|
loading: false,
|
|
|
- isScaning: false,
|
|
|
- canScan: true,
|
|
|
+ scanStatus: "INIT", // INIT:初始状态,START:已开始,PAUSE:已暂停
|
|
|
modalForm: {
|
|
|
- preScanCount: 0
|
|
|
+ preScanCount: undefined
|
|
|
},
|
|
|
rules: {
|
|
|
preScanCount: [
|
|
@@ -81,14 +92,11 @@ export default {
|
|
|
}
|
|
|
]
|
|
|
},
|
|
|
- scanList: [],
|
|
|
- scaningImageList: []
|
|
|
+ scaningImageList: [],
|
|
|
+ realScanCount: 0
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
- realScanCount() {
|
|
|
- return this.scanList.length;
|
|
|
- },
|
|
|
user() {
|
|
|
return this.$store.state.user;
|
|
|
}
|
|
@@ -99,15 +107,17 @@ export default {
|
|
|
methods: {
|
|
|
initData() {
|
|
|
this.loading = false;
|
|
|
- this.modalForm.preScanCount = 0;
|
|
|
- this.scanList = [];
|
|
|
- this.isScaning = false;
|
|
|
+ this.modalForm.preScanCount = undefined;
|
|
|
+ this.scaningImageList = [];
|
|
|
+ this.scanStatus = "INIT";
|
|
|
+ this.realScanCount = 0;
|
|
|
},
|
|
|
visibleChange() {
|
|
|
this.initData();
|
|
|
},
|
|
|
close() {
|
|
|
this.modalIsShow = false;
|
|
|
+ this.$emit("on-close");
|
|
|
},
|
|
|
open() {
|
|
|
this.modalIsShow = true;
|
|
@@ -119,12 +129,33 @@ export default {
|
|
|
if (this.loading) return;
|
|
|
this.loading = true;
|
|
|
|
|
|
- this.startScan();
|
|
|
- // TODO:唤起采集程序
|
|
|
+ this.scaningImageList = [];
|
|
|
+ this.scanStatus = "START";
|
|
|
+ this.getInitFile();
|
|
|
+
|
|
|
+ // 唤起采集程序
|
|
|
+ this.evokeScanExe();
|
|
|
+ },
|
|
|
+ async continueTask() {
|
|
|
+ this.scanStatus = "START";
|
|
|
+ this.getInitFile();
|
|
|
+
|
|
|
+ this.evokeScanExe();
|
|
|
+ },
|
|
|
+ evokeScanExe() {
|
|
|
+ console.log("唤起扫描仪");
|
|
|
+ setTimeout(() => {
|
|
|
+ this.scanStatus = "PAUSE";
|
|
|
+ console.log("扫描仪停止");
|
|
|
+ }, 5 * 1000);
|
|
|
},
|
|
|
async confirm() {
|
|
|
- await this.addUploadTask();
|
|
|
- this.pauseScan();
|
|
|
+ this.scaningImageList = getPreUploadFilesAutoSerial(this.GLOBAL.input);
|
|
|
+ if (!this.scaningImageList.length) {
|
|
|
+ this.$message.error("当前没有要保存的数据!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ await this.saveScanImage();
|
|
|
|
|
|
const confirm = await this.$confirm(`是否继续扫描?`, "提示", {
|
|
|
type: "warning"
|
|
@@ -153,61 +184,45 @@ export default {
|
|
|
// scan relate
|
|
|
getInitFile() {
|
|
|
this.clearSetTs();
|
|
|
- if (!this.canScan) return;
|
|
|
-
|
|
|
- const scaningImageList = getEarliestFile(this.GLOBAL.input);
|
|
|
- this.scaningImageList = scaningImageList || [];
|
|
|
+ if (this.scanStatus !== "START") return;
|
|
|
|
|
|
- if (this.scaningImageList.length) {
|
|
|
- this.saveScanImage(this.scaningImageList);
|
|
|
- this.addSetTime(() => {
|
|
|
- this.getInitFile();
|
|
|
- }, 200);
|
|
|
- } else {
|
|
|
- this.addSetTime(() => {
|
|
|
- this.getInitFile();
|
|
|
- }, 1000);
|
|
|
- }
|
|
|
- },
|
|
|
- saveScanImage() {
|
|
|
- const ouputImageList = saveOutputImage(this.scaningImageList);
|
|
|
- this.scanList.push({
|
|
|
- taskId: this.task.id,
|
|
|
- taskName: this.task.name,
|
|
|
- courseCode: this.task.courseCode,
|
|
|
- courseName: this.task.courseName,
|
|
|
- teachingClassName: this.task.teachingClassName,
|
|
|
- frontOriginImgPath: ouputImageList[0],
|
|
|
- versoOriginImgPath: ouputImageList[1],
|
|
|
- clientUserId: this.user.userId,
|
|
|
- clientUsername: this.user.name,
|
|
|
- clientUserLoginTime: this.user.loginTime
|
|
|
- });
|
|
|
- },
|
|
|
- pauseScan() {
|
|
|
- this.canScan = false;
|
|
|
+ this.realScanCount = getPreUploadFileCount(this.GLOBAL.input);
|
|
|
+ this.addSetTime(() => {
|
|
|
+ this.getInitFile();
|
|
|
+ }, 500);
|
|
|
},
|
|
|
- startScan() {
|
|
|
- this.scaningImageList = [];
|
|
|
- this.canScan = true;
|
|
|
- this.isScaning = true;
|
|
|
- this.getInitFile();
|
|
|
- },
|
|
|
- async addUploadTask() {
|
|
|
- // 添加上传任务
|
|
|
- for (let i = 0, len = this.scanList.length; i < len; i++) {
|
|
|
- await db.saveUploadInfo(this.scanList[i]).catch(err => {
|
|
|
+ async saveScanImage() {
|
|
|
+ for (let i = 0, len = this.scaningImageList.length; i < len; i++) {
|
|
|
+ const files = this.scaningImageList[i];
|
|
|
+ const ouputImageList = saveOutputImage([
|
|
|
+ files.frontFile,
|
|
|
+ files.versoFile
|
|
|
+ ]);
|
|
|
+ const fileInfo = {
|
|
|
+ taskId: this.task.id,
|
|
|
+ taskName: this.task.name,
|
|
|
+ courseCode: this.task.courseCode,
|
|
|
+ courseName: this.task.courseName,
|
|
|
+ teachingClassName: this.task.teachingClassName,
|
|
|
+ frontOriginImgPath: ouputImageList[0],
|
|
|
+ versoOriginImgPath: ouputImageList[1],
|
|
|
+ clientUserId: this.user.userId,
|
|
|
+ clientUsername: this.user.name,
|
|
|
+ clientUserLoginTime: this.user.loginTime
|
|
|
+ };
|
|
|
+
|
|
|
+ await db.saveUploadInfo(fileInfo).catch(err => {
|
|
|
console.log(err);
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
clearScanList() {
|
|
|
- for (let i = 0; i < this.scanList.length; i++) {
|
|
|
- const item = this.scanList[i];
|
|
|
- fs.unlinkSync(item.frontOriginImgPath);
|
|
|
- fs.unlinkSync(item.versoOriginImgPath);
|
|
|
+ for (let i = 0; i < this.scaningImageList.length; i++) {
|
|
|
+ const item = this.scaningImageList[i];
|
|
|
+ fs.unlinkSync(item.frontFile);
|
|
|
+ fs.unlinkSync(item.versoFile);
|
|
|
}
|
|
|
- this.scanList = [];
|
|
|
+ this.scaningImageList = [];
|
|
|
}
|
|
|
}
|
|
|
};
|