|
@@ -32,6 +32,10 @@
|
|
|
{{ loadingStatus ? "上传中..." : "上传" }}
|
|
|
</i-button>
|
|
|
</div>
|
|
|
+ <Modal v-model="showPreview" fullscreen footer-hide :closable="false">
|
|
|
+ <!-- <div slot="header"></div> -->
|
|
|
+ <img id="previewId" />
|
|
|
+ </Modal>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
@@ -59,6 +63,9 @@ export default {
|
|
|
loadingStatus: false,
|
|
|
uploadFileFormat: [],
|
|
|
uploadFileAccept: "",
|
|
|
+ // imageSrc
|
|
|
+ previewImage: null,
|
|
|
+ showPreview: false,
|
|
|
};
|
|
|
},
|
|
|
async created() {
|
|
@@ -72,13 +79,14 @@ export default {
|
|
|
(res.data.OFFLINE_UPLOAD_FILE_TYPE &&
|
|
|
JSON.parse(res.data.OFFLINE_UPLOAD_FILE_TYPE)) ||
|
|
|
[];
|
|
|
- this.uploadFileFormat.push(...["jpeg", "jpg"]);
|
|
|
- this.uploadFileFormat = this.uploadFileFormat.map(v => v.toLowerCase());
|
|
|
this.uploadFileAccept =
|
|
|
- "image/jpeg," + this.uploadFileFormat.map(v => "application/" + v).join();
|
|
|
+ "image/jpeg," +
|
|
|
+ this.uploadFileFormat.map(v => "application/" + v.toLowerCase()).join();
|
|
|
if (this.uploadFileAccept.includes("zip")) {
|
|
|
this.uploadFileAccept = ".zip," + this.uploadFileAccept;
|
|
|
}
|
|
|
+ this.uploadFileFormat.push(...["jpeg", "jpg"]);
|
|
|
+ this.uploadFileFormat = this.uploadFileFormat.map(v => v.toLowerCase());
|
|
|
},
|
|
|
methods: {
|
|
|
fileFormatCheck(file, resolve, reject) {
|
|
@@ -216,6 +224,7 @@ export default {
|
|
|
closable: true,
|
|
|
});
|
|
|
this.$emit("reloadList");
|
|
|
+ this.showPreview = false;
|
|
|
},
|
|
|
handleError(error, file) {
|
|
|
window._hmt.push(["_trackEvent", "离线考试页面", "上传作答", "上传失败"]);
|
|
@@ -227,6 +236,7 @@ export default {
|
|
|
duration: 15,
|
|
|
closable: true,
|
|
|
});
|
|
|
+ this.showPreview = false;
|
|
|
},
|
|
|
handleFormatError(file) {
|
|
|
this.file = null;
|
|
@@ -239,6 +249,7 @@ export default {
|
|
|
this.uploadFileFormat.join(" 或 ") +
|
|
|
" 文件。",
|
|
|
});
|
|
|
+ this.showPreview = false;
|
|
|
},
|
|
|
handleMaxSize(file) {
|
|
|
this.file = null;
|
|
@@ -247,6 +258,7 @@ export default {
|
|
|
title: "超出文件大小限制",
|
|
|
desc: file.name + " 太大,作答文件不能超过30M.",
|
|
|
});
|
|
|
+ this.showPreview = false;
|
|
|
},
|
|
|
async handleBeforeUpload(file) {
|
|
|
const suffix = file.name.split(".").pop();
|
|
@@ -268,53 +280,83 @@ export default {
|
|
|
} else {
|
|
|
resolve();
|
|
|
}
|
|
|
- }).then(() => {
|
|
|
- return printCurrentPage()
|
|
|
- .then(filename => {
|
|
|
- const fs = window.nodeRequire("fs");
|
|
|
- const path = window.nodeRequire("path");
|
|
|
- // const fileNew = {
|
|
|
- // name: path.basename(filename),
|
|
|
- // // filename: path.basename(filename),
|
|
|
- // uri: "file://" + filename,
|
|
|
- // // path: filename,
|
|
|
- // type: "application/pdf",
|
|
|
- // };
|
|
|
- const fileNew = new File(
|
|
|
- [fs.readFileSync(filename)],
|
|
|
- path.basename(filename),
|
|
|
- { type: "application/pdf" } // what I upload is image.
|
|
|
- );
|
|
|
- this.file = fileNew;
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ this.showPreview = true;
|
|
|
+ this.$Message.info({
|
|
|
+ content: "正在准备将图片转为PDF...",
|
|
|
+ duration: 1.5,
|
|
|
+ closable: true,
|
|
|
+ });
|
|
|
|
|
|
- var stats = fs.statSync(filename);
|
|
|
- var fileSizeInBytes = stats["size"];
|
|
|
- if (fileSizeInBytes > 1024 * 30 * 1024) {
|
|
|
- this.handleMaxSize();
|
|
|
- throw "exceed max size";
|
|
|
- }
|
|
|
+ return new Promise(resolve => {
|
|
|
+ var reader = new FileReader();
|
|
|
+ reader.onload = function(e) {
|
|
|
+ document
|
|
|
+ .getElementById("previewId")
|
|
|
+ .setAttribute("src", e.target.result);
|
|
|
|
|
|
- const formData = new FormData();
|
|
|
- formData.append("fileType", "pdf");
|
|
|
- formData.append("file", fileNew);
|
|
|
+ setTimeout(resolve, 2500);
|
|
|
+ // resolve();
|
|
|
+ };
|
|
|
+ //Imagepath.files[0] is blob type
|
|
|
+ reader.readAsDataURL(file);
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ return printCurrentPage()
|
|
|
+ .then(filename => {
|
|
|
+ const fs = window.nodeRequire("fs");
|
|
|
+ const path = window.nodeRequire("path");
|
|
|
+ // const fileNew = {
|
|
|
+ // name: path.basename(filename),
|
|
|
+ // // filename: path.basename(filename),
|
|
|
+ // uri: "file://" + filename,
|
|
|
+ // // path: filename,
|
|
|
+ // type: "application/pdf",
|
|
|
+ // };
|
|
|
+ const fileNew = new File(
|
|
|
+ [fs.readFileSync(filename)],
|
|
|
+ path.basename(filename),
|
|
|
+ { type: "application/pdf" } // what I upload is image.
|
|
|
+ );
|
|
|
+ this.file = fileNew;
|
|
|
|
|
|
- return this.$http
|
|
|
- .post(
|
|
|
- "/api/ecs_oe_admin/offlineExam/submitPaper?examRecordDataId=" +
|
|
|
- this.course.examRecordDataId,
|
|
|
- formData
|
|
|
- )
|
|
|
- .then(() => {
|
|
|
- this.handleSuccess();
|
|
|
- })
|
|
|
- .catch(() => {
|
|
|
- this.handleError();
|
|
|
+ this.$Message.info({
|
|
|
+ content: "图片转换成功,正在上传...",
|
|
|
+ duration: 2,
|
|
|
+ closable: true,
|
|
|
});
|
|
|
- })
|
|
|
- .catch(error => {
|
|
|
- console.log(error);
|
|
|
- });
|
|
|
- });
|
|
|
+
|
|
|
+ var stats = fs.statSync(filename);
|
|
|
+ var fileSizeInBytes = stats["size"];
|
|
|
+ if (fileSizeInBytes > 1024 * 30 * 1024) {
|
|
|
+ this.handleMaxSize();
|
|
|
+ throw "exceed max size";
|
|
|
+ }
|
|
|
+
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append("fileType", "pdf");
|
|
|
+ formData.append("file", fileNew);
|
|
|
+
|
|
|
+ return this.$http
|
|
|
+ .post(
|
|
|
+ "/api/ecs_oe_admin/offlineExam/submitPaper?examRecordDataId=" +
|
|
|
+ this.course.examRecordDataId,
|
|
|
+ formData
|
|
|
+ )
|
|
|
+ .then(() => {
|
|
|
+ this.handleSuccess();
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ this.handleError();
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ console.log(error);
|
|
|
+ this.handleError();
|
|
|
+ });
|
|
|
+ });
|
|
|
return Promise.reject("图片另外路径上传");
|
|
|
}
|
|
|
|