|
@@ -36,6 +36,8 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import { printCurrentPage } from "./imageToPdf";
|
|
|
+
|
|
|
export default {
|
|
|
name: "EcsOfflineUploadCug",
|
|
|
props: {
|
|
@@ -100,6 +102,7 @@ export default {
|
|
|
return "Unknown filetype";
|
|
|
}
|
|
|
}
|
|
|
+ console.log(file);
|
|
|
|
|
|
const filereader = new FileReader();
|
|
|
let uploads = [];
|
|
@@ -146,7 +149,28 @@ export default {
|
|
|
}
|
|
|
} else if (["image/jpeg"].includes(getMimetype(hex))) {
|
|
|
if (file.name.endsWith(".jpeg") || file.name.endsWith(".jpg")) {
|
|
|
- resolve();
|
|
|
+ printCurrentPage()
|
|
|
+ .then(filename => {
|
|
|
+ // const fs = nodeRequire("fs");
|
|
|
+ const path = window.nodeRequire("path");
|
|
|
+ const fileNew = {
|
|
|
+ name: path.basename(filename),
|
|
|
+ path: filename,
|
|
|
+ type: "application/pdf",
|
|
|
+ // lastModified
|
|
|
+ // lastModifiedDate
|
|
|
+ // size
|
|
|
+ };
|
|
|
+ this.file = fileNew;
|
|
|
+ file = fileNew;
|
|
|
+ // console.log(this.$refs.uploadComp.fileList);
|
|
|
+ // this.$refs.uploadComp.fileList = [file];
|
|
|
+ // console.log(this.$refs.uploadComp.fileList);
|
|
|
+ resolve();
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ reject();
|
|
|
+ });
|
|
|
} else {
|
|
|
this.loadingStatus = false;
|
|
|
// this.$refs.uploadComp.fileList.splice(0);
|
|
@@ -224,7 +248,7 @@ export default {
|
|
|
desc: file.name + " 太大,作答文件不能超过30M.",
|
|
|
});
|
|
|
},
|
|
|
- handleBeforeUpload(file) {
|
|
|
+ async handleBeforeUpload(file) {
|
|
|
const suffix = file.name.split(".").pop();
|
|
|
if (suffix.toLowerCase() !== suffix) {
|
|
|
this.$Notice.error({
|
|
@@ -233,6 +257,66 @@ export default {
|
|
|
});
|
|
|
return Promise.reject("file suffix should be lower case");
|
|
|
}
|
|
|
+ if (file.name.endsWith(".jpeg") || file.name.endsWith(".jpg")) {
|
|
|
+ new Promise((resolve, reject) => {
|
|
|
+ if (this.course.offlineFileUrl) {
|
|
|
+ this.$Modal.confirm({
|
|
|
+ title: "已有作答附件,是否覆盖?",
|
|
|
+ onCancel: () => reject(-1),
|
|
|
+ onOk: () => resolve(),
|
|
|
+ });
|
|
|
+ } 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;
|
|
|
+
|
|
|
+ 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);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return Promise.reject("图片另外路径上传");
|
|
|
+ }
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
if (this.course.offlineFileUrl) {
|
|
@@ -245,7 +329,12 @@ export default {
|
|
|
resolve();
|
|
|
}
|
|
|
}).then(() => {
|
|
|
- if (file.type.includes("/pdf")) {
|
|
|
+ if (
|
|
|
+ file.type.includes("/pdf")
|
|
|
+ // ||
|
|
|
+ // file.type.includes("/jpeg") ||
|
|
|
+ // file.type.includes("/jpg")
|
|
|
+ ) {
|
|
|
this.fileType = "pdf";
|
|
|
} else if (file.type.includes("/zip")) {
|
|
|
this.fileType = "zip";
|