|
@@ -1,7 +1,7 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
<el-dialog
|
|
|
- class="scan-task-dialog"
|
|
|
+ class="scan-task-dialog page-dialog"
|
|
|
:visible.sync="modalIsShow"
|
|
|
fullscreen
|
|
|
:close-on-click-modal="false"
|
|
@@ -9,18 +9,23 @@
|
|
|
:show-close="false"
|
|
|
append-to-body
|
|
|
@open="dialogOpen"
|
|
|
- @closed="dialogClosed"
|
|
|
>
|
|
|
<div class="scan-head" slot="title">
|
|
|
- <h3>扫描</h3>
|
|
|
+ <h3>
|
|
|
+ 扫描详情
|
|
|
+ <span class="color-gray ml-2"
|
|
|
+ >{{ task.courseName }}({{ task.courseCode }})</span
|
|
|
+ >
|
|
|
+ </h3>
|
|
|
<div
|
|
|
- v-if="scanStatus !== 'START'"
|
|
|
+ v-if="scanStatus === 'INIT'"
|
|
|
class="scan-head-btn cont-link"
|
|
|
- @click="closeDialog"
|
|
|
+ @click="close"
|
|
|
>
|
|
|
<i class="el-icon-close"></i>
|
|
|
</div>
|
|
|
</div>
|
|
|
+
|
|
|
<div class="scan-image-list">
|
|
|
<div
|
|
|
v-for="item in scanHistoryList"
|
|
@@ -31,54 +36,15 @@
|
|
|
<img :src="item" />
|
|
|
</div>
|
|
|
</div>
|
|
|
+
|
|
|
<div slot="footer">
|
|
|
- <el-form
|
|
|
- ref="modalFormComp"
|
|
|
- :model="modalForm"
|
|
|
- :rules="rules"
|
|
|
- label-width="100px"
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ :loading="scanStatus !== 'INIT'"
|
|
|
+ @click="startTask"
|
|
|
>
|
|
|
- <el-form-item label="课程名称:">
|
|
|
- {{ task.courseName }}
|
|
|
- </el-form-item>
|
|
|
- <el-form-item prop="preScanCount" label="预扫张数:">
|
|
|
- <el-input-number
|
|
|
- v-model="modalForm.preScanCount"
|
|
|
- :min="0"
|
|
|
- :max="1000000"
|
|
|
- :step="1"
|
|
|
- step-strictly
|
|
|
- :controls="false"
|
|
|
- ></el-input-number>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="实扫张数:">
|
|
|
- <span class="color-danger">
|
|
|
- {{ realScanCount }}
|
|
|
- </span>
|
|
|
- <i v-if="scanStatus === 'START'" class="el-icon-loading"></i>
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
- <div>
|
|
|
- <el-button
|
|
|
- v-if="scanStatus === 'INIT'"
|
|
|
- type="primary"
|
|
|
- @click="startTask"
|
|
|
- >开始扫描</el-button
|
|
|
- >
|
|
|
- <el-button
|
|
|
- v-if="scanStatus === 'PAUSE'"
|
|
|
- type="primary"
|
|
|
- :loading="submiting"
|
|
|
- @click="confirm"
|
|
|
- >确认</el-button
|
|
|
- >
|
|
|
- <el-button
|
|
|
- v-if="scanStatus === 'PAUSE'"
|
|
|
- :loading="submiting"
|
|
|
- @click="cancel"
|
|
|
- >取消</el-button
|
|
|
- >
|
|
|
- </div>
|
|
|
+ {{ statusDesc[scanStatus] }}
|
|
|
+ </el-button>
|
|
|
</div>
|
|
|
</el-dialog>
|
|
|
|
|
@@ -94,17 +60,12 @@
|
|
|
|
|
|
<script>
|
|
|
import { mapState } from "vuex";
|
|
|
-import { bingScanUser } from "../api";
|
|
|
import {
|
|
|
getPreUploadFiles,
|
|
|
- getPreUploadFileCount,
|
|
|
saveOutputImage,
|
|
|
- renamePreUploadJsonFile,
|
|
|
clearDir,
|
|
|
decodeImageCode,
|
|
|
- getScanHistoryFiles,
|
|
|
} from "../../../plugins/imageOcr";
|
|
|
-import setGroupTimeMixins from "../../../mixins/setGroupTimeMixins";
|
|
|
import db from "../../../plugins/db";
|
|
|
import { evokeScanner } from "../../../plugins/scanner";
|
|
|
import SimpleImagePreview from "@/components/SimpleImagePreview.vue";
|
|
@@ -124,61 +85,33 @@ export default {
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
- mixins: [setGroupTimeMixins],
|
|
|
data() {
|
|
|
return {
|
|
|
- modalIsShow: false,
|
|
|
- loading: false,
|
|
|
- submiting: false,
|
|
|
- user: this.$ls.get("user", { id: "" }),
|
|
|
- scanStatus: "INIT", // INIT:初始状态,START:已开始,PAUSE:已暂停
|
|
|
- modalForm: {
|
|
|
- preScanCount: 0,
|
|
|
- },
|
|
|
- rules: {
|
|
|
- preScanCount: [
|
|
|
- {
|
|
|
- required: true,
|
|
|
- message: "请输入预扫张数",
|
|
|
- trigger: "change",
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- scaningImageList: [],
|
|
|
+ modalIsShow: true,
|
|
|
+ scanStatus: "INIT",
|
|
|
realScanCount: 0,
|
|
|
- taskScanUserId: "",
|
|
|
scanHistoryList: [],
|
|
|
curPaper: {},
|
|
|
+ statusDesc: {
|
|
|
+ INIT: "开始扫描",
|
|
|
+ SCAN: "扫描中",
|
|
|
+ SAVING: "保存数据中",
|
|
|
+ },
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
...mapState("client", ["ocrArea"]),
|
|
|
- openBarCode() {
|
|
|
- return this.$store.state.user.openBarCode;
|
|
|
- },
|
|
|
- taskBound() {
|
|
|
- return this.user.id === this.taskScanUserId;
|
|
|
- },
|
|
|
- },
|
|
|
- beforeDestroy() {
|
|
|
- this.clearSetTs();
|
|
|
},
|
|
|
methods: {
|
|
|
initData() {
|
|
|
- this.loading = false;
|
|
|
- this.modalForm.preScanCount = undefined;
|
|
|
- this.scaningImageList = [];
|
|
|
this.scanStatus = "INIT";
|
|
|
this.realScanCount = 0;
|
|
|
+ this.getScanHistory();
|
|
|
},
|
|
|
dialogOpen() {
|
|
|
logger.info(`00进入扫描`);
|
|
|
- this.taskScanUserId = this.task.scanUserId;
|
|
|
this.initData();
|
|
|
},
|
|
|
- dialogClosed() {
|
|
|
- this.clearSetTs();
|
|
|
- },
|
|
|
close() {
|
|
|
this.modalIsShow = false;
|
|
|
this.$emit("on-close");
|
|
@@ -187,43 +120,9 @@ export default {
|
|
|
open() {
|
|
|
this.modalIsShow = true;
|
|
|
},
|
|
|
- closeDialog() {
|
|
|
- if (this.scanStatus === "START") return;
|
|
|
-
|
|
|
- if (this.scanStatus === "INIT") {
|
|
|
- this.close();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- this.cancel();
|
|
|
- },
|
|
|
- async startTask() {
|
|
|
- const valid = await this.$refs.modalFormComp.validate().catch(() => {});
|
|
|
- if (!valid) return;
|
|
|
-
|
|
|
- if (this.loading) return;
|
|
|
- this.loading = true;
|
|
|
-
|
|
|
- if (!this.taskBound) {
|
|
|
- await bingScanUser({
|
|
|
- paperScanTaskId: this.task.id,
|
|
|
- userId: this.user.id,
|
|
|
- });
|
|
|
- this.taskScanUserId = this.user.id;
|
|
|
- }
|
|
|
+ startTask() {
|
|
|
logger.info(`01开始扫描`);
|
|
|
- this.scaningImageList = [];
|
|
|
- this.scanStatus = "START";
|
|
|
- this.getInitFile();
|
|
|
- this.getScanHistory();
|
|
|
-
|
|
|
- this.evokeScanExe();
|
|
|
- },
|
|
|
- async continueTask() {
|
|
|
- logger.info(`01继续扫描`);
|
|
|
- this.scanStatus = "START";
|
|
|
- this.getInitFile();
|
|
|
-
|
|
|
+ this.scanStatus = "SCAN";
|
|
|
this.evokeScanExe();
|
|
|
},
|
|
|
async evokeScanExe() {
|
|
@@ -232,99 +131,48 @@ export default {
|
|
|
await evokeScanner(this.GLOBAL.input).catch((error) => {
|
|
|
console.error(error);
|
|
|
});
|
|
|
- this.scanStatus = "PAUSE";
|
|
|
- this.realScanCount = getPreUploadFileCount(this.GLOBAL.input);
|
|
|
|
|
|
// 缓存已扫描的数据
|
|
|
const res = getPreUploadFiles(this.GLOBAL.input);
|
|
|
if (!res.succeed) {
|
|
|
logger.error(`03扫描仪停止,故障:${res.errorMsg}`);
|
|
|
this.$message.error(res.errorMsg);
|
|
|
- renamePreUploadJsonFile(this.GLOBAL.input);
|
|
|
+ this.scanStatus = "INIT";
|
|
|
return;
|
|
|
}
|
|
|
logger.info(`03扫描仪停止,扫描数:${res.data.length}`);
|
|
|
- this.scaningImageList.push(...res.data);
|
|
|
- // console.log(this.scaningImageList);
|
|
|
- renamePreUploadJsonFile(this.GLOBAL.input);
|
|
|
- },
|
|
|
- async confirm() {
|
|
|
- if (!this.scaningImageList.length) {
|
|
|
- this.$message.error("当前没有需要保存的数据!");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (this.realScanCount !== this.modalForm.preScanCount) {
|
|
|
- this.$message.error("实扫张数与预扫张数不一致!");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (this.submiting) return;
|
|
|
- this.submiting = true;
|
|
|
-
|
|
|
- logger.info(`04-1开始保存数据`);
|
|
|
- let res = true;
|
|
|
- await this.saveScanImage().catch(() => {
|
|
|
- res = false;
|
|
|
+ this.scanStatus = "SAVING";
|
|
|
+ await this.saveScanImage(res.data).catch(() => {
|
|
|
+ this.$message.error("保存数据失败,请重新扫描!");
|
|
|
+ logger.error(`保存数据失败,请重新扫描!`);
|
|
|
});
|
|
|
- this.submiting = false;
|
|
|
- logger.info(`04-2保存数据结束`);
|
|
|
- if (!res) {
|
|
|
- this.$message.error("保存数据错误!");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const confirm = await this.$confirm(`是否继续扫描?`, "提示", {
|
|
|
- type: "warning",
|
|
|
- }).catch(() => {});
|
|
|
- this.clearScanList();
|
|
|
-
|
|
|
- if (confirm !== "confirm") {
|
|
|
- this.close();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- this.initData();
|
|
|
- },
|
|
|
- async cancel() {
|
|
|
- const confirm = await this.$confirm(
|
|
|
- `取消扫描后,当前未保存的数据将会被清空,确定要取消扫描吗?`,
|
|
|
- "提示",
|
|
|
- {
|
|
|
- type: "warning",
|
|
|
- }
|
|
|
- ).catch(() => {});
|
|
|
- if (confirm !== "confirm") return;
|
|
|
-
|
|
|
- this.clearScanList();
|
|
|
- this.close();
|
|
|
+ clearDir(this.GLOBAL.input);
|
|
|
+ this.scanStatus = "INIT";
|
|
|
+ await this.getScanHistory();
|
|
|
},
|
|
|
// scan relate
|
|
|
- getInitFile() {
|
|
|
- this.clearSetTs("scan");
|
|
|
- if (this.scanStatus !== "START") return;
|
|
|
+ async getScanHistory() {
|
|
|
+ const res = await db
|
|
|
+ .searchHistoryList({
|
|
|
+ isFormal: this.task.isFormal ? 1 : 0,
|
|
|
+ taskId: this.task.id,
|
|
|
+ })
|
|
|
+ .catch(() => {});
|
|
|
+ if (!res) return;
|
|
|
|
|
|
- this.realScanCount = getPreUploadFileCount(this.GLOBAL.input);
|
|
|
- this.addSetTime(
|
|
|
- "scan",
|
|
|
- () => {
|
|
|
- this.getInitFile();
|
|
|
- },
|
|
|
- 500
|
|
|
- );
|
|
|
- },
|
|
|
- getScanHistory() {
|
|
|
- this.clearSetTs("history");
|
|
|
- this.scanHistoryList = getScanHistoryFiles(this.GLOBAL.input);
|
|
|
- this.addSetTime(
|
|
|
- "history",
|
|
|
- () => {
|
|
|
- this.getScanHistory();
|
|
|
- },
|
|
|
- 1000
|
|
|
- );
|
|
|
+ this.scanHistoryList = [];
|
|
|
+ res.forEach((item) => {
|
|
|
+ this.scanHistoryList.push(item.frontOriginImgPath);
|
|
|
+ this.scanHistoryList.push(item.versoOriginImgPath);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.curPaper = {};
|
|
|
+ this.$refs.SimpleImagePreview.close();
|
|
|
},
|
|
|
- async saveScanImage() {
|
|
|
- for (let i = 0, len = this.scaningImageList.length; i < len; i++) {
|
|
|
- const files = this.scaningImageList[i];
|
|
|
+ async saveScanImage(imageList) {
|
|
|
+ logger.info(`04-1开始保存数据`);
|
|
|
+ for (let i = 0, len = imageList.length; i < len; i++) {
|
|
|
+ const files = imageList[i];
|
|
|
const ouputImageList = saveOutputImage(
|
|
|
[files.frontFile, files.versoFile],
|
|
|
{
|
|
@@ -333,28 +181,30 @@ export default {
|
|
|
);
|
|
|
const fileInfo = {
|
|
|
taskId: this.task.id,
|
|
|
- taskName: this.task.scanTaskName,
|
|
|
- courseCode: "",
|
|
|
+ schoolId: this.task.schoolId,
|
|
|
+ examId: this.task.examId,
|
|
|
+ courseCode: this.task.courseCode,
|
|
|
courseName: this.task.courseName,
|
|
|
- teachingClassName: "1",
|
|
|
frontOriginImgPath: ouputImageList[0],
|
|
|
versoOriginImgPath: ouputImageList[1],
|
|
|
- examNumber: "",
|
|
|
+ isFormal: this.task.isFormal ? 1 : 0,
|
|
|
+ studentCode: "",
|
|
|
clientUserId: this.user.id,
|
|
|
- clientUsername: this.user.name,
|
|
|
+ clientUsername: this.user.loginName,
|
|
|
clientUserLoginTime: this.user.loginTime,
|
|
|
};
|
|
|
|
|
|
- if (this.openBarCode) {
|
|
|
+ if (this.task.isFormal) {
|
|
|
const num = await decodeImageCode(
|
|
|
- ouputImageList[0],
|
|
|
+ fileInfo.frontOriginImgPath,
|
|
|
this.ocrArea
|
|
|
).catch((err) => {
|
|
|
console.error(err);
|
|
|
logger.error(`04-2条码解析失败,${err}`);
|
|
|
});
|
|
|
console.log(num);
|
|
|
- fileInfo.examNumber = num || "";
|
|
|
+ fileInfo.studentCode = num || "";
|
|
|
+ fileInfo.ocrArea = JSON.stringify(this.ocrArea);
|
|
|
}
|
|
|
let res = true;
|
|
|
await db.saveUploadInfo(fileInfo).catch((err) => {
|
|
@@ -364,11 +214,8 @@ export default {
|
|
|
});
|
|
|
if (!res) return Promise.reject();
|
|
|
}
|
|
|
- },
|
|
|
- clearScanList() {
|
|
|
- this.scaningImageList = [];
|
|
|
- this.scanHistoryList = [];
|
|
|
- clearDir(this.GLOBAL.input);
|
|
|
+
|
|
|
+ logger.info(`04-2保存数据结束`);
|
|
|
},
|
|
|
// image-preview
|
|
|
toViewPaper(imgUrl) {
|